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

View File

@ -17,9 +17,13 @@
"name": "comment" "name": "comment"
}, },
{ {
"type": "FIELD",
"name": "source",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "statement"
} }
}
] ]
}, },
"comment": { "comment": {
@ -180,9 +184,6 @@
"value": "[a-z|_|.]+[0-9]?" "value": "[a-z|_|.]+[0-9]?"
}, },
"value": { "value": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -218,7 +219,6 @@
"name": "map" "name": "map"
} }
] ]
}
}, },
"float": { "float": {
"type": "PATTERN", "type": "PATTERN",
@ -429,6 +429,9 @@
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
"content": {
"type": "FIELD",
"name": "key_value_pair",
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -446,6 +449,7 @@
} }
] ]
} }
}
}, },
{ {
"type": "STRING", "type": "STRING",
@ -685,16 +689,24 @@
"value": "if" "value": "if"
}, },
{ {
"type": "FIELD",
"name": "if_expression",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "then" "value": "then"
}, },
{ {
"type": "FIELD",
"name": "then_statement",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "statement"
}
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -707,9 +719,13 @@
"value": "else" "value": "else"
}, },
{ {
"type": "FIELD",
"name": "else_statement",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "statement"
} }
}
] ]
}, },
{ {

View File

@ -46,20 +46,37 @@
{ {
"type": "control_flow", "type": "control_flow",
"named": true, "named": true,
"fields": {}, "fields": {
"children": { "else_statement": {
"multiple": true, "multiple": false,
"required": true, "required": false,
"types": [ "types": [
{
"type": "expression",
"named": true
},
{ {
"type": "statement", "type": "statement",
"named": true "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", "type": "item",
"named": true, "named": true,
"fields": {}, "fields": {
"source": {
"multiple": false,
"required": false,
"types": [
{
"type": "statement",
"named": true
}
]
}
},
"children": { "children": {
"multiple": false, "multiple": false,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "comment", "type": "comment",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -259,11 +283,15 @@
{ {
"type": "map", "type": "map",
"named": true, "named": true,
"fields": {}, "fields": {
"children": { "key_value_pair": {
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "=",
"named": false
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -274,6 +302,7 @@
} }
] ]
} }
}
}, },
{ {
"type": "match", "type": "match",

17409
src/parser.c

File diff suppressed because it is too large Load Diff