Skip to content
Snippets Groups Projects
Commit a35298dc authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Fix MatchParser matching extra unnecessary constructors

parent 562e192d
No related branches found
No related tags found
No related merge requests found
......@@ -326,7 +326,7 @@ class MatchParser(JSParser):
"""A parser for the JS portion of an activity, that uses Python match statements
to navigate the abstract syntax tree (AST) produced by Esprima"""
activity: Activity
activity: Optional[Activity] = None
def __init__(self, graph: Graph, act_id: str) -> None:
self.graph = graph
......@@ -338,9 +338,15 @@ class MatchParser(JSParser):
# Try to match our template with one of the top-level statements
for statement in jstree.body:
self.match_function(statement.toDict())
if self.activity is not None:
return self.activity
else:
raise ParseError("No activity constructor found")
def match_constructor_call(self, new_expr: dict):
if self.activity is not None: # Ignore anything after the first match
return
match new_expr:
case {
"type": "NewExpression",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment