mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Simplify error & warning handling
This commit is contained in:
parent
122b049ce9
commit
b6ee649458
8 changed files with 38 additions and 21 deletions
|
@ -24,14 +24,21 @@ from .tokenizer import TokenType
|
|||
from .language import OBJECT_CONTENT_HOOKS, VALUE_HOOKS, Template, UI
|
||||
|
||||
|
||||
def parse(tokens) -> T.Tuple[UI, T.Optional[MultipleErrors], T.List[PrintableError]]:
|
||||
def parse(
|
||||
tokens: T.List[Token],
|
||||
) -> T.Tuple[T.Optional[UI], T.Optional[MultipleErrors], T.List[PrintableError]]:
|
||||
"""Parses a list of tokens into an abstract syntax tree."""
|
||||
|
||||
ctx = ParseContext(tokens)
|
||||
AnyOf(UI).parse(ctx)
|
||||
try:
|
||||
ctx = ParseContext(tokens)
|
||||
AnyOf(UI).parse(ctx)
|
||||
ast_node = ctx.last_group.to_ast() if ctx.last_group else None
|
||||
|
||||
ast_node = ctx.last_group.to_ast() if ctx.last_group else None
|
||||
errors = MultipleErrors(ctx.errors) if len(ctx.errors) else None
|
||||
warnings = ctx.warnings
|
||||
errors = [*ctx.errors, *ast_node.errors]
|
||||
warnings = [*ctx.warnings, *ast_node.warnings]
|
||||
|
||||
return (ast_node, errors, warnings)
|
||||
return (ast_node, MultipleErrors(errors) if len(errors) else None, warnings)
|
||||
except MultipleErrors as e:
|
||||
return (None, e, [])
|
||||
except CompileError as e:
|
||||
return (None, MultipleErrors([e]), [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue