-
Notifications
You must be signed in to change notification settings - Fork 0
/
caddy.ebnf
129 lines (96 loc) · 2.9 KB
/
caddy.ebnf
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
@@grammar::CADDY
@@keyword :: let in if else then function namespace import true false type this
start = block_region $ ;
block = '{' @:block_region '}' ;
block_region = @+:{ statement } @:expression ;
statement
= @:assignment ';'
| @:import_file ';'
;
assignment = 'let' name:identifier '=' value:expression ;
import_file = 'import' path:string ;
expression
= block
| function
| namespace
| if_then_else
| relational_expression
;
function
= 'function' '(' { parameters+:parameter { ',' parameters+:parameter } } ')' body:expression
;
parameter = name:identifier ;
namespace = 'namespace' '{' { @+:definition } '}' ;
definition = name:identifier '=' value:expression ';' ;
relational_expression
= relational_binary_operation
| additive_expression
;
relational_binary_operation
= lhs:relational_expression op:'<' rhs:additive_expression
| lhs:relational_expression op:'>' rhs:additive_expression
| lhs:relational_expression op:'<=' rhs:additive_expression
| lhs:relational_expression op:'>=' rhs:additive_expression
| lhs:relational_expression op:'==' rhs:additive_expression
;
additive_expression
= additive_binary_operation
| multiplicative_expression
;
additive_binary_operation
= lhs:additive_expression op:'+' rhs:multiplicative_expression
| lhs:additive_expression op:'-' rhs:multiplicative_expression
;
multiplicative_binary_operation
= lhs:multiplicative_expression op:'/' rhs:unary_expression
| lhs:multiplicative_expression op:'*' rhs:unary_expression
| lhs:multiplicative_expression op:'%' rhs:unary_expression
| lhs:multiplicative_expression op:'^' rhs:unary_expression
;
multiplicative_expression
= multiplicative_binary_operation
| unary_expression
;
unary_expression
= unary_operation
| postfix_expression
;
unary_operation
= op:'+' inner:unary_expression
| op:'-' inner:unary_expression
;
postfix_expression
= chain
| lookup
| index
| function_call
| primary_expression
;
primary_expression
= number
| bool
| variable
| string
| array
| '(' @:expression ')'
;
chain = first:postfix_expression '.' function:variable '(' { arguments:expression_list } ')' ;
lookup = @:postfix_expression '::' @:variable ;
variable = identifier | 'this' ;
function_call = function:postfix_expression '(' arguments:expression_list ')' ;
expression_list = { @+:expression { ',' @+:expression } } ;
if_then_else = 'if' @:expression 'then' @:expression 'else' @:expression ;
index = @:postfix_expression '[' @:expression ']' ;
array = '[' @:expression_list ']' ;
@name
identifier = /(?!\d)\w+/ ;
bool = 'true'
| 'false'
;
number = float
| integer
;
float = (/[0-9]+\.[0-9]*/ | /\.[0-9]+/);
integer = /[0-9]+/ ;
string = '"' @:{ STRING_ESCAPE_SEQ | /[^"]+/ }* '"' ;
STRING_ESCAPE_SEQ = '\\' /\w|\S/ ;