-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.pest
47 lines (40 loc) · 1.38 KB
/
grammar.pest
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
selector = ${ SOI ~ rootSelector ~ matchers ~ EOI }
matchers = ${ matcher* }
rootSelector = @{ "$" }
matcher = !{ dotChild | union }
dotChild = _{ wildcardedDotChild | namedDotChild }
wildcardedDotChild = { ".*" }
namedDotChild = ${ "." ~ childName }
childName = @{ char+ }
char = {
"-"
| ASCII_DIGIT
| ASCII_ALPHA
| "_"
| '\u{80}'..'\u{10FFFF}'
}
union = { "[" ~ unionElement ~ ("," ~ unionElement)* ~ "]" }
unionElement = _{ unionChild | unionArraySlice | unionArrayIndex }
unionChild = ${ doubleQuotedString | singleQuotedString }
unionArrayIndex = @{ integer }
integer = _{ "-" ? ~ ( "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* ) }
unionArraySlice = { sliceStart ? ~ ":" ~ sliceEnd ? ~ ( ":" ~ sliceStep ? ) ? }
sliceStart = @{ integer }
sliceEnd = @{ integer }
sliceStep = @{ integer }
doubleQuotedString = _{ "\"" ~ doubleInner ~ "\"" }
doubleInner = @{ doubleChar* }
doubleChar = {
!("\"" | "\\" | '\u{00}'..'\u{1F}') ~ ANY
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ hexDigit{4})
}
hexDigit = _{ ASCII_DIGIT | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f" }
singleQuotedString = _{ "'" ~ singleInner ~ "'" }
singleInner = @{ singleChar* }
singleChar = {
!("'" | "\\" | '\u{00}'..'\u{1F}') ~ ANY
| "\\" ~ ("'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ hexDigit{4})
}
WHITESPACE = _{ " " }