Skip to content

Commit fdd616d

Browse files
authored
Merge pull request #20 from Koihik/fix-incorrect-parse-order
fix: incorrect parse order
2 parents 21e0205 + 469859c commit fdd616d

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

Lua.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ exp:
108108
| prefixexp
109109
| functiondef
110110
| tableconstructor
111-
| exp linkOperator exp
112-
| unaryOperator exp;
111+
| unaryOperator exp
112+
| exp linkOperator exp;
113113

114114
prefixexp: varOrExp nameAndArgs*;
115115

generated/Lua.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

generated/LuaParser.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ LuaParser::ExpContext* LuaParser::exp(int precedence) {
18821882
setState(259);
18831883
unaryOperator();
18841884
setState(260);
1885-
exp(1);
1885+
exp(2);
18861886
break;
18871887
}
18881888

@@ -1902,11 +1902,11 @@ LuaParser::ExpContext* LuaParser::exp(int precedence) {
19021902
pushNewRecursionContext(_localctx, startState, RuleExp);
19031903
setState(264);
19041904

1905-
if (!(precpred(_ctx, 2))) throw FailedPredicateException(this, "precpred(_ctx, 2)");
1905+
if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)");
19061906
setState(265);
19071907
linkOperator();
19081908
setState(266);
1909-
exp(3);
1909+
exp(2);
19101910
}
19111911
setState(272);
19121912
_errHandler->sync(this);
@@ -3238,7 +3238,7 @@ bool LuaParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicate
32383238

32393239
bool LuaParser::expSempred(ExpContext *_localctx, size_t predicateIndex) {
32403240
switch (predicateIndex) {
3241-
case 0: return precpred(_ctx, 2);
3241+
case 0: return precpred(_ctx, 1);
32423242

32433243
default:
32443244
break;
@@ -3490,14 +3490,14 @@ LuaParser::Initializer::Initializer() {
34903490
0x2, 0x100, 0x109, 0x5, 0x4e, 0x28, 0x2, 0x101, 0x109, 0x7, 0x33, 0x2,
34913491
0x2, 0x102, 0x109, 0x5, 0x2e, 0x18, 0x2, 0x103, 0x109, 0x5, 0x3a, 0x1e,
34923492
0x2, 0x104, 0x109, 0x5, 0x40, 0x21, 0x2, 0x105, 0x106, 0x5, 0x4a, 0x26,
3493-
0x2, 0x106, 0x107, 0x5, 0x2c, 0x17, 0x3, 0x107, 0x109, 0x3, 0x2, 0x2,
3493+
0x2, 0x106, 0x107, 0x5, 0x2c, 0x17, 0x4, 0x107, 0x109, 0x3, 0x2, 0x2,
34943494
0x2, 0x108, 0xfb, 0x3, 0x2, 0x2, 0x2, 0x108, 0xfd, 0x3, 0x2, 0x2, 0x2,
34953495
0x108, 0xfe, 0x3, 0x2, 0x2, 0x2, 0x108, 0xff, 0x3, 0x2, 0x2, 0x2, 0x108,
34963496
0x100, 0x3, 0x2, 0x2, 0x2, 0x108, 0x101, 0x3, 0x2, 0x2, 0x2, 0x108,
34973497
0x102, 0x3, 0x2, 0x2, 0x2, 0x108, 0x103, 0x3, 0x2, 0x2, 0x2, 0x108,
34983498
0x104, 0x3, 0x2, 0x2, 0x2, 0x108, 0x105, 0x3, 0x2, 0x2, 0x2, 0x109,
3499-
0x110, 0x3, 0x2, 0x2, 0x2, 0x10a, 0x10b, 0xc, 0x4, 0x2, 0x2, 0x10b,
3500-
0x10c, 0x5, 0x48, 0x25, 0x2, 0x10c, 0x10d, 0x5, 0x2c, 0x17, 0x5, 0x10d,
3499+
0x110, 0x3, 0x2, 0x2, 0x2, 0x10a, 0x10b, 0xc, 0x3, 0x2, 0x2, 0x10b,
3500+
0x10c, 0x5, 0x48, 0x25, 0x2, 0x10c, 0x10d, 0x5, 0x2c, 0x17, 0x4, 0x10d,
35013501
0x10f, 0x3, 0x2, 0x2, 0x2, 0x10e, 0x10a, 0x3, 0x2, 0x2, 0x2, 0x10f,
35023502
0x112, 0x3, 0x2, 0x2, 0x2, 0x110, 0x10e, 0x3, 0x2, 0x2, 0x2, 0x110,
35033503
0x111, 0x3, 0x2, 0x2, 0x2, 0x111, 0x2d, 0x3, 0x2, 0x2, 0x2, 0x112, 0x110,

test/test_format_file.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ using namespace std;
2727
REQUIRE(expect == formatTwice); \
2828
}
2929

30+
TEST_FILE("../test/testdata/linebreak/args_length.lua");
3031
TEST_FILE("../test/testdata/linebreak/block.lua");
32+
TEST_FILE("../test/testdata/linebreak/chained_call_args.lua");
3133
TEST_FILE("../test/testdata/linebreak/functioncall.lua");
3234
TEST_FILE("../test/testdata/linebreak/functiondef.lua");
35+
TEST_FILE("../test/testdata/linebreak/indent_in_explist.lua");
36+
TEST_FILE("../test/testdata/linebreak/long_var.lua");
37+
TEST_FILE("../test/testdata/linebreak/nested_method_call.lua");
3338
TEST_FILE("../test/testdata/linebreak/operators.lua");
3439
TEST_FILE("../test/testdata/linebreak/table.lua");
35-
TEST_FILE("../test/testdata/linebreak/chained_call_args.lua");
36-
TEST_FILE("../test/testdata/linebreak/nested_method_call.lua");
37-
TEST_FILE("../test/testdata/linebreak/args_length.lua");
3840

3941
TEST_FILE("../test/testdata/comment/function.lua");
4042
TEST_FILE("../test/testdata/comment/space.lua");
@@ -50,3 +52,4 @@ TEST_FILE("../test/testdata/statement/statements.lua");
5052
TEST_FILE("../test/testdata/statement/table.lua");
5153

5254
TEST_FILE("../test/testdata/issues/issue-1.lua");
55+
TEST_FILE("../test/testdata/issues/issue-18.lua");

test/testdata/issues/_issue-18.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if aaaaaaa == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and
2+
b == -1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and
3+
bbbbb == 1 and bbbbb == 1 then print(1) end

test/testdata/issues/issue-18.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if aaaaaaa == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and
2+
b ==
3+
-1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb == 1 and bbbbb ==
4+
1 and bbbbb == 1 then print(1) end

0 commit comments

Comments
 (0)