Skip to content

Commit 5976424

Browse files
authored
replace command_call with left associativity (Wilfred#2)
This fits the definition of how command call is evaluated perfectly!
1 parent 20c0878 commit 5976424

File tree

3 files changed

+3553
-3165
lines changed

3 files changed

+3553
-3165
lines changed

grammar.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ module.exports = grammar({
5151

5252
extras: $ => [' ', $._spaces_before_comment, $.comment],
5353

54-
conflicts: $ => [
55-
[$._expression_argument_list, $._command_argument_list]
56-
],
57-
5854
rules: {
5955
source_file: $ => seq(
6056
$._indent_start,
@@ -64,8 +60,7 @@ module.exports = grammar({
6460

6561
_statement: $ => choice(
6662
$._declaration,
67-
$._expression,
68-
alias($._command_call, $.call)
63+
$._expression
6964
),
7065

7166
_command_call: $ => seq(
@@ -186,15 +181,12 @@ module.exports = grammar({
186181

187182
call: $ => seq(
188183
field('function', $.identifier),
189-
field('arguments', $._expression_argument_list)
184+
field('arguments', $.argument_list)
190185
),
191186

192-
_expression_argument_list: $ => alias(
193-
choice(
194-
$._paren_argument_list,
195-
$._expression
196-
),
197-
$.argument_list
187+
argument_list: $ => choice(
188+
$._paren_argument_list,
189+
$._command_argument_list
198190
),
199191

200192
_paren_argument_list: $ => seq(
@@ -203,7 +195,9 @@ module.exports = grammar({
203195
')'
204196
),
205197

206-
_command_argument_list: $ => repeatSepInd1($, ',', $._expression),
198+
_command_argument_list: $ => prec.left(
199+
repeatSepInd1($, ',', $._expression)
200+
),
207201

208202
_literal: $ => choice(
209203
$.boolean_literal,

src/grammar.json

Lines changed: 57 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@
6161
{
6262
"type": "SYMBOL",
6363
"name": "_expression"
64-
},
65-
{
66-
"type": "ALIAS",
67-
"content": {
68-
"type": "SYMBOL",
69-
"name": "_command_call"
70-
},
71-
"named": true,
72-
"value": "call"
7364
}
7465
]
7566
},
@@ -890,28 +881,23 @@
890881
"name": "arguments",
891882
"content": {
892883
"type": "SYMBOL",
893-
"name": "_expression_argument_list"
884+
"name": "argument_list"
894885
}
895886
}
896887
]
897888
},
898-
"_expression_argument_list": {
899-
"type": "ALIAS",
900-
"content": {
901-
"type": "CHOICE",
902-
"members": [
903-
{
904-
"type": "SYMBOL",
905-
"name": "_paren_argument_list"
906-
},
907-
{
908-
"type": "SYMBOL",
909-
"name": "_expression"
910-
}
911-
]
912-
},
913-
"named": true,
914-
"value": "argument_list"
889+
"argument_list": {
890+
"type": "CHOICE",
891+
"members": [
892+
{
893+
"type": "SYMBOL",
894+
"name": "_paren_argument_list"
895+
},
896+
{
897+
"type": "SYMBOL",
898+
"name": "_command_argument_list"
899+
}
900+
]
915901
},
916902
"_paren_argument_list": {
917903
"type": "SEQ",
@@ -977,46 +963,50 @@
977963
]
978964
},
979965
"_command_argument_list": {
980-
"type": "SEQ",
981-
"members": [
982-
{
983-
"type": "SYMBOL",
984-
"name": "_expression"
985-
},
986-
{
987-
"type": "REPEAT",
988-
"content": {
989-
"type": "SEQ",
990-
"members": [
991-
{
992-
"type": "SEQ",
993-
"members": [
994-
{
995-
"type": "STRING",
996-
"value": ","
997-
},
998-
{
999-
"type": "CHOICE",
1000-
"members": [
1001-
{
1002-
"type": "SYMBOL",
1003-
"name": "_indent_ge"
1004-
},
1005-
{
1006-
"type": "BLANK"
1007-
}
1008-
]
1009-
}
1010-
]
1011-
},
1012-
{
1013-
"type": "SYMBOL",
1014-
"name": "_expression"
1015-
}
1016-
]
966+
"type": "PREC_LEFT",
967+
"value": 0,
968+
"content": {
969+
"type": "SEQ",
970+
"members": [
971+
{
972+
"type": "SYMBOL",
973+
"name": "_expression"
974+
},
975+
{
976+
"type": "REPEAT",
977+
"content": {
978+
"type": "SEQ",
979+
"members": [
980+
{
981+
"type": "SEQ",
982+
"members": [
983+
{
984+
"type": "STRING",
985+
"value": ","
986+
},
987+
{
988+
"type": "CHOICE",
989+
"members": [
990+
{
991+
"type": "SYMBOL",
992+
"name": "_indent_ge"
993+
},
994+
{
995+
"type": "BLANK"
996+
}
997+
]
998+
}
999+
]
1000+
},
1001+
{
1002+
"type": "SYMBOL",
1003+
"name": "_expression"
1004+
}
1005+
]
1006+
}
10171007
}
1018-
}
1019-
]
1008+
]
1009+
}
10201010
},
10211011
"_literal": {
10221012
"type": "CHOICE",
@@ -2001,12 +1991,7 @@
20011991
"name": "comment"
20021992
}
20031993
],
2004-
"conflicts": [
2005-
[
2006-
"_expression_argument_list",
2007-
"_command_argument_list"
2008-
]
2009-
],
1994+
"conflicts": [],
20101995
"precedences": [],
20111996
"externals": [
20121997
{

0 commit comments

Comments
 (0)