Commit 43dd61e4 authored by Igor Dejanovic's avatar Igor Dejanovic

Reference resolving unification

parent dd71eb5e
...@@ -964,6 +964,14 @@ class Parser(object): ...@@ -964,6 +964,14 @@ class Parser(object):
raise self.nm raise self.nm
class CrossRef(object):
'''
Used for rule reference resolving.
'''
def __init__(self, rule_name):
self.rule_name = rule_name
class ParserPython(Parser): class ParserPython(Parser):
def __init__(self, language_def, comment_def=None, *args, **kwargs): def __init__(self, language_def, comment_def=None, *args, **kwargs):
super(ParserPython, self).__init__(*args, **kwargs) super(ParserPython, self).__init__(*args, **kwargs)
...@@ -994,10 +1002,6 @@ class ParserPython(Parser): ...@@ -994,10 +1002,6 @@ class ParserPython(Parser):
__for_resolving = [] # Expressions that needs crossref resolvnih __for_resolving = [] # Expressions that needs crossref resolvnih
self.__cross_refs = 0 self.__cross_refs = 0
class CrossRef(object):
def __init__(self, rule_name):
self.rule_name = rule_name
def inner_from_python(expression): def inner_from_python(expression):
retval = None retval = None
if callable(expression): # Is this expression a parser rule? if callable(expression): # Is this expression a parser rule?
......
...@@ -47,15 +47,6 @@ def expression(): return [regex,(rule_identifier, Not(LEFT_ARROW)), ...@@ -47,15 +47,6 @@ def expression(): return [regex,(rule_identifier, Not(LEFT_ARROW)),
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# PEG Semantic Actions # PEG Semantic Actions
class RuleReference(object):
'''
Used for rule reference resolving in the second
pass of the semantic analysis.
'''
def __init__(self, rule_name):
self.rule_name = rule_name
class PEGSemanticAction(SemanticAction): class PEGSemanticAction(SemanticAction):
def _resolve(self, parser, rule_name): def _resolve(self, parser, rule_name):
if rule_name in parser.peg_rules: if rule_name in parser.peg_rules:
...@@ -67,11 +58,11 @@ class PEGSemanticAction(SemanticAction): ...@@ -67,11 +58,11 @@ class PEGSemanticAction(SemanticAction):
.format(rule_name)) .format(rule_name))
def second_pass(self, parser, node): def second_pass(self, parser, node):
if isinstance(node, RuleReference): if isinstance(node, CrossRef):
return self._resolve(parser, node.rule_name) return self._resolve(parser, node.rule_name)
elif isinstance(node, ParsingExpression): elif isinstance(node, ParsingExpression):
for i, n in node.nodes.items(): for i, n in enumerate(node.nodes):
if isinstance(n, RuleReference): if isinstance(n, CrossRef):
node[i] = self._resolve(parser, n.rule_name) node[i] = self._resolve(parser, n.rule_name)
return node return node
else: else:
......
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