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 (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))))
|
(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
|
Function
|
||||||
========
|
========
|
||||||
|
@ -43,12 +43,12 @@ module.exports = grammar({
|
|||||||
$.assignment,
|
$.assignment,
|
||||||
$.constraint,
|
$.constraint,
|
||||||
$.declaration,
|
$.declaration,
|
||||||
|
$.enumeration,
|
||||||
$.function_item,
|
$.function_item,
|
||||||
$.goal,
|
$.goal,
|
||||||
$.include,
|
$.include,
|
||||||
$.output,
|
$.output,
|
||||||
$.predicate
|
$.predicate
|
||||||
// TODO: Other statements types
|
|
||||||
),
|
),
|
||||||
|
|
||||||
annotation: ($) =>
|
annotation: ($) =>
|
||||||
@ -72,6 +72,13 @@ module.exports = grammar({
|
|||||||
optional(seq("=", field("expr", $._expression)))
|
optional(seq("=", field("expr", $._expression)))
|
||||||
),
|
),
|
||||||
|
|
||||||
|
enumeration: ($) =>
|
||||||
|
seq(
|
||||||
|
"enum",
|
||||||
|
field("name", $.identifier),
|
||||||
|
optional(seq("=", "{", field("members", sepBy(",", $.identifier)), "}"))
|
||||||
|
),
|
||||||
|
|
||||||
function_item: ($) =>
|
function_item: ($) =>
|
||||||
seq(
|
seq(
|
||||||
"function",
|
"function",
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
"else"
|
"else"
|
||||||
"elseif"
|
"elseif"
|
||||||
"endif"
|
"endif"
|
||||||
|
"enum"
|
||||||
"function"
|
"function"
|
||||||
"if"
|
"if"
|
||||||
"in"
|
"in"
|
||||||
|
83
src/grammar.json
vendored
83
src/grammar.json
vendored
@ -59,6 +59,10 @@
|
|||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "declaration"
|
"name": "declaration"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "enumeration"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "function_item"
|
"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": {
|
"function_item": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
38
src/node-types.json
vendored
38
src/node-types.json
vendored
@ -101,6 +101,10 @@
|
|||||||
"type": "declaration",
|
"type": "declaration",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "enumeration",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "function_item",
|
"type": "function_item",
|
||||||
"named": true
|
"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",
|
"type": "function_item",
|
||||||
"named": true,
|
"named": true,
|
||||||
@ -1241,6 +1275,10 @@
|
|||||||
"type": "endif",
|
"type": "endif",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "enum",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "escape_sequence",
|
"type": "escape_sequence",
|
||||||
"named": true
|
"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