about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-26 21:26:19 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-26 21:26:19 -0800
commit882cab69f7c999c0f79f6fc574c72dcba426a71b (patch)
tree9f297ae150f44d913d4505e8e71cd2f860712d7a /baremetal/shell
parenta65ea6e4a70212b42d25307b06a2c986dce35bc4 (diff)
downloadmu-882cab69f7c999c0f79f6fc574c72dcba426a71b.tar.gz
7809
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/read.mu53
1 files changed, 53 insertions, 0 deletions
diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu
index 96ea958f..8fdf4714 100644
--- a/baremetal/shell/read.mu
+++ b/baremetal/shell/read.mu
@@ -55,6 +55,15 @@ fn next-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace
       next-symbol-token in, out, trace
       break $next-token:body
     }
+    # brackets are always single-char tokens
+    {
+      var bracket?/eax: boolean <- is-bracket-grapheme? g
+      compare bracket?, 0/false
+      break-if-=
+      var g/eax: grapheme <- read-from-gap-buffer in
+      next-bracket-token g, out, trace
+      break $next-token:body
+    }
   }
   trace-higher trace
   var stream-storage: (stream byte 0x40)
@@ -140,6 +149,16 @@ fn next-number-token in: (addr gap-buffer), out: (addr stream byte), trace: (add
   trace-higher trace
 }
 
+fn next-bracket-token g: grapheme, out: (addr stream byte), trace: (addr trace) {
+  trace-text trace, "read", "bracket"
+  write-grapheme out, g
+  var stream-storage: (stream byte 0x40)
+  var stream/esi: (addr stream byte) <- address stream-storage
+  write stream, "=> "
+  write-stream stream, out
+  trace trace, "read", stream
+}
+
 fn read-symbol in: (addr stream byte), _out: (addr handle cell) {
   rewind-stream in
   var out/eax: (addr handle cell) <- copy _out
@@ -325,3 +344,37 @@ fn is-symbol-grapheme? g: grapheme -> _/eax: boolean {
   }
   return 1/true
 }
+
+fn is-bracket-grapheme? g: grapheme -> _/eax: boolean {
+  compare g, 0x28/open-paren
+  {
+    break-if-!=
+    return 1/true
+  }
+  compare g, 0x29/close-paren
+  {
+    break-if-!=
+    return 1/true
+  }
+  compare g, 0x5b/open-square-bracket
+  {
+    break-if-!=
+    return 1/true
+  }
+  compare g, 0x5d/close-square-bracket
+  {
+    break-if-!=
+    return 1/true
+  }
+  compare g, 0x7b/open-curly-bracket
+  {
+    break-if-!=
+    return 1/true
+  }
+  compare g, 0x7d/close-curly-bracket
+  {
+    break-if-!=
+    return 1/true
+  }
+  return 0/false
+}