-
Notifications
You must be signed in to change notification settings - Fork 5
/
grammar.go
40 lines (36 loc) · 1.13 KB
/
grammar.go
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
package translator
const defaultGrammar = `
instrs <- instr (Semi instr)* Semi?
instr <- expr / Byte / Int / String / complex_instr
complex_instr <- (LeftCurly instrs* RightCurly)
expr <- prim annots? args?
annots <- (annot+)
annot <- < Annot >
args <- (arg+)
arg <- prim / Byte / Int / String / complex_instr / (LeftParen expr RightParen)
prim <- < Alpha Accessible+ >
Int <- < Minus? Digit+ >
Byte <- < HexPrefix Hex+ >
String <- < Quote StringBody* Quote >
StringBody <- StringContent+ EQuote* Slash*
Annot <- AnnotPrefix+ AnnotBody*
EQuote <- Slash Quote
LeftParen <- '('
RightParen <- ')'
LeftCurly <- '{'
RightCurly <- '}'
Semi <- ';'
Minus <- '-'
Dot <- '.'
Quote <- '"'
Slash <- '\\'
StringContent <- [_a-zA-Z0-9- /:,.'()*+><=!^?%$;#№@~{}[\]]
Hex <- [A-F0-9a-f]
Alpha <- [a-zA-Z]
Accessible <- [A-Za-z0-9_]
Digit <- [0-9]
HexPrefix <- '0' 'x'
AnnotPrefix <- [:@%]
AnnotBody <- [_0-9a-zA-Z\\.]
%whitespace <- [ \t\r\n]*
`