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 --
|
# -- Semantics --
|
||||||
|
|
||||||
|
|
||||||
# class SemanticsError(CompilerError):
|
class SemanticError(CompilerError):
|
||||||
class SemanticsError(Exception):
|
|
||||||
|
|
||||||
_compiler_error_type = "Semantics"
|
_compiler_error_type = "Semantics"
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateScreen(SemanticError):
|
||||||
|
|
||||||
|
def __init__(self, file_info: FileInfo):
|
||||||
|
super().__init__(
|
||||||
|
"Duplicate 'screen' declaration.",
|
||||||
|
file_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ContextOperator(Enum):
|
class ContextOperator(Enum):
|
||||||
NoOp = "0"
|
NoOp = "0"
|
||||||
Identifier = "i"
|
Identifier = "i"
|
||||||
|
@ -1984,13 +1992,17 @@ def semantics_analyzer(file: File) -> Context:
|
||||||
graphs: list[ContextGraph] = []
|
graphs: list[ContextGraph] = []
|
||||||
for child in file.children:
|
for child in file.children:
|
||||||
if isinstance(child, Screen):
|
if isinstance(child, Screen):
|
||||||
pass
|
if screen is not None:
|
||||||
|
raise DuplicateScreen(child.file_info)
|
||||||
|
screen = child
|
||||||
elif isinstance(child, Constant):
|
elif isinstance(child, Constant):
|
||||||
pass
|
pass
|
||||||
elif isinstance(child, Animation):
|
elif isinstance(child, Animation):
|
||||||
pass
|
pass
|
||||||
elif isinstance(child, Graph):
|
elif isinstance(child, Graph):
|
||||||
pass
|
pass
|
||||||
|
if screen is None:
|
||||||
|
screen = Screen(file.file_info)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue