-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.peg
52 lines (47 loc) · 1.37 KB
/
grammar.peg
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
#
# PEG formally describing its own ASCII syntax (based on Bryan Ford 2014)
#
# Hierarchical syntax
Grammar <- _ Rule+ EOF
Rule <- Name LEFTARROW Expression
Expression <- Sequence (SLASH Sequence)*
Sequence <- Prefix*
Prefix <- (AND / NOT)? Suffix
Suffix <- Primary (QUESTION / STAR / PLUS)?
Primary <- Name !LEFTARROW
/ OPEN Expression CLOSE
/ Literal
/ Class
/ Object
/ DOT
# Lexical syntax
Name <- [a-zA-Z_] [a-zA-Z_0-9]* _
Literal <- "\"" (!"\"" Character)+ "\"" _
/ "'" (!"'" Character)+ "'" _
Class <- "[" (!"]" Range)+ "]" _
Range <- Character "-" Character / Character
Character <- "\\" [nrt'"\[\]\\]
/ "\\" "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]
/ !"\\" .
Object <- LBRACE (Property (COMMA Property)*)? RBRACE
Property <- Name COLON Literal
DOT <- "." _
LEFTARROW <- "<" "-" _
SLASH <- "/" _
AND <- "&" _
NOT <- "!" _
QUESTION <- "?" _
STAR <- "*" _
PLUS <- "+" _
OPEN <- "(" _
CLOSE <- ")" _
LBRACE <- "{" _
RBRACE <- "}" _
COLON <- ":" _
COMMA <- "," _
_ <- (Space / Comment)* # optional whitespace
Comment <- "#" (!EOL .)*
Space <- [ \t-\r]
EOL <- "\n"
/ "\r" "\n"?
EOF <- !.