Commit 79b8e8d9 authored by Igor Dejanovic's avatar Igor Dejanovic

Support for adding nodes to predicates and repetitions.

parent 6d7fe26e
...@@ -211,12 +211,17 @@ class Repetition(ParsingExpression): ...@@ -211,12 +211,17 @@ class Repetition(ParsingExpression):
''' '''
Base class for all repetition-like parser expressions (?,*,+) Base class for all repetition-like parser expressions (?,*,+)
''' '''
def __init__(self, *elements): def __init__(self, *elements, **kwargs):
super(Repetition, self).__init__(None) super(Repetition, self).__init__(None)
if len(elements)==1: if len(elements)==1:
elements = elements[0] elements = elements[0]
self.elements = elements self.elements = elements
nodes = kwargs.get('nodes', [])
if not hasattr(nodes, '__iter__'):
nodes = [nodes]
self.nodes = nodes
class Optional(Repetition): class Optional(Repetition):
''' '''
...@@ -276,10 +281,16 @@ class SyntaxPredicate(ParsingExpression): ...@@ -276,10 +281,16 @@ class SyntaxPredicate(ParsingExpression):
Predicates are parser expressions that will do the match but will not consume Predicates are parser expressions that will do the match but will not consume
any input. any input.
''' '''
def __init__(self, *elements): def __init__(self, *elements, **kwargs):
if len(elements)==1: if len(elements)==1:
elements = elements[0] elements = elements[0]
self.elements = elements self.elements = elements
nodes = kwargs.get('nodes', [])
if not hasattr(nodes, '__iter__'):
nodes = [nodes]
self.nodes = nodes
super(SyntaxPredicate, self).__init__(None) super(SyntaxPredicate, self).__init__(None)
class And(SyntaxPredicate): class And(SyntaxPredicate):
......
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