1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +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:
Jonathan Coates 2023-02-04 12:44:07 +00:00
parent 366052ec48
commit 22cadd6730
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
3 changed files with 527 additions and 870 deletions

View File

@ -8,7 +8,7 @@
```
```txt
Unexpected until.
Unexpected until. Expected a statement.
|
1 | break until
| ^^^^^
@ -76,7 +76,7 @@
```
```txt
Unexpected while.
Unexpected while. Expected a statement.
|
1 | for xyz , xyz while
| ^^^^^
@ -96,6 +96,22 @@
```
```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
for xyz = xyz , xyz , xyz while
-- Line 1: 'do' expected near 'while' (program)
@ -290,10 +306,13 @@
```
```txt
Unexpected until. Expected a statement.
Unexpected until. Expected end or another statement.
|
1 | function xyz ( ) until
| ^^^^^
| ^^^^^^^^ Block started here.
|
1 | function xyz ( ) until
| ^^^^^ Expected end of block here.
```
@ -303,7 +322,7 @@
```
```txt
Unexpected while.
Unexpected while. Expected ( to start function arguments.
|
1 | function xyz while
| ^^^^^
@ -316,10 +335,13 @@
```
```txt
Unexpected until. Expected a statement.
Unexpected until. Expected end or another statement.
|
1 | function ( ) until
| ^^^^^
| ^^^^^^^^ Block started here.
|
1 | function ( ) until
| ^^^^^ Expected end of block here.
```
@ -843,7 +865,7 @@
Unexpected until. Expected end or another statement.
|
1 | if xyz then else until
| ^^ Block started here.
| ^^^^ Block started here.
|
1 | if xyz then else until
| ^^^^^ Expected end of block here.
@ -943,10 +965,13 @@ # while
```
```txt
Unexpected until. Expected a statement.
Unexpected until. Expected end or another statement.
|
1 | local function xyz ( ) until
| ^^^^^
| ^^^^^^^^^^^^^^ Block started here.
|
1 | local function xyz ( ) until
| ^^^^^ Expected end of block here.
```

View File

@ -209,6 +209,38 @@ ## Expecting `end`
| ^ 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
while true do
print("Hello")
@ -224,6 +256,48 @@ ## Expecting `end`
| ^ 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
where it may occur before then:
@ -276,6 +350,7 @@ ## Unexpected `end`
|
3 | end
| ^^^
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
```
```lua
@ -291,4 +366,5 @@ ## Unexpected `end`
|
4 | end
| ^^^
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
```