about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-08 17:54:07 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-08 17:54:07 -0800
commitd124be9cb68a7d46fddc59e4e107ffdf6fb07508 (patch)
tree86b85d0705460f81cb84001700272f99f25ad0e4 /shell
parente58980b4c8552ea41f097d905db34f603ea35a09 (diff)
downloadmu-d124be9cb68a7d46fddc59e4e107ffdf6fb07508.tar.gz
strip spaces when tokenizing
Thanks Max Bernstein for reporting this.
Diffstat (limited to 'shell')
-rw-r--r--shell/sandbox.mu23
-rw-r--r--shell/tokenize.mu1
2 files changed, 24 insertions, 0 deletions
diff --git a/shell/sandbox.mu b/shell/sandbox.mu
index 7d85ed59..37e94c12 100644
--- a/shell/sandbox.mu
+++ b/shell/sandbox.mu
@@ -210,6 +210,29 @@ fn test-run-integer {
   check-screen-row screen, 2/y, "=> 1 ", "F - test-run-integer/2"
 }
 
+fn test-run-with-spaces {
+  var sandbox-storage: sandbox
+  var sandbox/esi: (addr sandbox) <- address sandbox-storage
+  initialize-sandbox sandbox
+  # type "1"
+  edit-sandbox sandbox, 0x20/space
+  edit-sandbox sandbox, 0x31/1
+  edit-sandbox sandbox, 0x20/space
+  edit-sandbox sandbox, 0xa/newline
+  # eval
+  edit-sandbox sandbox, 0x13/ctrl-s
+  # setup: screen
+  var screen-on-stack: screen
+  var screen/edi: (addr screen) <- address screen-on-stack
+  initialize-screen screen, 0x80/width, 0x10/height
+  #
+  render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
+  check-screen-row screen, 0/y, " 1   ", "F - test-run-with-spaces/0"
+  check-screen-row screen, 1/y, "     ", "F - test-run-with-spaces/1"
+  check-screen-row screen, 2/y, "...  ", "F - test-run-with-spaces/2"
+  check-screen-row screen, 3/y, "=> 1 ", "F - test-run-with-spaces/3"
+}
+
 fn test-run-error-invalid-integer {
   var sandbox-storage: sandbox
   var sandbox/esi: (addr sandbox) <- address sandbox-storage
diff --git a/shell/tokenize.mu b/shell/tokenize.mu
index d28f59dc..8391ae7e 100644
--- a/shell/tokenize.mu
+++ b/shell/tokenize.mu
@@ -9,6 +9,7 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
   var token-storage: cell
   var token/edx: (addr cell) <- address token-storage
   {
+    skip-whitespace-from-gap-buffer in
     var done?/eax: boolean <- gap-buffer-scan-done? in
     compare done?, 0/false
     break-if-!=