Created
April 24, 2018 20:27
-
-
Save gavlooth/e5497038cc940e5d0ae0257a167af0ba to your computer and use it in GitHub Desktop.
Grammar for Clojure in Perl 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =begin overview | |
| This is the grammar for Clojure in Perl 6 rules. | |
| =end overview | |
| grammar PClojure::Grammar is HLL::Grammar; | |
| token TOP {^ <form>* $} | |
| token ws { | |
| <!ww> | |
| [ ';' \N* \n? | \s+ ]* [\s* ',' \s*]* | |
| } | |
| rule form { | |
| | <literal> | |
| | <list> | |
| | <vector> | |
| | <map> | |
| | <reader_macro> } | |
| rule list { '(' <form>* ')' } | |
| rule vector { '[' <form>* ']' } | |
| rule map { '{' [<form> <form>]* '}' } | |
| rule set { '#{' <form>* '}' } | |
| regex ext_alpha {'|' | '&' | '<' | '>' | '*' | '+' | '!' | '-' | '_' | '\'' | '?' | '=' | <alpha>} | |
| regex ext_alnum {\d | <ext_alpha>} | |
| regex symbol_T { ':'? [<ext_alnum> ['.' <ext_alnum>]?]+ } | |
| regex symbol_H { <ext_alpha> <symbol_T>* } | |
| token symbol { <symbol_H>+ ['/' <symbol_T>+ ]?} | |
| token literal { <String> | |
| | <Character> | |
| | <Number> | |
| | <param_name> | |
| | <nil> | |
| | <Boolean> | |
| | <keyword> | |
| | <symbol> | |
| | <special_form> | |
| } | |
| token OctalEscape { | |
| '\\' [ | |
| | <[0..3]> <[0..7]> <[0..7]> | |
| | <[0..7]> <[0..7]> | |
| | <[0..7]> | |
| ] | |
| } | |
| token UnicodeEscape { '\\u' <HexDigit>**{4} } | |
| token HexDigit { \d|<[a..f]>|<[A..F]> } | |
| token LiteralEscape{ | |
| | '\\' ['b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\'] | |
| | <UnicodeEscape> | |
| | <OctalEscape> | |
| } | |
| token esc_double_quote { '\\' | '"' } | |
| token String { '"' [ <-["]> | '\\' '"' ]* '"' } | |
| token CharacterLiteral { '\\' . } | |
| token NamedCharacterLiteral { '\\' [ 'newline' | |
| | 'return' | |
| | 'space' | |
| | 'tab' | |
| | 'formfeed' | |
| | 'backspace' ] } | |
| token Character { | |
| <LiteralEscape> | |
| |<NamedCharacterLiteral> | |
| |<UnicodeEscape> | |
| |<CharacterLiteral> } | |
| token Hex-digit { \d|<[a..f]>|<[A..F]> } | |
| token Hex-exponent { ['p'|'P'] ['+'|'-']? \d+ } | |
| token Octal-literal { '0' <[0..7]>+ <IntegerTypeSuffix>? } | |
| token Decimal-literal { ['0'<!before \d> | |
| | <[1..9]> \d*] <IntegerTypeSuffix>? } | |
| token Integer-type-suffix { 'l'|'L' } | |
| token Exponent { ['e'|'E'] ['+'|'-']? \d+ } | |
| token Float-type-suffix { 'f'|'F'|'d'|'D' } | |
| token Hex { '0' ['x'|'X'] [ | '.' <Hex-digit>+ <Hex-exponent>? <Float-type-suffix>? | |
| | <Hex-digit>+ [ '.' <Hex-digit>* <Hex-exponent>? <Float-type-suffix>? | |
| | <Integer-typeSuffix>? ] ] } | |
| token Float { | |
| | \d+ '.' \d* <Exponent>? <Float-type-suffix>? | |
| | '.' \d+ <Exponent>? <Float-type-suffix>? | |
| | \d+ <Exponent> <Float-type-suffix>? | |
| | \d+ <Float-type-suffix> | |
| | '-'? 'infinity' | |
| | '-'? 'NaN' | |
| } | |
| token Bin {'0' [b | B] [ 0 | 1 ]+ } | |
| token Bign {'-'? '0' \d+ [ n | N ] } | |
| token Long {'-'? \d+ [ l | L ]? } | |
| token Number { <Float> | <Hex> | <Bin> | <Bign> | <Long> } | |
| token param_name {'%' [[\d <[0..9]>*] | '&']?} | |
| token nil {'nil'} | |
| token Boolean {<true> | <false> } | |
| token true { 'true'} | |
| token false {'false'} | |
| token keyword {<ns_keyword> | <BS_keyword>} | |
| regex ns_keyword {':' <BS_keyword>} | |
| regex BS_keyword { ':' <symbol> } | |
| rule reader_macro { | |
| <lambda> | |
| | <gensym> | |
| | <unquote_splicing> | |
| | <unquote> | |
| | <backtick> | |
| | <quote> | |
| | <deref> | |
| | <dispatch> | |
| | <discard> | |
| | <tag> | |
| | <set> | |
| | <host_expr> | |
| | <var_quote> | |
| | <regex> | |
| | <meta_data> } | |
| rule lambda { '#(' <form>* ')' } | |
| token gensym {<symbol>'#' } | |
| token unquote_splicing { '~@' <form> } | |
| token unquote { '~' <form> } | |
| token backtick { '`' <form> } | |
| rule meta_data { '#^' [[<map> <form>] | <form>] } | |
| token var_quote { '#\'' <symbol> } | |
| token regex { '#' <String> } | |
| rule host_expr { '#+' <form> <form> } | |
| rule tag { '^' <form> <form> } | |
| rule discard { '#_' <form> } | |
| rule dispatch { '#(' <form>* ')' } | |
| token deref { '@' <form> } | |
| token quote {'\'' <form> } | |
| token dot_forms { [ <!after <ext_alnum>> '..' <!before <ext_alnum>>] | |
| | [<!after '.'> [ '.' | '.-'] <ext_alnum>*] } | |
| token special_form { '&' | |
| | 'monitor-exit' | |
| | 'case*' | |
| | 'try' | |
| | 'reify*' | |
| | 'finally' | |
| | 'loop*' | |
| | 'do' | |
| | 'letfn*' | |
| | 'if' | |
| | 'clojure.core/import*' | |
| | 'new' | |
| | 'deftype*' | |
| | 'let*' | |
| | 'fn*' | |
| | 'recur' | |
| | 'set!' | |
| | <dot_forms> | |
| | 'var' | |
| | 'quote' | |
| | 'catch' | |
| | 'throw' | |
| | 'monitor-enter' | |
| | 'def' } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment