Skip to content

Commit

Permalink
Merge pull request #144 from afroozeh/main
Browse files Browse the repository at this point in the history
Make the 'else' part explicit in parse trees
  • Loading branch information
fwcd authored Aug 31, 2024
2 parents dc5e8a1 + 8c7c0ca commit 68211f5
Show file tree
Hide file tree
Showing 6 changed files with 502,284 additions and 495,709 deletions.
14 changes: 7 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,16 @@ module.exports = grammar({

if_expression: $ => prec.right(seq(
"if",
"(", $._expression, ")",
"(", field('condition', $._expression), ")",
choice(
$.control_structure_body,
";",
field('consequence', $.control_structure_body),
seq(
optional($.control_structure_body),
optional(field('consequence', $.control_structure_body)),
optional(";"),
"else",
choice($.control_structure_body, ";")
)
"else",
choice(field('alternative', $.control_structure_body), ";")
),
";"
)
)),

Expand Down
40 changes: 28 additions & 12 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4245,8 +4245,12 @@
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression"
"type": "FIELD",
"name": "condition",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "STRING",
Expand All @@ -4256,12 +4260,12 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "control_structure_body"
},
{
"type": "STRING",
"value": ";"
"type": "FIELD",
"name": "consequence",
"content": {
"type": "SYMBOL",
"name": "control_structure_body"
}
},
{
"type": "SEQ",
Expand All @@ -4270,8 +4274,12 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "control_structure_body"
"type": "FIELD",
"name": "consequence",
"content": {
"type": "SYMBOL",
"name": "control_structure_body"
}
},
{
"type": "BLANK"
Expand All @@ -4298,8 +4306,12 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "control_structure_body"
"type": "FIELD",
"name": "alternative",
"content": {
"type": "SYMBOL",
"name": "control_structure_body"
}
},
{
"type": "STRING",
Expand All @@ -4308,6 +4320,10 @@
]
}
]
},
{
"type": "STRING",
"value": ";"
}
]
}
Expand Down
Loading

0 comments on commit 68211f5

Please sign in to comment.