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

17409
src/parser.c

File diff suppressed because it is too large Load Diff