-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-minizinc.ebnf
188 lines (143 loc) · 4.08 KB
/
tree-sitter-minizinc.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// From tree-sitter-minizinc/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_file ::=
( _item ';' )* _item?
_item ::=
annotation
| assignment
| constraint
| declaration
| enumeration
| function_item
| goal
| include
| output
| predicate
annotation ::=
'annotation' identifier _parameters? ( '=' _expression )?
assignment ::=
identifier '=' _expression
constraint ::=
'constraint' _expression
declaration ::=
_type ':' identifier _annotations? ( '=' _expression )?
enumeration ::=
'enum' identifier _annotations? ( '=' '{' ( ( identifier ',' )* identifier? ) '}' )?
function_item ::=
'function' _type ':' identifier _parameters _annotations? ( '=' _expression )?
goal ::=
'solve' ( 'satisfy' | 'maximize' _expression | 'minimize' _expression )
include ::=
'include' string_literal
output ::=
'output' _expression
predicate ::=
( 'predicate' | 'test' ) identifier _parameters _annotations? ( '=' _expression )?
_annotations ::=
( '::' _expression )+
_parameters ::=
'(' ( _type ( ':' identifier )? ',' )* ( _type ( ':' identifier )? )? ')'
_expression ::=
identifier
| _literal
| array_comprehension
| call
| generator_call
| if_then_else
| indexed_access
| infix_operator
| let_expression
| prefix_operator
| set_comprehension
| string_interpolation
| parenthesised_expression
parenthesised_expression ::=
'(' _expression ')'
array_comprehension ::=
'[' _expression '|' generator ( ',' generator )* ','? ']'
call ::=
identifier '(' ( ( _expression ',' )* _expression? ) ')'
generator_call ::=
identifier '(' ( generator ( ',' generator )* ','? ) ')' '(' _expression ')'
generator ::=
identifier 'in' _expression ( 'where' _expression )?
if_then_else ::=
'if' _expression 'then' _expression ( 'elseif' _expression 'then' _expression )* ( 'else' _expression )? 'endif'
indexed_access ::=
_expression '[' ( _expression ( ',' _expression )* ) ']'
infix_operator ::=
_expression '<->' _expression
| _expression ( '->' | '<-' ) _expression
| _expression '\/' _expression
| _expression 'xor' _expression
| _expression '/\' _expression
| _expression ( '=' | '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'subset' | 'superset' ) _expression
| _expression 'union' _expression
| _expression 'diff' _expression
| _expression 'symdiff' _expression
| _expression 'intersect' _expression
| _expression '..' _expression
| _expression ( '+' | '-' | '++' ) _expression
| _expression ( '*' | '/' | 'div' | 'mod' ) _expression
| _expression '^' _expression
| _expression '::' _expression
let_expression ::=
'let' '{' ( ( ( declaration | constraint ) ( ',' | ';' ) )* ( declaration | constraint )? ) '}' 'in' _expression
prefix_operator ::=
( '-' | 'not' | '¬' ) _expression
set_comprehension ::=
'{' _expression '|' generator ( ',' generator )* ','? '}'
string_interpolation ::=
'"' string_content? ( '\(' _expression ')' string_content? )+ '"'
_type ::=
array_type
| type_base
array_type ::=
'array' '[' type_base ( ',' type_base )* ','? ']' 'of' _type
type_base ::=
( 'var' | 'par' )? 'opt'? ( 'set' 'of' )? ( primitive_type | _expression )
primitive_type ::=
'ann'
| 'bool'
| 'float'
| 'int'
| 'string'
_literal ::=
absent
| array_literal
| boolean_literal
| float_literal
| integer_literal
| set_literal
| string_literal
absent ::=
'<>'
array_literal ::=
'[' ( _expression ',' )* _expression? ']'
boolean_literal ::=
'true'
| 'false'
float_literal ::=
( [0-9]+'.'[0-9]+ | [0-9]+('.'[0-9]+)?[Ee][+-]?[0-9]+ )
integer_literal ::=
( [0-9]+ | '0x'[0-9a-fA-F]+ | '0b'[01]+ | '0o'[0-7]+ )
set_literal ::=
'{' ( _expression ',' )* _expression? '}'
string_literal ::=
'"' string_content? '"'
string_content ::=
( [^"#x0A\]+ | escape_sequence )+
escape_sequence ::=
( '\\' ( [^xuU] | [0-9]'{2,3}' | 'x'[0-9a-fA-F]'{2,}' | 'u'[0-9a-fA-F]'{4}' | 'U'[0-9a-fA-F]'{8}' ) )
identifier ::=
[A-Za-z][A-Za-z0-9_]*
line_comment ::=
( '%' '.'* )
block_comment ::=
( '/*' ([^*]|'\'*[^\/]|'#x0A')*?'\'*? '*/' )