forked from cornucopia-rs/cornucopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.pest
56 lines (51 loc) · 1.19 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
// Symbols
dot = _{"."}
underscore = _{"_"}
colon = _{":"}
comma = _{","}
start_param_list = _{"("}
end_param_list = _{")"}
start_ret_struct = _{"{"}
end_ret_struct = _{"}"}
// Postgres identifiers
lowercase_letter = _{'a'..'z'}
uppercase_letter = _{'A'..'Z'}
letter = _{ lowercase_letter | uppercase_letter }
digit = _{'0'..'9'}
postgres_alpha = _{ letter | digit | underscore }
ident = { (underscore | letter) ~ postgres_alpha* }
// Query parameters
parameter_list = {
start_param_list
~ (ident ~ (comma ~ ident)*)?
~ (comma)?
~ end_param_list
}
// Query return
nullable_return_param = {ident ~ nullable_marker}
non_nullable_return_param = {ident}
return_param = _{nullable_return_param | non_nullable_return_param }
nullable_marker = _{"?"}
inferred_params = { return_param ~ (comma ~ return_param)* }
implicit_return = { "" }
struct_return = {
start_ret_struct
~ inferred_params?
~ comma?
~ end_ret_struct
}
return_type = _{(struct_return) | (implicit_return)}
// Query quantifier
zero_or_more = {"*"}
zero_or_one = {"?"}
one = {""}
quantifier = {zero_or_more | zero_or_one | one}
// Parser
parser = {
SOI
~ ident
~ parameter_list
~ return_type
~ quantifier
~ EOI
}