-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathebnf.ebnf
More file actions
63 lines (40 loc) · 2.04 KB
/
ebnf.ebnf
File metadata and controls
63 lines (40 loc) · 2.04 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* An EBNF grammar for EBNF */
[1] ebnf ::= (declaration | rule)*
[2] declaration ::= '@terminals' | pass
# Use the LHS terminal to match the identifier, rule name and assignment due to
# confusion between the identifier and RANGE.
# The PEG parser has special rules for matching LHS and RANGE
# so that RANGE is not confused with LHS.
[3] rule ::= LHS expression
[4] expression ::= alt
[5] alt ::= seq ('|' seq)*
[6] seq ::= diff+
[7] diff ::= postfix ('-' postfix)?
[8] postfix ::= primary POSTFIX?
[9] primary ::= HEX
| SYMBOL
| O_RANGE
| RANGE
| STRING1
| STRING2
| '(' expression ')'
[10] pass ::= '@pass' expression
@terminals
[11] LHS ::= ('[' SYMBOL ']' ' '+)? SYMBOL ' '* '::='
[12] SYMBOL ::= '<' O_SYMBOL '>' | O_SYMBOL
[12a] O_SYMBOL ::= ([a-z] | [A-Z] | [0-9] | '_' | '.')+
[13] HEX ::= '#x' ([a-f] | [A-F] | [0-9])+
[14] RANGE ::= '[' ('-' ((R_CHAR '-' R_CHAR) | (HEX '-' HEX) | R_CHAR | HEX)+ | ((R_CHAR '-' R_CHAR) | (HEX '-' HEX) | R_CHAR | HEX)+ '-'?) ']'
[15] O_RANGE ::= '[^' ('-' ((R_CHAR '-' R_CHAR) | (HEX '-' HEX) | R_CHAR | HEX)+ | ((R_CHAR '-' R_CHAR) | (HEX '-' HEX) | R_CHAR | HEX)+ '-'?) ']'
# Strings are unescaped Unicode, excepting control characters and hash (#)
[16] STRING1 ::= '"' (CHAR - '"')* '"'
[17] STRING2 ::= "'" (CHAR - "'")* "'"
[18] CHAR ::= [#x9#xA#xD] | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
[19] R_CHAR ::= CHAR - (']' | '-' | HEX)
[20] POSTFIX ::= [?*+]
# Ignore all whitespace and comments between non-terminals
[21] PASS ::= [#x9#xA#xD#x20]
| ( ('#' - '#x') | '//' ) [^#xA#xD]*
| '/*' (( '*' [^/] )? | [^*] )* '*/'
| '(*' (( '*' [^)] )? | [^*] )* '*)'
@pass PASS