mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-05-14 05:14:11 +00:00
Various improvements to our Lua parser
- Encode the DFA as a virtual machine (identical to lrgrep) rather than compiling it to a series of Lua functions. While this is a little slower and uglier, it's much more space efficient, shaving off 16Kb. - Minimise the DFA properly. This only shaves off a few states, but every little helps. - Run the error handling code from a non-reduced parser stack. This was incredibly nasty to get right (and positions are still not correctly handled), but it fixes several broken error messages.
This commit is contained in:
parent
366052ec48
commit
22cadd6730
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@ break until
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected until.
|
Unexpected until. Expected a statement.
|
||||||
|
|
|
|
||||||
1 | break until
|
1 | break until
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -76,7 +76,7 @@ for xyz , xyz while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected while.
|
Unexpected while. Expected a statement.
|
||||||
|
|
|
|
||||||
1 | for xyz , xyz while
|
1 | for xyz , xyz while
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -96,6 +96,22 @@ Unexpected while. Expected a variable name.
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```lua
|
||||||
|
for xyz = xyz , xyz , xyz do until
|
||||||
|
-- Line 1: 'end' expected near 'until' (program)
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected until. Expected end or another statement.
|
||||||
|
|
|
||||||
|
1 | for xyz = xyz , xyz , xyz do until
|
||||||
|
| ^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | for xyz = xyz , xyz , xyz do until
|
||||||
|
| ^^^^^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
for xyz = xyz , xyz , xyz while
|
for xyz = xyz , xyz , xyz while
|
||||||
-- Line 1: 'do' expected near 'while' (program)
|
-- Line 1: 'do' expected near 'while' (program)
|
||||||
@ -290,10 +306,13 @@ function xyz ( ) until
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected until. Expected a statement.
|
Unexpected until. Expected end or another statement.
|
||||||
|
|
|
|
||||||
1 | function xyz ( ) until
|
1 | function xyz ( ) until
|
||||||
| ^^^^^
|
| ^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | function xyz ( ) until
|
||||||
|
| ^^^^^ Expected end of block here.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -303,7 +322,7 @@ function xyz while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected while.
|
Unexpected while. Expected ( to start function arguments.
|
||||||
|
|
|
|
||||||
1 | function xyz while
|
1 | function xyz while
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -316,10 +335,13 @@ function ( ) until
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected until. Expected a statement.
|
Unexpected until. Expected end or another statement.
|
||||||
|
|
|
|
||||||
1 | function ( ) until
|
1 | function ( ) until
|
||||||
| ^^^^^
|
| ^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | function ( ) until
|
||||||
|
| ^^^^^ Expected end of block here.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -843,7 +865,7 @@ if xyz then else until
|
|||||||
Unexpected until. Expected end or another statement.
|
Unexpected until. Expected end or another statement.
|
||||||
|
|
|
|
||||||
1 | if xyz then else until
|
1 | if xyz then else until
|
||||||
| ^^ Block started here.
|
| ^^^^ Block started here.
|
||||||
|
|
|
|
||||||
1 | if xyz then else until
|
1 | if xyz then else until
|
||||||
| ^^^^^ Expected end of block here.
|
| ^^^^^ Expected end of block here.
|
||||||
@ -943,10 +965,13 @@ local function xyz ( ) until
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected until. Expected a statement.
|
Unexpected until. Expected end or another statement.
|
||||||
|
|
|
|
||||||
1 | local function xyz ( ) until
|
1 | local function xyz ( ) until
|
||||||
| ^^^^^
|
| ^^^^^^^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | local function xyz ( ) until
|
||||||
|
| ^^^^^ Expected end of block here.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,6 +209,38 @@ Unexpected end of file. Expected end or another statement.
|
|||||||
| ^ Expected end of block here.
|
| ^ Expected end of block here.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
if true then
|
||||||
|
else
|
||||||
|
print("Hello")
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected end or another statement.
|
||||||
|
|
|
||||||
|
2 | else
|
||||||
|
| ^^^^ Block started here.
|
||||||
|
|
|
||||||
|
3 | print("Hello")
|
||||||
|
| ^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
if true then
|
||||||
|
elseif true then
|
||||||
|
print("Hello")
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected end or another statement.
|
||||||
|
|
|
||||||
|
2 | elseif true then
|
||||||
|
| ^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
3 | print("Hello")
|
||||||
|
| ^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
while true do
|
while true do
|
||||||
print("Hello")
|
print("Hello")
|
||||||
@ -224,6 +256,48 @@ Unexpected end of file. Expected end or another statement.
|
|||||||
| ^ Expected end of block here.
|
| ^ Expected end of block here.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local function f()
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected end or another statement.
|
||||||
|
|
|
||||||
|
1 | local function f()
|
||||||
|
| ^^^^^^^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | local function f()
|
||||||
|
| ^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
function f()
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected end or another statement.
|
||||||
|
|
|
||||||
|
1 | function f()
|
||||||
|
| ^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | function f()
|
||||||
|
| ^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
return function()
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected end or another statement.
|
||||||
|
|
|
||||||
|
1 | return function()
|
||||||
|
| ^^^^^^^^ Block started here.
|
||||||
|
|
|
||||||
|
1 | return function()
|
||||||
|
| ^ Expected end of block here.
|
||||||
|
```
|
||||||
|
|
||||||
While we typically see these errors at the end of the file, there are some cases
|
While we typically see these errors at the end of the file, there are some cases
|
||||||
where it may occur before then:
|
where it may occur before then:
|
||||||
|
|
||||||
@ -276,6 +350,7 @@ Unexpected end.
|
|||||||
|
|
|
|
||||||
3 | end
|
3 | end
|
||||||
| ^^^
|
| ^^^
|
||||||
|
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -291,4 +366,5 @@ Unexpected end.
|
|||||||
|
|
|
|
||||||
4 | end
|
4 | end
|
||||||
| ^^^
|
| ^^^
|
||||||
|
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user