parser: Tweak parsing during error conditions

When an explicit parsing error is encountered and a CompileError raised,
apply the changes to the context state. This way, the rule that catches
the exception (e.g. Statement or Until) knows where the error occurred.

Also, changed "Expected" errors to be reported at the end of the
previous non-whitespace token.
This commit is contained in:
James Westman 2025-05-03 10:10:06 -05:00
parent e5d6910626
commit 8f3ae9a626
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
10 changed files with 69 additions and 37 deletions

View file

@ -1 +1 @@
1,0,0,File must start with a "using Gtk" directive (e.g. `using Gtk 4.0;`)
1,1,0,File must start with a "using Gtk" directive (e.g. `using Gtk 4.0;`)

View file

@ -1 +1 @@
6,1,1,Expected `;`
5,4,0,Expected `;`

View file

@ -1,2 +1 @@
5,1,0,Expected a signal detail name
4,9,3,Unexpected tokens
4,11,0,Expected a signal detail name

View file

@ -1,2 +1 @@
4,5,21,Attributes are not permitted at the top level of a menu
4,16,10,Unexpected tokens
4,5,21,Attributes are not permitted at the top level of a menu

View file

@ -1 +1 @@
1,11,0,Expected a version number for GTK
1,10,0,Expected a version number for GTK

View file

@ -143,9 +143,9 @@ class TestSamples(unittest.TestCase):
]
def error_str(error: CompileError):
line, col = utils.idx_to_pos(error.range.start + 1, blueprint)
line, col = utils.idx_to_pos(error.range.start, blueprint)
len = error.range.length
return ",".join([str(line + 1), str(col), str(len), error.message])
return ",".join([str(line + 1), str(col + 1), str(len), error.message])
actual = "\n".join([error_str(error) for error in errors])