Created
November 28, 2020 12:30
-
-
Save samebchase/f6fbb81a2273fe86dbc129488ed5f842 to your computer and use it in GitHub Desktop.
This file contains 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
grammar Namespace { | |
token TOP { <ns-form> | |
# <clojure-forms> | |
} | |
# token clojure-forms { } | |
token ns-form { <.ws>? | |
(<.comment-line> <ws>?)* | |
<.ws>? | |
<lparen> | |
'ns' <.ws> | |
(<ns-name-docstring> | <ns-meta-ns-name> | <ns-name-author-map> | <ns-name>) ** 1 | |
<.ws>? | |
((<require-form> | <import-form> | <gen-class-form> | <refer-clojure-form> | <use-form>) <.ws>?)* | |
<rparen> } | |
token comment-line { ^^ ';'+ <.comment-chars>+ $$ } | |
token ns-name-docstring { <ns-name> <.ws> <.docstring> (<.ws> '^'? <author-map>)?} | |
token ns-meta-ns-name { <ns-metadata> <.ws> <ns-name> } | |
token ns-name-author-map { <ns-name> <.ws> <author-map> } | |
token author-map { <lcurly> <-[\}]>+ <rcurly> } | |
token documentation-char { <.alnum> | '.' | ' ' | '-' | | |
<lparen> | <rparen> | | |
<lsquare> | <rsquare> | | |
<langle> | <rangle> | \\ | \' | | |
'_' | ':' | '/' | ',' | '`' | | |
'?' | '& ' | '+' | '%' | '~' | | |
'=' | \n | '#' } | |
token documentation-chars { <.documentation-char>+ } | |
token comment-chars { (<.alnum> | '.' | ' ' | '-' | | |
<lparen> | <rparen> | | |
<lsquare> | <rsquare> | | |
'\'' | '_' | ':' | ';' | '/' | ',' | |
| '`' | '"' | '*' | '#' | '$' | '=' ) } | |
token docstring { '"' <.documentation-chars> '"' } | |
token clj-ns-name { (<.alnum> | '-' | '_' | '.' | '$')+ } | |
token ns-name { <.clj-ns-name> } | |
token dependency-ns-name { <.clj-ns-name> } | |
token ns-metadata { \^ <lcurly> <-[\}]>+ <rcurly> } | |
token gen-class-form { '(:gen-class)' } | |
token require-form { <lparen> | |
':'? 'require' | |
<.ws> | |
<ns-entries> | |
<rparen> } | |
token ns-entries { <ns-entry>+ % <.ws> } | |
token ns-entry { <ns-vector> | | |
<ns-name> | | |
<nested-vector> } | |
# Only supports one level of nesting. | |
# Should be extended. | |
token nested-vector {<lsquare> <dependency-ns-name> <.ws> | |
<ns-vector>+ % <.ws> | |
<rsquare> } | |
token ns-vector { (<lsquare> | |
<dependency-ns-name> <.ws> | |
((<ns-as> <.ws>?) | (<ns-refer> <.ws>?))* | |
<rsquare>) } | |
token ns-nickname { ( <.alnum> | '-' | '_' | '.' )+ } | |
token ns-as { ':as' <.ws> <ns-nickname> } | |
token clj-function { ( <.alnum> | '-' | '_' | '.' | | |
'!' | '?' | <langle> | <rangle> | | |
'+' | '*' )+ } | |
token ns-refer { (':refer' | ':only') <.ws> | |
(<ns-refer-import-vector> | ':all') | |
(<.ws> ':exclude' <.ws> <ns-refer-import-vector>)? } | |
token ns-refer-import-vector { <lsquare> | |
<clj-function>+ % <.ws> | |
<rsquare> } | |
token ns-refer-import-function { <clj-function> } | |
token refer-clojure-form { <lparen> ':refer-clojure :exclude' <.ws> | |
<ns-refer-import-vector> | |
<rparen> <.ws>? } | |
token use-form { <lparen> | |
':use' <.ws> | |
<ns-entries> | |
<rparen> } | |
token import-form { <lparen> | |
':import' <.ws> | |
<java-class-entry>+ % <.ws> | |
<rparen> } | |
token java-class-entry { <java-package> | | |
<singleton-java-package> | | |
<java-package-coll> } | |
token singleton-java-package { ( <.lsquare> | <.lparen> ) | |
<java-package> | |
( <.rsquare> | <.rparen> ) } | |
token java-package-coll { ( <.lsquare> | <.lparen> ) | |
<java-package> <.ws>? <java-classes> | |
( <.rsquare> | <.rparen> ) } | |
token java-package { ( <.alnum> | '.' | '$' )+ } | |
token java-class { ( <.alnum> | '$' )+ } | |
token java-classes { <java-class>+ % <.ws> } | |
token lparen { '(' } | |
token rparen { ')' } | |
token lsquare { '[' } | |
token rsquare { ']' } | |
token lcurly { '{' } | |
token rcurly { '}' } | |
token langle { '<' } | |
token rangle { '>' } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment