-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoml.ebnf
103 lines (73 loc) · 3.23 KB
/
coml.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
coml ::= combined splitter?;
(* Basic Token *)
whitespace ::= " " | "\t";
whitespaces ::= whitespace+;
eol ::= "\r\n" | "\r" | "\n";
splitter ::= whitespaces | eol+ | whitespaces splitter | eol+ splitter;
(* Basic Types *)
basicTypes ::= number | boolean | string | array | hash | patchKey | patch | "nil" | "undefined";
(* Basic Types: Number *)
digit ::= #'[1-9]';
natural ::= digit | "0" | natural "0" | digit natural;
decInteger ::= natural | "-" natural | "+" natural;
float ::= decInteger "f"
| decInteger "." natural
| decInteger "." natural "e" decInteger
| decInteger "." natural "E" decInteger;
binDigit ::= #'[0-1]';
binNature ::= "0b" binDigit+;
binInteger ::= binNature | "-" binNature | "+" binNature;
octDigit ::= #'[0-7]';
octNature ::= "0o" octDigit+ | "0" octDigit+;
octInteger ::= octNature | "-" octNature | "+" octNature;
hexDigit ::= #'[0-9a-fA-F]';
hexNature ::= "0x" hexDigit+;
hexInteger ::= hexNature | "-" hexNature | "+" hexNature;
integer ::= decInteger | binInteger | octInteger | hexInteger;
number ::= integer | float;
(* Basic Types: Boolean *)
boolean ::= "true" | "false";
(* Basic Types: Array *)
arrayElement ::= splitter? expr splitter?;
arrayElements ::= arrayElement "," arrayElement | arrayElement "," | arrayElement;
inlineArrayElement ::= (whitespaces?) "-" whitespaces? expr splitter?;
inlineArrayElements ::= inlineArrayElement | inlineArrayElement eol+ inlineArrayElements;
array ::= "[" splitter? arrayElements splitter? "]"
| "[" splitter? "]"
| inlineArrayElements;
(* Basic Types: Hash *)
keyCharStart ::= #'[a-zA-Z_]';
keyCharMiddle ::= keyCharStart | digit | "0" | "_";
key ::= keyCharStart keyCharMiddle*;
hashElement ::= (whitespaces?) key (splitter?) ":" (splitter?) expr;
hash ::= hashElement | hashElement eol+ hash;
(* Basic Types: String *)
string ::= #'".*?"' | #'\'.*?\'';
(* Import *)
import ::= "import" whitespaces (string) whitespaces "as" whitespaces key;
imports ::= import | import eol+ imports;
(* Patch *)
patchKey ::= patchKey "." key
| patchKey "[" whitespaces? (string | integer) whitespaces? "]"
| patchKey "[" whitespaces? integer whitespaces? ".." whitespaces? integer whitespaces? "]"
| patchKey "[" whitespaces? integer whitespaces? "..." whitespaces? integer whitespaces? "]"
| key;
patchReplace ::= patchKey whitespaces? "=" splitter? expr;
patchAppend ::= patchKey whitespaces? "<<" splitter? expr
| patchKey whitespaces? "+=" splitter? expr;
patchPrepend ::= patchKey whitespaces? ">>" splitter? expr;
patchKeyVal ::= patchReplace | patchAppend | patchPrepend;
patchKeyVals ::= patchKeyVal | patchKeyVal eol+ whitespaces? patchKeyVals whitespaces?;
patch ::= "(" patchKey ")" splitter? "{" splitter? patchKeyVals splitter? "}" splitter?
| "(" patchKey ")" splitter? "+=" splitter? expr splitter?;
(* Combination *)
expr ::= basicTypes
| expr splitter? "??" splitter? expr
| expr splitter? "+" splitter? expr
| expr splitter? "-" splitter? expr
| expr splitter? "*" splitter? expr
| expr splitter? "/" splitter? expr
| expr splitter? "%" splitter? expr
| "(" splitter? expr splitter? ")";
combined ::= expr
| imports eol+ expr;