mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add tests, remove unused code, fix bugs
- Added tests for more error messages - Test the "go to reference" feature at every character index of every test case - Delete unused code and imports - Fix some bugs I found along the way
This commit is contained in:
parent
5b0f662478
commit
9b9fab832b
47 changed files with 140 additions and 190 deletions
|
@ -95,19 +95,11 @@ class ParseGroup:
|
|||
|
||||
try:
|
||||
return self.ast_type(self, children, self.keys, incomplete=self.incomplete)
|
||||
except TypeError as e:
|
||||
except TypeError: # pragma: no cover
|
||||
raise CompilerBugError(
|
||||
f"Failed to construct ast.{self.ast_type.__name__} from ParseGroup. See the previous stacktrace."
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
result = str(self.ast_type.__name__)
|
||||
result += "".join([f"\n{key}: {val}" for key, val in self.keys.items()]) + "\n"
|
||||
result += "\n".join(
|
||||
[str(child) for children in self.children.values() for child in children]
|
||||
)
|
||||
return result.replace("\n", "\n ")
|
||||
|
||||
|
||||
class ParseContext:
|
||||
"""Contains the state of the parser."""
|
||||
|
@ -265,10 +257,6 @@ class ParseNode:
|
|||
"""Convenience method for err()."""
|
||||
return self.err("Expected " + expect)
|
||||
|
||||
def warn(self, message) -> "Warning":
|
||||
"""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."""
|
||||
|
@ -290,27 +278,6 @@ class Err(ParseNode):
|
|||
return True
|
||||
|
||||
|
||||
class Warning(ParseNode):
|
||||
"""ParseNode that emits a compile warning if it parses successfully."""
|
||||
|
||||
def __init__(self, child, message: str):
|
||||
self.child = to_parse_node(child)
|
||||
self.message = message
|
||||
|
||||
def _parse(self, ctx: ParseContext):
|
||||
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
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class Fail(ParseNode):
|
||||
"""ParseNode that emits a compile error if it parses successfully."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue