mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-11 16:52:14 -04:00
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:
parent
69e05bba34
commit
d3c31447c9
6 changed files with 18 additions and 11 deletions
|
@ -76,8 +76,8 @@ def did_you_mean(word: str, options: T.List[str]) -> T.Optional[str]:
|
|||
def idx_to_pos(idx: int, text: str) -> T.Tuple[int, int]:
|
||||
if idx == 0 or len(text) == 0:
|
||||
return (0, 0)
|
||||
line_num = text.count("\n", 0, idx) + 1
|
||||
col_num = idx - text.rfind("\n", 0, idx) - 1
|
||||
line_num = text.count("\n", 0, idx - 1) + 1
|
||||
col_num = idx - text.rfind("\n", 0, idx - 1) - 1
|
||||
return (line_num - 1, col_num)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue