mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add warning for sync-create
This commit is contained in:
parent
32d4769f65
commit
9873a2072b
8 changed files with 62 additions and 19 deletions
|
@ -24,7 +24,7 @@ import typing as T
|
|||
from collections import defaultdict
|
||||
from enum import Enum
|
||||
|
||||
from .errors import assert_true, CompilerBugError, CompileError, UnexpectedTokenError
|
||||
from .errors import assert_true, CompilerBugError, CompileError, CompileWarning, UnexpectedTokenError
|
||||
from .tokenizer import Token, TokenType
|
||||
|
||||
|
||||
|
@ -233,6 +233,10 @@ class ParseNode:
|
|||
""" Convenience method for err(). """
|
||||
return self.err("Expected " + expect)
|
||||
|
||||
def warn(self, message):
|
||||
""" Causes this ParseNode to emit a warning if it parses successfully. """
|
||||
return Warning(self, message)
|
||||
|
||||
|
||||
class Err(ParseNode):
|
||||
""" ParseNode that emits a compile error if it fails to parse. """
|
||||
|
@ -253,6 +257,23 @@ class Err(ParseNode):
|
|||
return True
|
||||
|
||||
|
||||
class Warning(ParseNode):
|
||||
""" ParseNode that emits a compile warning if it parses successfully. """
|
||||
|
||||
def __init__(self, child, message):
|
||||
self.child = to_parse_node(child)
|
||||
self.message = message
|
||||
|
||||
def _parse(self, ctx):
|
||||
ctx.skip()
|
||||
start_idx = ctx.index
|
||||
if self.child.parse(ctx).succeeded():
|
||||
start_token = ctx.tokens[start_idx]
|
||||
end_token = ctx.tokens[ctx.index]
|
||||
ctx.warnings.append(CompileWarning(self.message, start_token.start, end_token.end))
|
||||
return True
|
||||
|
||||
|
||||
class Fail(ParseNode):
|
||||
""" ParseNode that emits a compile error if it parses successfully. """
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue