Skip to content

Commit

Permalink
parser: parse else if then statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbz64 committed Oct 25, 2023
1 parent f0d8350 commit 3551921
Show file tree
Hide file tree
Showing 5 changed files with 17,664 additions and 16,908 deletions.
11 changes: 10 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,19 @@ module.exports = grammar({
field("condition", $._expression),
kw("THEN"),
$._terminated_statement,
optional(repeat($.else_then_if_statement)),
optional($.else_then_statement)
),

else_then_statement: ($) => seq("ELSE", $._terminated_statement),
else_then_if_statement: ($) =>
seq(
kw("ELSE"),
kw("IF"),
field("condition", $._expression),
kw("THEN"),
$._terminated_statement
),
else_then_statement: ($) => seq(kw("ELSE"), $._terminated_statement),

ternary_expression: ($) =>
prec.right(
Expand Down
94 changes: 93 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,21 @@
"type": "SYMBOL",
"name": "_terminated_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "else_then_if_statement"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand All @@ -2225,11 +2240,88 @@
}
]
},
"else_then_if_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][lL][sS][eE]"
}
}
},
"named": false,
"value": "ELSE"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[iI][fF]"
}
}
},
"named": false,
"value": "IF"
},
{
"type": "FIELD",
"name": "condition",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[tT][hH][eE][nN]"
}
}
},
"named": false,
"value": "THEN"
},
{
"type": "SYMBOL",
"name": "_terminated_statement"
}
]
},
"else_then_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][lL][sS][eE]"
}
}
},
"named": false,
"value": "ELSE"
},
{
Expand Down
42 changes: 42 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,44 @@
]
}
},
{
"type": "else_then_if_statement",
"named": true,
"fields": {
"condition": {
"multiple": false,
"required": true,
"types": [
{
"type": "_expression",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "abl_statement",
"named": true
},
{
"type": "function_call_statement",
"named": true
},
{
"type": "return_statement",
"named": true
},
{
"type": "variable_assignment",
"named": true
}
]
}
},
{
"type": "else_then_statement",
"named": true,
Expand Down Expand Up @@ -1207,6 +1245,10 @@
"type": "abl_statement",
"named": true
},
{
"type": "else_then_if_statement",
"named": true
},
{
"type": "else_then_statement",
"named": true
Expand Down
Loading

0 comments on commit 3551921

Please sign in to comment.