diff options
author | bd <bdunahu@operationnull.com> | 2025-04-11 00:19:36 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-11 00:19:36 -0400 |
commit | 57bf0a940b3d1fdbe13684f545f0ce8707cdcd35 (patch) | |
tree | e33f252030e580cc7e60df69f413aa5a19ee4b3e | |
parent | c02164cfee4d8c3d3eca76fa8cc60b6ca60c2ca0 (diff) |
Add comments to parsing
-rw-r--r-- | src/parse.lisp | 13 | ||||
-rw-r--r-- | t/parse.lisp | 18 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/parse.lisp b/src/parse.lisp index 73e98c5..8eca782 100644 --- a/src/parse.lisp +++ b/src/parse.lisp @@ -9,10 +9,13 @@ (+ (or #\space #\tab)) (:constant nil)) -(esrap:defrule nl (+ #\newline) +(esrap:defrule eol (and (esrap:? space) (esrap:? (and #\; (* (not #\newline)))) #\newline) (:constant nil)) -(esrap:defrule nl-inc (+ #\newline) +(esrap:defrule nl (+ eol) + (:constant nil)) + +(esrap:defrule nl-inc (+ eol) (:lambda (n) (declare (ignore n)) (incf line-number) @@ -139,10 +142,10 @@ DESTRUCTURE-PATTERN is the list of non-terminals on the right side of the gramma ;;; defines rules to parse the .text segment -(esrap:defrule instr-clean (and (esrap:? space) instr (esrap:? space) nl-inc) +(esrap:defrule instr-clean (and (esrap:? space) instr nl-inc) (:function cadr)) -(esrap:defrule label-clean (and label-decl (esrap:? space) nl) +(esrap:defrule label-clean (and label-decl nl) (:function car)) (esrap:defrule text-line (or instr-clean label-clean)) @@ -164,7 +167,7 @@ DESTRUCTURE-PATTERN is the list of non-terminals on the right side of the gramma (util:add-variable e var-offset) nil)) -(esrap:defrule data-line (and (esrap:? space) var-decl (+ data-word) (esrap:? space) nl) +(esrap:defrule data-line (and (esrap:? space) var-decl (+ data-word) nl) (:function caddr)) (esrap:defrule data (and ".DATA" (esrap:? space) nl (* data-line)) diff --git a/t/parse.lisp b/t/parse.lisp index bd5ee97..993447f 100644 --- a/t/parse.lisp +++ b/t/parse.lisp @@ -78,6 +78,18 @@ (esrap:parse 'parse:str->ast (format nil ".DATA~%~%.TEXT~t~%JMP 3($3)~t JRL FOO~t~%PUSH $5~%"))))) +(test esrap-instr-type-comments + (is (equal + '(emit::p + (emit::d) + (emit::x + (emit::j "JMP" (emit::rr 3) (emit::imm 3)) + (emit::j "JRL" (emit::rr 0) (emit::l "FOO" 17)) + (emit::j "PUSH" (emit::rr 5) (emit::imm 0)))) + (esrap:parse 'parse:str->ast (format nil ".DATA~%.TEXT;; dot dot dot +~tJMP 3($3) ;; this does things +~tJRL FOO~%~tPUSH $5~%"))))) + (test esrap-data-singleton (is (equal '(emit::p @@ -86,7 +98,7 @@ JRL FOO~t~%PUSH $5~%"))))) (emit::x)) (esrap:parse 'parse:str->ast (format nil ".DATA~%~tA 1~%.TEXT~%"))))) -(test esrap-data-loadedp +(test esrap-data-loaded (is (equal '(emit::p (emit::d @@ -131,11 +143,11 @@ H 3 5~%.TEXT~%"))))) (emit::i "ADDI" (emit::rr 0) (emit::rr 5) (emit::imm (emit::var "S"))) (emit::i "ADDI" (emit::rr 0) (emit::rr 10) (emit::imm (emit::var "ARR"))) (emit::i "ADDI" (emit::rr 0) (emit::rr 6) (emit::imm (emit::var "I"))) - (emit::j "JRL" (emit::rr 0) (emit::l "CMP" 20)) + (emit::j "JRL" (emit::rr 0) (emit::l "CMP" 23)) (emit::r "ADD" (emit::rr 10) (emit::rr 6) (emit::rr 9)) (emit::i "ADDI" (emit::rr 6) (emit::rr 6) (emit::imm 1)) (emit::r "CMP" (emit::rr 6) (emit::rr 5) (emit::rr 0)) - (emit::j "BGT" (emit::rr 0) (emit::l "L" 24)))) + (emit::j "BGT" (emit::rr 0) (emit::l "L" 27)))) (esrap:parse 'parse:str->ast (format nil " .DATA ARR 1 2 3 4 |