-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammar.pest
109 lines (86 loc) · 1.91 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
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
104
105
106
107
108
109
//! # Pest parsing grammar
//!
//! Pest is really easy to use, and it forms simple parsing trees
//!
//! I may eventually switch to Nom if I have the time to convert everything.
// Core items: whitespace and comments
WHITESPACE = _{ " " | "\n" | "\r" | "\t" | "\\\n" }
COMMENT = _{
"/*" ~ (!"*/" ~ ANY)* ~ "*/"
| ("//" | "--" | "#") ~ (!"\n" ~ ANY)* ~ "\n"
}
white = _{WHITESPACE | COMMENT}
string = ${
"\"" ~ (
"\\" ~ ANY
| !"\"" ~ ANY
)* ~ "\""
| "`" ~ (!"`" ~ ANY)* ~ "`"
}
date = ${
('0'..'9'){4}
~ "/"
~ ('0'..'9'){2}
~ "/"
~ ('0'..'9'){2}
}
msecs = ${"." ~ ('0'..'9'){3}}
time = ${
('0'..'9'){2}
~ ":"
~ ('0'..'9'){2}
~ ":"
~ ('0'..'9'){2}
~ msecs?
}
utc = ${"-UTC"}
datetime = ${
date
~ (WHITESPACE | COMMENT)+
~ time
~ utc?
}
days = ${('0'..'9')+}
duration = @{
(days ~ "d:")?
~ time
}
number_raw = ${"-"? ~ ('0'..'9')+}
number_suffix = ${"L" | "BD"}
number = ${
number_raw
~ number_suffix?
}
decimal_raw = ${"-"? ~ ('0'..'9')+ ~ "." ~ ('0'..'9')+}
decimal_suffix = ${"f"}
decimal = ${
decimal_raw
~ decimal_suffix?
}
bool_true = ${"true" | "on"}
bool_false = ${"false" | "off"}
boolean = ${bool_true | bool_false}
null = ${"null"}
base64_char = {'a'..'z' | 'A'..'Z' | '0'..'9' | "+" | "/" | "="}
base64 = ${"[" ~ (base64_char | (WHITESPACE | COMMENT)+)* ~ "]"}
value = ${
string | base64
| datetime| date | duration
| decimal | number
| boolean | null
}
ident = ${
('a'..'z' | 'A'..'Z' | "_")
~ ('a'..'z' | 'A'..'Z' | '0'..'9' | "." | "$" | "-" | "_")*
}
attribute = ${ident ~ "=" ~ value}
namespace = ${ident ~ ":"}
tag = ${
(value | namespace? ~ (!"\n" ~ white)* ~ ident)
~ ((!"\n" ~ white)+ ~ value)*
~ ((!"\n" ~ white)+ ~ attribute)*
~ ((!"\n" ~ white)+ ~ "{" ~ white* ~ tags ~ white* ~ "}" ~ (!"\n" ~ white)*)?
}
tags_sep = _{";" | "\n"}
tags = { tag? ~ (tags_sep ~ tag?)* }
tagtree = {SOI ~ tags ~ EOI}