about summary refs log tree commit diff stats
path: root/shell/parenthesize.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-18 21:41:17 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-18 21:42:01 -0700
commit29795a0db4e1d180217123f81f14b69189b3c12c (patch)
tree7f60a0df59feb7141ec1d722ed852c3764cff2b1 /shell/parenthesize.mu
parente5cf5708900497919f7ff4f2f1897e6c6af57aee (diff)
downloadmu-29795a0db4e1d180217123f81f14b69189b3c12c.tar.gz
start emitting indent tokens
Diffstat (limited to 'shell/parenthesize.mu')
-rw-r--r--shell/parenthesize.mu21
1 files changed, 21 insertions, 0 deletions
diff --git a/shell/parenthesize.mu b/shell/parenthesize.mu
new file mode 100644
index 00000000..67b50854
--- /dev/null
+++ b/shell/parenthesize.mu
@@ -0,0 +1,21 @@
+# TODO: not really implemented yet
+fn parenthesize in: (addr stream token), out: (addr stream token), trace: (addr trace) {
+  trace-text trace, "parenthesize", "insert parens"
+  trace-lower trace
+  rewind-stream in
+  {
+    var done?/eax: boolean <- stream-empty? in
+    compare done?, 0/false
+    break-if-!=
+    #
+    var token-storage: token
+    var token/edx: (addr token) <- address token-storage
+    read-from-stream in, token
+    var is-indent?/eax: boolean <- indent-token? token
+    compare is-indent?, 0/false
+    loop-if-!=
+    write-to-stream out, token  # shallow copy
+    loop
+  }
+  trace-higher trace
+}