-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschema.pest
89 lines (76 loc) · 1.59 KB
/
schema.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
main = {
SOI ~
(
version_stmt
| aggregate_def
| event_def
| struct_def
| type_def
)*
~ EOI
}
// Version
version_stmt = { "version" ~ "=" ~ string ~ ";" }
// Aggregate
aggregate_def = {
"aggregate" ~ item_ident ~ "{"
~ (command_def)*
~ "}" ~ ";"?
}
// Command
command_def = {
ident ~ "("
~ field_list
~ ")" ~ "->" ~ command_return ~ ";"
}
command_return = {
command_multi_return
| command_single_return
}
command_multi_return = {
"("
~ command_single_return
~ ("," ~ command_single_return)*
~ ")" }
command_single_return = { item_ident_opt | item_ident }
// Event
event_def = {
"event" ~ item_ident ~ "{"
~ field_list
~ "}" ~ ";"?
}
// Struct
struct_def = {
"struct" ~ item_ident ~ "{"
~ field_list
~ "}" ~ ";"?
}
// Type alias
type_def = { "type" ~ item_ident ~ "=" ~ ty ~ ";" }
field_list = { field ~ ("," ~ field)* ~ ","? }
field = { ident ~ ":" ~ ty }
ty = { optional_ty | required_ty }
required_ty = @{ scalar | item_ident }
optional_ty = @{ (scalar | item_ident) ~ "?" }
scalar = @{
"String"
| "Int"
| "UInt"
| "Float"
| "Bool"
| "Timestamp"
}
item_ident_opt = { item_ident ~ "?" }
item_ident = @{ ASCII_ALPHA_UPPER ~ ASCII_ALPHA* }
ident = { optional_ident | required_ident }
required_ident = @{ ( ASCII_ALPHA_LOWER | "_" )+ }
optional_ident = @{ ( ASCII_ALPHA_LOWER | "_" )+ ~ "?" }
string = ${ "\"" ~ inner ~ "\"" }
inner = @{ char* }
char = {
!("\"" | "\\") ~ ANY
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
WHITESPACE = _{ " " | NEWLINE }
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }