Better lexer error handling
This commit is contained in:
parent
b47eb7ce10
commit
03c24a2074
@ -1,5 +1,6 @@
|
||||
import typing
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from .lexer import LexToken
|
||||
|
||||
|
||||
|
@ -7,6 +7,12 @@ import sys
|
||||
from ._ply import lex
|
||||
from ._ply.lex import TOKEN
|
||||
|
||||
from .errors import CxxParseError
|
||||
|
||||
|
||||
class LexError(CxxParseError):
|
||||
pass
|
||||
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from typing import Protocol
|
||||
@ -249,7 +255,11 @@ class Lexer:
|
||||
return t
|
||||
|
||||
def t_error(self, t: LexToken) -> None:
|
||||
print("Lex error: ", t)
|
||||
self._error(f"Illegal character {t.value!r}", t)
|
||||
|
||||
def _error(self, msg: str, tok: LexToken):
|
||||
tok.location = self.current_location()
|
||||
raise LexError(msg, tok)
|
||||
|
||||
_lexer = None
|
||||
lex: lex.Lexer
|
||||
|
Loading…
x
Reference in New Issue
Block a user