Add enumerations
This commit is contained in:
parent
7b5536ad87
commit
4d07e3441b
@ -51,6 +51,21 @@ array[X, 1..23] of var int: simple_decl = some_call(X);
|
||||
(declaration (type_base (primitive_type)) (identifier))
|
||||
(declaration (array_type (type_base (identifier)) (type_base (infix_operator (integer_literal) (integer_literal))) (type_base (primitive_type))) (identifier) (call (identifier) (identifier))))
|
||||
|
||||
===========
|
||||
Enumeration
|
||||
===========
|
||||
|
||||
enum in_dzn;
|
||||
enum empty = {};
|
||||
enum with_members = {a, b, c};
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(enumeration name: (identifier))
|
||||
(enumeration name: (identifier))
|
||||
(enumeration name: (identifier) members: (identifier) members: (identifier) members: (identifier)))
|
||||
|
||||
========
|
||||
Function
|
||||
========
|
||||
|
@ -43,12 +43,12 @@ module.exports = grammar({
|
||||
$.assignment,
|
||||
$.constraint,
|
||||
$.declaration,
|
||||
$.enumeration,
|
||||
$.function_item,
|
||||
$.goal,
|
||||
$.include,
|
||||
$.output,
|
||||
$.predicate
|
||||
// TODO: Other statements types
|
||||
),
|
||||
|
||||
annotation: ($) =>
|
||||
@ -72,6 +72,13 @@ module.exports = grammar({
|
||||
optional(seq("=", field("expr", $._expression)))
|
||||
),
|
||||
|
||||
enumeration: ($) =>
|
||||
seq(
|
||||
"enum",
|
||||
field("name", $.identifier),
|
||||
optional(seq("=", "{", field("members", sepBy(",", $.identifier)), "}"))
|
||||
),
|
||||
|
||||
function_item: ($) =>
|
||||
seq(
|
||||
"function",
|
||||
|
@ -24,6 +24,7 @@
|
||||
"else"
|
||||
"elseif"
|
||||
"endif"
|
||||
"enum"
|
||||
"function"
|
||||
"if"
|
||||
"in"
|
||||
|
83
src/grammar.json
vendored
83
src/grammar.json
vendored
@ -59,6 +59,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "declaration"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "enumeration"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_item"
|
||||
@ -227,6 +231,85 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"enumeration": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "enum"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "="
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "members",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"function_item": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
38
src/node-types.json
vendored
38
src/node-types.json
vendored
@ -101,6 +101,10 @@
|
||||
"type": "declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "enumeration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_item",
|
||||
"named": true
|
||||
@ -369,6 +373,36 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "enumeration",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"members": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function_item",
|
||||
"named": true,
|
||||
@ -1241,6 +1275,10 @@
|
||||
"type": "endif",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "enum",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
|
20553
src/parser.c
vendored
20553
src/parser.c
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user