Add simple keyword items
This commit is contained in:
parent
686f3154ce
commit
ffaa229697
59
corpus/items.txt
Normal file
59
corpus/items.txt
Normal file
@ -0,0 +1,59 @@
|
||||
==========
|
||||
Assignment
|
||||
==========
|
||||
|
||||
this = that;
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(assignment (identifier) (identifier)))
|
||||
|
||||
|
||||
==========
|
||||
Constraint
|
||||
==========
|
||||
|
||||
constraint true;
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(constraint (boolean_literal)))
|
||||
|
||||
====
|
||||
Goal
|
||||
====
|
||||
|
||||
solve satisfy;
|
||||
solve maximize this;
|
||||
solve minimize that;
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(goal)
|
||||
(goal (identifier))
|
||||
(goal (identifier)))
|
||||
|
||||
=======
|
||||
Include
|
||||
=======
|
||||
|
||||
include "globals.mzn";
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(include (string_literal)))
|
||||
|
||||
=======
|
||||
Output
|
||||
=======
|
||||
|
||||
output ["something"];
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(output (array_literal (string_literal))))
|
18
grammar.js
18
grammar.js
@ -39,6 +39,10 @@ module.exports = grammar({
|
||||
|
||||
_item: $ => choice(
|
||||
$.assignment,
|
||||
$.constraint,
|
||||
$.goal,
|
||||
$.include,
|
||||
$.output,
|
||||
// TODO: Other statements types
|
||||
),
|
||||
|
||||
@ -48,6 +52,20 @@ module.exports = grammar({
|
||||
field('expr', $._expression)
|
||||
),
|
||||
|
||||
constraint: $ => seq('constraint', $._expression),
|
||||
|
||||
goal: $ => seq(
|
||||
'solve', field('strategy', choice(
|
||||
'satisfy',
|
||||
seq('maximize', $._expression),
|
||||
seq('minimize', $._expression),
|
||||
)),
|
||||
),
|
||||
|
||||
include: $ => seq('include', $.string_literal),
|
||||
|
||||
output: $ => seq('output', $._expression),
|
||||
|
||||
_expression: $ => choice(
|
||||
$.identifier,
|
||||
$._literal,
|
||||
|
103
src/grammar.json
vendored
103
src/grammar.json
vendored
@ -46,6 +46,22 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assignment"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "constraint"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "goal"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "include"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "output"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -74,6 +90,93 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"constraint": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "constraint"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"goal": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "solve"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "strategy",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "satisfy"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "maximize"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "minimize"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "include"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string_literal"
|
||||
}
|
||||
]
|
||||
},
|
||||
"output": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "output"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
117
src/node-types.json
vendored
117
src/node-types.json
vendored
@ -84,6 +84,22 @@
|
||||
{
|
||||
"type": "assignment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "goal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "include",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "output",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -182,6 +198,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "constraint",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "content",
|
||||
"named": false,
|
||||
@ -252,6 +283,34 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "goal",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"strategy": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "maximize",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "minimize",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "satisfy",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if_then_else",
|
||||
"named": true,
|
||||
@ -267,6 +326,21 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "include",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "indexed_access",
|
||||
"named": true,
|
||||
@ -449,6 +523,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "output",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "parenthesised_expression",
|
||||
"named": true,
|
||||
@ -702,6 +791,10 @@
|
||||
"type": "absent",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "constraint",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "diff",
|
||||
"named": false
|
||||
@ -746,6 +839,10 @@
|
||||
"type": "in",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "include",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
@ -754,6 +851,14 @@
|
||||
"type": "intersect",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "maximize",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "minimize",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "mod",
|
||||
"named": false
|
||||
@ -762,6 +867,18 @@
|
||||
"type": "not",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "output",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "satisfy",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "solve",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "subset",
|
||||
"named": false
|
||||
|
12419
src/parser.c
vendored
12419
src/parser.c
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user