mparser: Add partial AST to exceptions

Surprisingly enough we need to do this twice. In some cases
(failing-meson/72 triggers this) we can error out after parsing the
codeblock, but without getting the expected eof.

We need to catch both exceptions as either one can interrupt the built
codeblock object.

Co-authored-by: Xavier Claessens <xavier.claessens@collabora.com>
pull/11466/head
Eli Schwartz 2 years ago
parent 9423631b76
commit cc23996266
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 11
      mesonbuild/mparser.py

@ -41,6 +41,9 @@ def decode_match(match: T.Match[str]) -> str:
return codecs.decode(match.group(0).encode(), 'unicode_escape')
class ParseException(MesonException):
ast: T.Optional[CodeBlockNode] = None
def __init__(self, text: str, line: str, lineno: int, colno: int) -> None:
# Format as error message, followed by the line with the error, followed by a caret to show the error column.
super().__init__(mlog.code_line(text, line, colno))
@ -548,7 +551,11 @@ class Parser:
def parse(self) -> CodeBlockNode:
block = self.codeblock()
try:
self.expect('eof')
except ParseException as e:
e.ast = block
raise
return block
def statement(self) -> BaseNode:
@ -838,9 +845,13 @@ class Parser:
def codeblock(self) -> CodeBlockNode:
block = CodeBlockNode(self.current)
cond = True
try:
while cond:
curline = self.line()
if not isinstance(curline, EmptyNode):
block.lines.append(curline)
cond = self.accept('eol')
except ParseException as e:
e.ast = block
raise
return block

Loading…
Cancel
Save