Skip to content

Commit 68211f5

Browse files
authored
Merge pull request #144 from afroozeh/main
Make the 'else' part explicit in parse trees
2 parents dc5e8a1 + 8c7c0ca commit 68211f5

File tree

6 files changed

+502284
-495709
lines changed

6 files changed

+502284
-495709
lines changed

grammar.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,16 @@ module.exports = grammar({
829829

830830
if_expression: $ => prec.right(seq(
831831
"if",
832-
"(", $._expression, ")",
832+
"(", field('condition', $._expression), ")",
833833
choice(
834-
$.control_structure_body,
835-
";",
834+
field('consequence', $.control_structure_body),
836835
seq(
837-
optional($.control_structure_body),
836+
optional(field('consequence', $.control_structure_body)),
838837
optional(";"),
839-
"else",
840-
choice($.control_structure_body, ";")
841-
)
838+
"else",
839+
choice(field('alternative', $.control_structure_body), ";")
840+
),
841+
";"
842842
)
843843
)),
844844

src/grammar.json

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,8 +4245,12 @@
42454245
"value": "("
42464246
},
42474247
{
4248-
"type": "SYMBOL",
4249-
"name": "_expression"
4248+
"type": "FIELD",
4249+
"name": "condition",
4250+
"content": {
4251+
"type": "SYMBOL",
4252+
"name": "_expression"
4253+
}
42504254
},
42514255
{
42524256
"type": "STRING",
@@ -4256,12 +4260,12 @@
42564260
"type": "CHOICE",
42574261
"members": [
42584262
{
4259-
"type": "SYMBOL",
4260-
"name": "control_structure_body"
4261-
},
4262-
{
4263-
"type": "STRING",
4264-
"value": ";"
4263+
"type": "FIELD",
4264+
"name": "consequence",
4265+
"content": {
4266+
"type": "SYMBOL",
4267+
"name": "control_structure_body"
4268+
}
42654269
},
42664270
{
42674271
"type": "SEQ",
@@ -4270,8 +4274,12 @@
42704274
"type": "CHOICE",
42714275
"members": [
42724276
{
4273-
"type": "SYMBOL",
4274-
"name": "control_structure_body"
4277+
"type": "FIELD",
4278+
"name": "consequence",
4279+
"content": {
4280+
"type": "SYMBOL",
4281+
"name": "control_structure_body"
4282+
}
42754283
},
42764284
{
42774285
"type": "BLANK"
@@ -4298,8 +4306,12 @@
42984306
"type": "CHOICE",
42994307
"members": [
43004308
{
4301-
"type": "SYMBOL",
4302-
"name": "control_structure_body"
4309+
"type": "FIELD",
4310+
"name": "alternative",
4311+
"content": {
4312+
"type": "SYMBOL",
4313+
"name": "control_structure_body"
4314+
}
43034315
},
43044316
{
43054317
"type": "STRING",
@@ -4308,6 +4320,10 @@
43084320
]
43094321
}
43104322
]
4323+
},
4324+
{
4325+
"type": "STRING",
4326+
"value": ";"
43114327
}
43124328
]
43134329
}

0 commit comments

Comments
 (0)