about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--color-repl.mu33
-rw-r--r--repl.mu20
2 files changed, 27 insertions, 26 deletions
diff --git a/color-repl.mu b/color-repl.mu
index 427106ed..667cdeec 100644
--- a/color-repl.mu
+++ b/color-repl.mu
@@ -1,4 +1,4 @@
-; a simple line editor for reading lisp s-expressions
+; a simple line editor for reading lisp expressions
 ; colors strings and comments. nested parens get different colors.
 ;
 ; needs to do its own raw keyboard/screen management since we need to decide
@@ -6,7 +6,7 @@
 ; lots of logic devoted to handling backspace correctly
 
 ; abort continuation -> string
-(function read-sexp [
+(function read-expression [
   (default-space:space-address <- new space:literal 30:literal)
   (abort:continuation <- next-input)
   (history:buffer-address <- next-input)  ; buffer of strings
@@ -29,16 +29,17 @@
 ])
 
 (function process-key [
-  (default-space:space-address/names:read-sexp <- next-input)
+  ; must always be called from within 'read-expression'
+  (default-space:space-address/names:read-expression <- next-input)
   (c:character <- next-input)
 ;?   (print-primitive-to-host 1:literal) ;? 2
-  (maybe-cancel-this-sexp c:character abort:continuation)
+  (maybe-cancel-this-expression c:character abort:continuation)
 ;?   (print-primitive-to-host 2:literal) ;? 2
   ; check for ctrl-d and exit
   { begin
     (eof?:boolean <- equal c:character ((ctrl-d literal)))
     (break-unless eof?:boolean)
-    ; return nil from read-sexp
+    ; return empty expression
     (s:string-address-address <- get-address result:buffer-address/deref data:offset)
     (s:string-address-address/deref <- copy nil:literal)
     (reply t:literal)
@@ -119,12 +120,12 @@
     ;   test: ; comment<enter>(+ 1 2)<enter>
     ;   too expensive to build: 3<backspace>; comment<enter>(+ 1 2)<enter>
     (at-top-level?:boolean <- lesser-or-equal open-parens:integer 0:literal)
-    (end-sexp?:boolean <- and at-top-level?:boolean not-empty?:boolean)
+    (end-expression?:boolean <- and at-top-level?:boolean not-empty?:boolean)
     { begin
-      (break-if end-sexp?:boolean)
+      (break-if end-expression?:boolean)
       (continue-from next-key:continuation)
     }
-    (reply nil:literal)
+    (reply nil:literal)  ; wait for more keys
   }
 ;?   (print-primitive-to-host 7:literal) ;? 2
   ; if it's not whitespace, set not-empty? and continue
@@ -180,12 +181,12 @@
     (break-unless newline?:boolean)
     ($print-key-to-host c:character)
     (at-top-level?:boolean <- lesser-or-equal open-parens:integer 0:literal)
-    (end-sexp?:boolean <- and at-top-level?:boolean not-empty?:boolean)
+    (end-expression?:boolean <- and at-top-level?:boolean not-empty?:boolean)
     { begin
-      (break-if end-sexp?:boolean)
+      (break-if end-expression?:boolean)
       (continue-from next-key:continuation)
     }
-    (reply nil:literal)
+    (reply nil:literal)  ; wait for more keys
   }
 ;?   (print-primitive-to-host 12:literal) ;? 2
   ; if all else fails, print the character without color
@@ -207,7 +208,7 @@
   { begin
     next-key-in-comment
     (c:character <- $wait-for-key-from-host)
-    (maybe-cancel-this-sexp c:character abort:continuation)  ; test: check needs to come before print
+    (maybe-cancel-this-expression c:character abort:continuation)  ; test: check needs to come before print
     ($print-key-to-host c:character 4:literal/fg/blue)
     ; handle backspace
     ;   test: ; abc<backspace><backspace>def<enter>
@@ -239,7 +240,7 @@
   { begin
     next-key-in-string
     (c:character <- $wait-for-key-from-host)
-    (maybe-cancel-this-sexp c:character abort:continuation)  ; test: check needs to come before print
+    (maybe-cancel-this-expression c:character abort:continuation)  ; test: check needs to come before print
     ($print-key-to-host c:character 6:literal/fg/cyan)
     ; handle backspace
     ;   test: "abc<backspace>d"
@@ -281,7 +282,7 @@
   (escapes:buffer-address <- next-input)
   (abort:continuation <- next-input)
   (c:character <- $wait-for-key-from-host)
-  (maybe-cancel-this-sexp c:character abort:continuation)  ; test: check needs to come before print
+  (maybe-cancel-this-expression c:character abort:continuation)  ; test: check needs to come before print
   ($print-key-to-host c:character color-code:integer)
   (len:integer-address <- get-address in:buffer-address/deref length:offset)
   (escapes:buffer-address <- append escapes:buffer-address len:integer-address/deref)
@@ -345,7 +346,7 @@
   (reply result:character)
 ])
 
-(function maybe-cancel-this-sexp [
+(function maybe-cancel-this-expression [
   ; check for ctrl-g and abort
   (default-space:space-address <- new space:literal 30:literal)
   (c:character <- next-input)
@@ -367,7 +368,7 @@
   (abort:continuation <- current-continuation)
   (history:buffer-address <- init-buffer 5:literal)
   { begin
-    (s:string-address <- read-sexp abort:continuation history:buffer-address)
+    (s:string-address <- read-expression abort:continuation history:buffer-address)
     (break-unless s:string-address)
     (history:buffer-address <- append history:buffer-address s:string-address)
     (len:integer <- get history:buffer-address/deref length:offset)
diff --git a/repl.mu b/repl.mu
index 90bfa8ac..6d223f19 100644
--- a/repl.mu
+++ b/repl.mu
@@ -1,6 +1,6 @@
-; a simple line editor for reading lisp s-expressions
+; a simple line editor for reading lisp expressions
 
-(function read-sexp [
+(function read-expression [
   (default-space:space-address <- new space:literal 30:literal)
   (in:channel-address <- next-input)
   (result:buffer-address <- init-buffer 30:literal)
@@ -9,7 +9,7 @@
 ;?     (skip-whitespace k:keyboard-address) ;? 1
     (x:tagged-value in:channel-address/deref <- read in:channel-address)
     (c:character <- maybe-coerce x:tagged-value character:literal)
-    (assert c:character "read-sexp: non-character in stdin")
+    (assert c:character "read-expression: non-character in stdin")
 ;?     (print-primitive-to-host (("key: " literal))) ;? 1
 ;?     (print-primitive-to-host c:character) ;? 2
 ;?     (print-primitive-to-host (("$\n" literal))) ;? 2
@@ -20,8 +20,8 @@
       (break-unless comment?:boolean)
       (skip-comment in:channel-address)
       ; comment slurps newline, so check if we should return
-      (end-sexp?:boolean <- lesser-or-equal open-parens:integer 0:literal)
-      (break-if end-sexp?:boolean 2:blocks)
+      (end-expression?:boolean <- lesser-or-equal open-parens:integer 0:literal)
+      (break-if end-expression?:boolean 2:blocks)
     }
     ; parse string
     { begin
@@ -44,8 +44,8 @@
       (newline?:boolean <- equal c:character ((#\newline literal)))
       (break-unless newline?:boolean)
 ;?       (print-primitive-to-host (("AAA" literal))) ;? 1
-      (end-sexp?:boolean <- lesser-or-equal open-parens:integer 0:literal)
-      (break-if end-sexp?:boolean 2:blocks)
+      (end-expression?:boolean <- lesser-or-equal open-parens:integer 0:literal)
+      (break-if end-expression?:boolean 2:blocks)
     }
     ; todo: error on space outside parens, like python
     ; []
@@ -63,7 +63,7 @@
   { begin
     (x:tagged-value in:channel-address/deref <- read in:channel-address)
     (c:character <- maybe-coerce x:tagged-value character:literal)
-    (assert c:character "read-sexp: non-character in stdin")
+    (assert c:character "read-expression: non-character in stdin")
     (newline?:boolean <- equal c:character ((#\newline literal)))
     (break-if newline?:boolean)
     (loop)
@@ -77,7 +77,7 @@
   { begin
     (x:tagged-value in:channel-address/deref <- read in:channel-address)
     (c:character <- maybe-coerce x:tagged-value character:literal)
-    (assert c:character "read-sexp: non-character in stdin")
+    (assert c:character "read-expression: non-character in stdin")
     (result:buffer-address <- append result:buffer-address c:character)
     (end-quote?:boolean <- equal c:character ((#\" literal)))  ; for vim: "
     (break-if end-quote?:boolean)
@@ -94,7 +94,7 @@
   (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address)
   { begin
     (print-primitive-to-host (("anarki> " literal)))
-    (s:string-address <- read-sexp buffered-stdin:channel-address)
+    (s:string-address <- read-expression buffered-stdin:channel-address)
     (retro-mode)  ; print errors cleanly
     (t:string-address <- $eval s:string-address)
     (cursor-mode)