Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

microstack updates

  • Loading branch information...
commit 9cd75a7638724795df5ee5989d0fac1973c4c4aa 1 parent d3ded5e
@VincentToups authored
Showing with 34 additions and 10 deletions.
  1. +31 −8 microstack.el
  2. +3 −2 microstack.md
View
39 microstack.el
@@ -18,23 +18,42 @@
(=let* [_ (=string "\\]")]
(if _ ?\" nil)))
-(defunc =bracketed-string ()
- (=let* [_ (=char ?\[)
+;; (defunc =bracketed-string ()
+;; (=let* [_ (=char ?\[)
+;; contents (zero-or-more (=or
+;; (=escaped-close-bracket)
+;; (=satisfies
+;; (lex-lambda (c) (!= c ?\])))))
+;; _ (=char ?\])]
+;; (parse-and-translate-microstack (coerce (flatten contents) 'string))))
+
+(defunc =single-quote-string ()
+ (=let* [_ (=char ?\')
contents (zero-or-more (=or
(=escaped-close-bracket)
(=satisfies
- (lex-lambda (c) (!= c ?\])))))
- _ (=char ?\])]
- (parse-and-translate-microstack (coerce (flatten contents) 'string))))
+ (lex-lambda (c) (!= c ?\')))))
+ _ (=char ?\')]
+ (coerce (flatten contents) 'string)))
+(defun =microstack-string ()
+ (=or (=single-quote-string)
+ (=lisp-string)))
+
+
+(defun =microstack-quote ()
+ (=let* [_ (=char ?\[)
+ contents (microstack-parser)
+ _ (=char ?\])]
+ (translate-microstack contents)))
(defun microstack-parser ()
"Parser for the microstack language."
(zero-or-more (=or
(=microstack-symbol)
(=number)
- (=lisp-string)
- (=bracketed-string))))
+ (=microstack-string)
+ (=microstack-quote))))
(defun parse-microstack (code)
"Parse the microstack language and return the results as a sequence of symbols, numbers, strings. Remove no-ops."
@@ -89,6 +108,9 @@
do
(|||- {qtn} call))))
+(defstackword loop-until-char
+ (|||- '(char-at-point->string string=) curry loop-until))
+
(defstackword forward
(forward-char))
(defstackword backward
@@ -139,8 +161,9 @@
(intern ".") 'print ; print the top of the stack, pop it
(intern "%") 'format ; lst format-string format; calls format with the string format-string and lst as rest args
(intern "|") 'compose ; compose two quotations
- (intern "/") 'curry ; curry the value on the stack into the quotation below it.
+ (intern "^") 'curry ; curry the value on the stack into the quotation below it.
'U 'loop-until ; qt pred loop-until ; loop qt until pred is true
+ 'u 'loop-until-char ; qt char loop-until-char; loop qt until char is beneath the cursor.
'W 'loop-while ; qt pred loop-while ; loop qt while pred is true
'i 'insert ; insert the top of the stack as text into the buffer
View
5 microstack.md
@@ -72,7 +72,8 @@ In general, microstack takes a specially formatted string, parses it
into a series of single-character "operands," numbers or strings and
then passes that sequence through a translator which transforms
symbols into stack-language words using a dictionary. Operands are
-single characters, strings are like Lisp strings, numbers like lisp
+single characters, strings are like Lisp strings (except they can be
+delimimted with single or double quotes in pairs), numbers like lisp
numbers, and the only special syntax is `[]` for quotation.
Everything inside a `[]` is compiled into a stack-quotation using the
microstack compiler.
@@ -128,7 +129,7 @@ the language supports the following operands
(intern "%") 'format ; lst format-string format; calls format with the string format-string and lst as rest args
(intern "|") 'compose ; compose two quotations
(intern "/") 'curry ; curry the value on the stack into the quotation below it.
- 'U 'loop-until ; qt pred loop-until ; loop qt until pred is true
+ 'U 'loop-until ; qt pred loop-until ; loop qt until pred is true
'W 'loop-while ; qt pred loop-while ; loop qt while pred is true
'i 'insert ; insert the top of the stack as text into the buffer
Please sign in to comment.
Something went wrong with that request. Please try again.