From: Frank Duncan Date: Sat, 23 Apr 2016 21:21:08 +0000 (-0500) Subject: Improve parser - generate prims from lets X-Git-Tag: v0.1.0~52 X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=b81522f;p=clnl Improve parser - generate prims from lets --- diff --git a/src/main/parse.lisp b/src/main/parse.lisp index c427019..5c4c233 100644 --- a/src/main/parse.lisp +++ b/src/main/parse.lisp @@ -101,6 +101,7 @@ DESCRIPTION: :arg-countdown (when arg-countdown (1- arg-countdown)))) ((eql (intern "(" (find-package :keyword)) (car lexed-ast)) (parse-parened-expr (cdr lexed-ast) arg-countdown)) ((eql (intern ")" (find-package :keyword)) (car lexed-ast)) (error "Closing parens has no opening parens")) + ((eql :let (car lexed-ast)) (parse-let (cdr lexed-ast) arg-countdown)) ((eql :[ (car lexed-ast)) (parse-block (cdr lexed-ast) arg-countdown)) (prim (when (prim-structure-prim prim) @@ -108,6 +109,17 @@ DESCRIPTION: (parse-prim prim lexed-ast nil arg-countdown)) (t (error "Couldn't parse ~S" lexed-ast)))))))) +(defun parse-let (lexed-ast arg-countdown) + (when (not (keywordp (car lexed-ast))) (error "Needed a keyword for let")) + (let* + ((half-parsed-remainder (parse-internal (cdr lexed-ast) :arg-countdown 1))) + (let + ((*dynamic-prims* (cons (list :name (car lexed-ast)) *dynamic-prims*))) + (parse-internal + (cdr half-parsed-remainder) + :arg-countdown (when arg-countdown (1- arg-countdown)) + :prev-item (list :let (car lexed-ast) (car half-parsed-remainder)))))) + (defun parse-prim (prim lexed-ast prev-item arg-countdown) (let* ((num-args (- (prim-num-args prim) (if (prim-is-infix prim) 1 0))) @@ -218,7 +230,7 @@ DESCRIPTION: (defprim :with (:reporter-block)) (defprim :fd (:number)) (defprim :hatch (:number :command-block)) -(defprim :let (t t)) +; (defprim :let (t t)) ; keeping this here, commented out, to note that it has special processing (defprim :if (:boolean :command-block)) (defprim :if-else (:boolean :command-block :command-block)) (defprim :ifelse (:boolean :command-block :command-block)) @@ -273,7 +285,7 @@ DESCRIPTION: (defprim :display-labels ()) ; Generated by a let -(defprim :prey ()) +;(defprim :prey ()) ; Generated by breeds (defprim :sheep ())