-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.ebnf
31 lines (29 loc) · 927 Bytes
/
macros.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
macro := '$syntax' [identifier] [integer] pattern '=' replacements ';' ;
(*
NOTE: `'$'*FOO` means that `FOO` can be proceeded by any amount of `$`s.
Likewise, `'$'+FOO` must be proceeded by at least one `$`
*)
pattern := '{' pattern-body '}' ;
pattern-body := pattern-sequence {'$|' pattern-sequence} ;
pattern-sequence := pattern-atom {pattern-atom};
pattern-atom
:= '$'+ident ':' pattern-kind
| '$'*( pattern-body ')' (* note that non-`$` braces have to be matched *)
| '$'*[ pattern-body ']'
| '$'*{ pattern-body '}'
| (? any non-macro token ?)
;
pattern-kind
:= '$'* ident
| '(' pattern-body ')'
| '[' pattern-body ']'
| '{' pattern-body '}' ;
replacements := '{' replacement-body '}'
replacement-body := replacement-atom {replacement-atom} ;
replacement-atom
:= '$'+ident
| '$'+[ replacement-body ']'
| '$'+( replacement-body ')'
| '$'+{ replacement-body '}'
| (? any non-macro token ?)
;