Skip to content

Commit c7bd20c

Browse files
committed
updates the grammar file
1 parent 456fddd commit c7bd20c

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

grammar.ebnf

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ program = { expression } ;
55
expression = literal
66
| symbol
77
| list
8+
| vector
89
| quoted
910
| quasiquoted
1011
| unquoted
1112
| splice
13+
| syntax_short
14+
| quasisyntax_short
15+
| unsyntax_short
16+
| unsyntax_splice_short
1217
| interp_string
1318
| comment ;
1419
@@ -26,9 +31,10 @@ symbol_char = letter | digit | "!" | "?" | "-" | "_" | "+"
2631
| "*" | "/" | "<" | ">" | "=" | "." | ":" | "@"
2732
| "~" | "^" | "&" | "%" ;
2833
29-
(* lists *)
34+
(* lists and vectors *)
3035
3136
list = ( "(" | "[" ) , { expression } , ( ")" | "]" ) ;
37+
vector = "#(" , { expression } , ")" ;
3238
3339
(* quoting *)
3440
@@ -44,6 +50,13 @@ unquoted = "," , expression
4450
splice = ",@" , expression
4551
| "(" , "unquote-splicing" , expression , ")" ;
4652
53+
(* syntax shorthands *)
54+
55+
syntax_short = "#'" , expression ;
56+
quasisyntax_short = "#`" , expression ;
57+
unsyntax_short = "#," , expression ;
58+
unsyntax_splice_short = "#,@" , expression ;
59+
4760
(* string interpolation *)
4861
4962
interp_string = "$\"" , { interp_segment } , '"' ;
@@ -93,15 +106,46 @@ do_binding = "(" , symbol , expression , expression , ")" ;
93106
94107
define_values = "(" , "define-values" , "(" , { symbol } , ")" , expression , ")" ;
95108
96-
(* macros *)
109+
(* macros — syntax-rules *)
110+
111+
define_syntax = "(" , "define-syntax" , symbol , ( syntax_rules | transformer ) , ")" ;
97112
98-
define_syntax = "(" , "define-syntax" , symbol , syntax_rules , ")" ;
99113
syntax_rules = "(" , "syntax-rules" , "(" , { symbol } , ")"
100114
, { "(" , pattern , template , ")" }
101115
, ")" ;
116+
102117
pattern = expression ;
103118
template = expression ;
104119
120+
(* macros — syntax-case *)
121+
122+
transformer = "(" , "lambda" , "(" , symbol , ")" , body , ")" ;
123+
124+
syntax_case = "(" , "syntax-case" , expression , "(" , { symbol } , ")"
125+
, { syntax_clause }
126+
, ")" ;
127+
syntax_clause = "[" , pattern , body , "]"
128+
| "[" , pattern , fender , body , "]" ;
129+
fender = expression ;
130+
131+
syntax_form = "(" , "syntax" , template , ")"
132+
| "#'" , template ;
133+
134+
quasisyntax_form = "(" , "quasisyntax" , qs_template , ")"
135+
| "#`" , qs_template ;
136+
qs_template = qs_atom | qs_list ;
137+
qs_atom = expression ;
138+
qs_list = "(" , { qs_element } , ")" ;
139+
qs_element = unsyntax_form | unsyntax_splice_form | qs_template ;
140+
141+
unsyntax_form = "(" , "unsyntax" , expression , ")"
142+
| "#," , expression ;
143+
unsyntax_splice_form = "(" , "unsyntax-splicing" , expression , ")"
144+
| "#,@" , expression ;
145+
146+
with_syntax = "(" , "with-syntax" , "(" , { ws_binding } , ")" , body , ")" ;
147+
ws_binding = "[" , pattern , expression , "]" ;
148+
105149
(* libraries *)
106150
107151
import_form = "(" , "import" , { import_spec } , ")" ;

0 commit comments

Comments
 (0)