Fix control flow

This commit is contained in:
Jeff 2023-10-02 18:54:49 -04:00
parent 89a9f6ebb9
commit bcc3557b77
5 changed files with 8888 additions and 8778 deletions

@ -1 +1 @@
Subproject commit 41483f6b84b83488ff02512bfad8719cd62481fc
Subproject commit a42b43ed7853b73e8bb42b0ab23765acc1fc78c1

View File

@ -8,7 +8,7 @@ module.exports = grammar({
item: $ => choice(
$.comment,
$.statement,
field('source', $.statement),
),
comment: $ => seq(token('#'), /.*/),
@ -48,7 +48,7 @@ module.exports = grammar({
identifier: $ => /[a-z|_|.]+[0-9]?/,
value: $ => prec.left(1, choice(
value: $ => choice(
$.integer,
$.float,
$.string,
@ -57,7 +57,7 @@ module.exports = grammar({
$.function,
$.table,
$.map,
)),
),
float: $ => /[-]*[0-9]*[.]{1}[0-9]+/,
@ -95,7 +95,7 @@ module.exports = grammar({
map: $ => seq(
'map',
'{',
repeat(seq($.identifier, "=", $.value)),
repeat(field('key_value_pair', seq($.identifier, "=", $.value))),
'}',
),
@ -155,10 +155,14 @@ module.exports = grammar({
control_flow: $ => prec.right(seq(
'if',
$.expression,
field('if_expression', $.expression),
'then',
$.statement,
optional(seq('else', $.statement))
field('then_statement', $.statement),
optional(
seq('else',
field('else_statement', $.statement),
),
),
)),
function_call: $ => prec.right(seq(

View File

@ -17,8 +17,12 @@
"name": "comment"
},
{
"type": "SYMBOL",
"name": "statement"
"type": "FIELD",
"name": "source",
"content": {
"type": "SYMBOL",
"name": "statement"
}
}
]
},
@ -180,45 +184,41 @@
"value": "[a-z|_|.]+[0-9]?"
},
"value": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "function"
},
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "map"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "function"
},
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "map"
}
]
},
"float": {
"type": "PATTERN",
@ -430,21 +430,25 @@
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "value"
}
]
"type": "FIELD",
"name": "key_value_pair",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
}
},
{
@ -685,16 +689,24 @@
"value": "if"
},
{
"type": "SYMBOL",
"name": "expression"
"type": "FIELD",
"name": "if_expression",
"content": {
"type": "SYMBOL",
"name": "expression"
}
},
{
"type": "STRING",
"value": "then"
},
{
"type": "SYMBOL",
"name": "statement"
"type": "FIELD",
"name": "then_statement",
"content": {
"type": "SYMBOL",
"name": "statement"
}
},
{
"type": "CHOICE",
@ -707,8 +719,12 @@
"value": "else"
},
{
"type": "SYMBOL",
"name": "statement"
"type": "FIELD",
"name": "else_statement",
"content": {
"type": "SYMBOL",
"name": "statement"
}
}
]
},

View File

@ -46,20 +46,37 @@
{
"type": "control_flow",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
"fields": {
"else_statement": {
"multiple": false,
"required": false,
"types": [
{
"type": "statement",
"named": true
}
]
},
"if_expression": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
},
"then_statement": {
"multiple": false,
"required": true,
"types": [
{
"type": "statement",
"named": true
}
]
}
}
},
{
@ -181,18 +198,25 @@
{
"type": "item",
"named": true,
"fields": {},
"fields": {
"source": {
"multiple": false,
"required": false,
"types": [
{
"type": "statement",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "comment",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
@ -259,20 +283,25 @@
{
"type": "map",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
"fields": {
"key_value_pair": {
"multiple": true,
"required": false,
"types": [
{
"type": "=",
"named": false
},
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
}
}
},
{

17409
src/parser.c

File diff suppressed because it is too large Load Diff