Skip to content

Commit

Permalink
Allow a single ; after a break statement in Lua 5.1 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fstirlitz committed Jun 7, 2021
1 parent 0852fc4 commit d61c6fe
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions luaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,7 @@
// break ::= 'break'

function parseBreakStatement() {
consume(';');
return finishNode(ast.breakStatement());
}

Expand Down
3 changes: 3 additions & 0 deletions test/scaffolding/break
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repeat do break end until 0
repeat if 0 then break end until 0
repeat if 0 then else break end until 0
while 0 do break end
while 0 do break; end
while 0 do break;; end -- FAIL
while 0 do do break end end
while 0 do if 0 then break end end
while 0 do if 0 then else break end end
Expand All @@ -29,6 +31,7 @@ break -- FAIL
do break end -- FAIL
if 0 then break end -- FAIL
if 0 then else break end -- FAIL
while 0 do break;; end
while 0 do function x() break end end -- FAIL
repeat function x() break end until 0 -- FAIL
repeat x = function() break end until 0 -- FAIL
Expand Down
169 changes: 169 additions & 0 deletions test/spec/break.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,89 @@
"globals": []
}
},
{
"source": "while 0 do break; end",
"result": {
"type": "Chunk",
"body": [
{
"type": "WhileStatement",
"condition": {
"type": "NumericLiteral",
"value": 0,
"raw": "0",
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
},
"range": [
6,
7
]
},
"body": [
{
"type": "BreakStatement",
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 17
}
},
"range": [
11,
17
]
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"range": [
0,
21
]
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"range": [
0,
21
],
"comments": [],
"globals": []
}
},
{
"source": "while 0 do break;; end",
"result": "[1:17] 'end' expected near ';'"
},
{
"source": "while 0 do do break end end",
"result": {
Expand Down Expand Up @@ -2432,6 +2515,92 @@
"luaVersion": "5.2"
}
},
{
"source": "while 0 do break;; end",
"result": {
"type": "Chunk",
"body": [
{
"type": "WhileStatement",
"condition": {
"type": "NumericLiteral",
"value": 0,
"raw": "0",
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
},
"range": [
6,
7
]
},
"body": [
{
"type": "BreakStatement",
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 17
}
},
"range": [
11,
17
]
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"range": [
0,
22
]
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"range": [
0,
22
],
"comments": [],
"globals": []
},
"options": {
"comments": true,
"locations": true,
"ranges": true,
"scope": true,
"luaVersion": "5.2"
}
},
{
"source": "while 0 do function x() break end end",
"result": "[1:30] no loop to break near 'end'",
Expand Down

0 comments on commit d61c6fe

Please sign in to comment.