by wcummings · 9y ago · 0 comments
Fun example: https://github.com/perl6/perl6-examples/blob/master/categori...
digits: charset "1234567890"
char: charset [#"a" - #"z" "+/-*"] ;; chars allowed in a symbol
not-quot: complement charset {"}
esc-string: [{\"} | not-quot]
bool: ["#t" | "#f"]
float: [opt "+-" any digits "." some digits]
number: [opt "+-" some digits]
symbol: [some char]
quot: [#"'" [sexp | atom]]
string: [{"} any esc-string {"}]
statement: [sexp | atom | space | newline]
sexp: ["(" any statement ")"]
atom: [bool | float | number | quot | symbol | string]
lisp-rule: [some statement]
NB. I wrote this "off the cuff" so I don't expect it to be flawless! Also there are no capture rules provided in my example (unlike perl6 grammars which provides this automatically).Anyway neither example fully covers the Common Lisp spec for a number atom (for eg. scientific notation or rationals).
* Regexp::Grammars - https://metacpan.org/pod/Regexp::Grammars
* Parse::RecDescent - https://metacpan.org/pod/Parse::RecDescent