(defpackage :nerdl (:use :clex2 :parse2 :cl)) (in-package :nerdl) (defun nerdl-lexer (input) (lexer (input) (:simple-tokens "{" "}" "[" "]" "-") (:atom -> "[-+_a-zA-Z0-9.]+" => $$) (:string -> #\" (* (or (- t #\\ #\") (and #\\ t))) #\") (:backtick-string -> #\` (* (or (- t #\\ #\") (and #\\ t))) #\`) (:pipe -> (and #\|) => (clex2:begin :quoted-content)) (:gt -> (and #\>) => (clex2:begin :quoted-content)) (:caret -> #\^) (-> "\\s+") (-> "#.*") (:in :quoted-content (:line-content -> ".*" => (clex2:begin :initial) $$)))) (defun test-nerdl-lexer (input &aux (fun (nerdl-lexer input))) (loop for tok = (multiple-value-list (funcall fun)) until (eq ':eof (car tok)) do (prin1 tok) (terpri))) (defun parse-nerdl (input) (parse (input) (top -> (* (or "{" "}" "[" "]" :pipe :gt "^" :atom :string :backtick-string :line-content))) (:atom -> "[-+_a-zA-Z0-9.]+" => $$) (:string -> #\" (* (or (- t #\\ #\") (and #\\ t))) #\") (:backtick-string -> #\` (* (or (- t #\\ #\") (and #\\ t))) #\`) (:pipe -> (and #\|) => (clex2:begin :quoted-content)) (:gt -> (and #\>) => (clex2:begin :quoted-content)) (:caret -> #\^) (-> "\\s+") (-> "#.*") (:in :quoted-content (:line-content -> ".*" => (clex2:begin :initial) $$)))) (defparameter *fodder* "# What now brown cow { the-wind \"bullseye\" the-trees false the-sparrows his-eye poem # I don't know if you can hear me |His eye # or if # you're even there |is on # I don't know if you can listen |The sparrow ^ # to a gypsy's prayer this-should-still-work 15.0 other |And I know |He's watching |Over me ^ `force push` >I sing >because >I'm happy ^ \"I am sysadmin\" true \"I am webadmin\" false \"you are so wrong\" null wendover [ { so 1 much -10 gambling 100 but 1000 also -1000 apparently 10000 paramedics -10000 and 1.01 } { die in a fire } 15 |this |that ^ >Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do >eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim >ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut >aliquip ex ea commodo consequat. Duis aute irure dolor in >reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla >pariatur. Excepteur sint occaecat cupidatat non proident, sunt in >culpa qui officia deserunt mollit anim id est laborum.\" ^ ] }") (defun run () (test-nerdl-lexer *fodder*))