-
Notifications
You must be signed in to change notification settings - Fork 1
/
snowcap.pest
53 lines (35 loc) · 1.52 KB
/
snowcap.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
48
49
50
51
52
53
/* Snowcap pest grammar */
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ SingleLineComment }
SingleLineComment = { "//" ~ (!"\n" ~ ANY)* }
container = {
"{" ~ ("<" ~ attributes ~ ">")? ~ (!container ~ element)? ~ "}"
}
row = { (^"row" | "-") ~ (id)? ~ ("<" ~ attributes ~ ">")? ~ element_list }
column = { (^"column" | ^"col" | "|") ~ (id)? ~ ("<" ~ attributes ~ ">")? ~ element_list }
stack = { (^"stack" | "^") ~ (id)? ~ ("<" ~ attributes ~ ">")? ~ element_list }
element_list = _{ "[" ~ element ~ ("," ~ element)* ~ "]" }
widget = { label ~ (id)? ~ ("<" ~ attributes ~ ">")? ~ "(" ~ (element_value | element)? ~ ")" }
element = _{ (module | widget | row | column | stack | container) }
// Consume everything inside <, > to pass to AttributeParser
attributes = @{ (!("<" | ">") ~ ANY)* }
id = { "#" ~ label }
element_value = _{ module | value }
array = { "[" ~ value ~ ("," ~ value)* ~ "]" }
value = { string | number | boolean | null | array }
module = { label ~ "!" ~ "{" ~ module_arguments ~ "}" }
// Consume everything inside {, } to pass to ModuleParser
module_arguments = @{ (!("{" | "}") ~ ANY)* }
boolean = { "true" | "false" }
null = { "null" }
label = @{ (ASCII_ALPHA | "-")* }
string = ${ "\"" ~ inner ~ "\"" }
inner = @{ char* }
char = {
!("\"" | "\\") ~ ANY
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
number = @{
"-"? ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) ~ ("." ~ ASCII_DIGIT*)? ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)?
}
markup = _{ SOI ~ (container) ~ EOI }