Commit 75e2027a authored by Igor Dejanovic's avatar Igor Dejanovic

Fixing semantic action results test

parent a6ad2785
...@@ -12,7 +12,7 @@ import pytest ...@@ -12,7 +12,7 @@ import pytest
# Grammar # Grammar
from arpeggio import ZeroOrMore, OneOrMore, ParserPython, Terminal, NonTerminal,\ from arpeggio import ZeroOrMore, OneOrMore, ParserPython, Terminal, NonTerminal,\
SemanticAction, SemanticActionResults SemanticActionResults, PTNodeVisitor, visit_parse_tree
from arpeggio.export import PTDOTExporter from arpeggio.export import PTDOTExporter
from arpeggio import RegExMatch as _ from arpeggio import RegExMatch as _
...@@ -27,23 +27,18 @@ def fourth(): return _(r'\d+') ...@@ -27,23 +27,18 @@ def fourth(): return _(r'\d+')
first_sar = None first_sar = None
third_sar = None third_sar = None
class FirstSA(SemanticAction): class TestVisitor(PTNodeVisitor):
def first_pass(self, parser, node, children): def visit_first(self, node, children):
global first_sar global first_sar
first_sar = children first_sar = children
def visit_third(self, node, children):
class ThirdSA(SemanticAction):
def first_pass(self, parser, node, children):
global third_sar global third_sar
third_sar = children third_sar = children
return 1 return 1
first.sem = FirstSA()
third.sem = ThirdSA()
def test_semantic_action_results(): def test_semantic_action_results():
global first_sar, third_sar global first_sar, third_sar
...@@ -55,7 +50,7 @@ def test_semantic_action_results(): ...@@ -55,7 +50,7 @@ def test_semantic_action_results():
PTDOTExporter().exportFile(result, 'test_semantic_action_results_pt.dot') PTDOTExporter().exportFile(result, 'test_semantic_action_results_pt.dot')
parser.getASG() visit_parse_tree(result, TestVisitor())
assert isinstance(first_sar, SemanticActionResults) assert isinstance(first_sar, SemanticActionResults)
assert len(first_sar.third) == 3 assert len(first_sar.third) == 3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment