-
Notifications
You must be signed in to change notification settings - Fork 23
/
grammar.ebnf
76 lines (70 loc) · 3.69 KB
/
grammar.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
zero = "0";
nonzero = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
digit = zero | nonzero;
lowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g"
| "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t"
| "u" | "v" | "w" | "x" | "y" | "z";
uppercase = "A" | "B" | "C" | "D" | "E" | "F" | "G"
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
| "O" | "P" | "Q" | "R" | "S" | "T"
| "U" | "V" | "W" | "X" | "Y" | "Z";
letter = lowercase | uppercase;
ifs = " " | "\t";
newline = "\n" | "\r\n";
identifier = letter, { letter | digit | "_" };
number = nonzero, { digit };
number_greater_or_equal_than_zero = zero | { number };
whitespace = ifs | newline;
break = whitespace, { whitespace };
break_opt = { whitespace };
item_end = ",";
field_end = ",";
stmt_end = ";";
item_decl = identifier, break_opt,
item_end;
field_decl = identifier, break_opt, ":", break_opt,
identifier, break_opt,
field_end;
custom_union_item_decl = identifier, break_opt, ":", break_opt,
number_greater_or_equal_than_zero, break_opt,
field_end;
option_decl = "option", break, identifier, break_opt,
"(", break_opt,
identifier, break_opt,
")", break_opt,
stmt_end;
union_decl = "union", break, identifier, break_opt,
"{", break_opt,
(item_decl | custom_union_item_decl), break_opt,
{ (item_decl | custom_union_item_decl), break_opt },
"}";
array_decl = "array", break, identifier, break_opt,
"[", break_opt,
identifier, break_opt, ";", break_opt, number, break_opt,
"]", break_opt,
stmt_end;
struct_decl = "struct", break, identifier, break_opt,
"{", break_opt,
field_decl, break_opt,
{ field_decl, break_opt },
"}";
vector_decl = "vector", break, identifier, break_opt,
"<", break_opt,
identifier, break_opt,
">", break_opt,
stmt_end;
table_decl = "table", break, identifier, break_opt,
"{", break_opt,
{ field_decl, break_opt },
"}";
decl_stmt = option_decl | union_decl | array_decl
| struct_decl | vector_decl | table_decl;
path_super = "../";
path = { path_super }, { identifier, "/" }, identifier;
import_stmt = "import", break, path, break_opt, stmt_end;
grammar = break_opt,
{ import_stmt, break_opt },
decl_stmt,
{ break_opt, decl_stmt }
break_opt;