Implement semantic error handling for duplicate screen declarations
This commit is contained in:
parent
16a3446d48
commit
38ee57547d
18
compiler.py
18
compiler.py
|
@ -1673,12 +1673,20 @@ def syntactical_analyzer(tokens: Sequence[Token]) -> File:
|
|||
# -- Semantics --
|
||||
|
||||
|
||||
# class SemanticsError(CompilerError):
|
||||
class SemanticsError(Exception):
|
||||
class SemanticError(CompilerError):
|
||||
|
||||
_compiler_error_type = "Semantics"
|
||||
|
||||
|
||||
class DuplicateScreen(SemanticError):
|
||||
|
||||
def __init__(self, file_info: FileInfo):
|
||||
super().__init__(
|
||||
"Duplicate 'screen' declaration.",
|
||||
file_info,
|
||||
)
|
||||
|
||||
|
||||
class ContextOperator(Enum):
|
||||
NoOp = "0"
|
||||
Identifier = "i"
|
||||
|
@ -1984,13 +1992,17 @@ def semantics_analyzer(file: File) -> Context:
|
|||
graphs: list[ContextGraph] = []
|
||||
for child in file.children:
|
||||
if isinstance(child, Screen):
|
||||
pass
|
||||
if screen is not None:
|
||||
raise DuplicateScreen(child.file_info)
|
||||
screen = child
|
||||
elif isinstance(child, Constant):
|
||||
pass
|
||||
elif isinstance(child, Animation):
|
||||
pass
|
||||
elif isinstance(child, Graph):
|
||||
pass
|
||||
if screen is None:
|
||||
screen = Screen(file.file_info)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue