-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathguarding.pest
165 lines (134 loc) · 2.97 KB
/
guarding.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// online parser: [https://pest.rs/](https://pest.rs/)
start = _{ SOI ~ declaration* ~ EOI}
identifier = @{ (ASCII_ALPHA | ASCII_ALPHANUMERIC | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
declaration = {
normal_rule |
layer_rule
}
// package is a container of file and classes
// file is a container of classes and functions
// classes is a container of functions and field
normal_rule = {
rule_level ~ ("(" ~ scope ~ ")")? ~ (use_symbol ~ expression)? ~ should? ~ only? ~ operator ~ assert ~ ";"?
}
rule_level = {
"package" |
"class" |
"struct" |
"function" |
"file"
}
layer_rule = {
"layer" ~ "(" ~ layer_type ~ ")" ~ (use_symbol ~ layer_expression)* ~ ";"?
}
// use property
use_symbol = {
"::" |
"->"
}
layer_type = {
string
}
layer_expression = {
identifier ~ "(" ~ string ~ (comma ~ string)* ~ ")"
}
scope = {
path_scope |
impl_scope |
extend_scope |
assignable_scope |
match_scope
}
path_scope = {
string
}
match_scope = {
"match" ~ "(" ~ string ~ ")"
}
assignable_scope = {
"assignable" ~ string
}
extend_scope = {
"extends" ~ string
}
impl_scope = {
"implementation" ~ string
}
expression = {
fn_call
}
fn_call = {
identifier ~ (dot ~ identifier )*
}
assert = {
leveled |
stringed |
array_stringed |
sized
}
array_stringed = {
"(" ~ "[" ~ string ~ ("," ~ string)* ~ "]" ~ ")"
}
stringed = {
"("? ~ string ~ ")"?
}
leveled = {
rule_level ~ "(" ~ string ~ ")"
}
sized = {
int
}
operator = {
op_not ~ operator |
op_not_symbol ~ operator |
op_lte |
op_gte |
op_lt |
op_gt |
op_eq |
op_ineq |
op_contains |
op_endsWith |
op_startsWith |
op_resideIn |
op_inside |
op_accessed |
op_dependBy
}
// todo: change to strings operations method
op_contains = { "contains" }
op_endsWith = { "endsWith" }
op_startsWith = { "startsWith" }
// todo: thinking in define packages ops
op_inside = { "inside" }
op_resideIn = { "resideIn" }
op_accessed = { "accessed" }
op_dependBy = { "dependBy" }
op_not = @{ "not" }
op_not_symbol = @{ "!" }
// todo: move to comparison;
op_lte = { "<=" }
op_gte = { ">=" }
op_lt = { "<" }
op_gt = { ">" }
op_eq = { "=" }
op_ineq = { "!=" }
should = { "should" }
only = { "only" }
double_quoted_string = @{ "\"" ~ (!("\"") ~ ANY)* ~ "\""}
single_quoted_string = @{ "\'" ~ (!("\'") ~ ANY)* ~ "\'"}
string = @{
double_quoted_string |
single_quoted_string
}
number = @{ '0'..'9'+ }
int = @{ number | "-" ~ "0"* ~ '1'..'9' ~ number? }
dot = { "." }
comma = { "," }
semicolon = { ";" }
opening_paren = { "(" }
closing_paren = { ")" }
newline = _{ "\n" | "\r\n" }
WHITESPACE = _{ " " | "\t" | newline }
block_comment = _{ "/*" ~ (block_comment | !"*/" ~ ANY)* ~ "*/" }
COMMENT = _{ block_comment | ("//" ~ (!newline ~ ANY)*) }