def bound(item, count): from yargy.api import rule, or_ if count == 1: return item else: return or_(rule(item, bound(item, count - 1)), item)
def optional(item, reverse=False): from yargy.api import or_, empty a = empty() b = item if reverse: a, b = b, a return or_(a, b)
def repeatable(item, reverse=False): from yargy.api import forward, or_, rule temp = forward() a = rule(item, temp) b = item if reverse: a, b = b, a return temp.define(or_(a, b))
def visit_RepeatableOptionalRule(self, item): from yargy.api import forward, or_, rule, empty child = self.visit(item.rule) temp = forward() return temp.define(or_( rule(child, temp), child, empty(), ))
def max_bound(item, count, reverse=False): from yargy.api import rule, or_ if count == 1: return item else: a = rule(item, max_bound(item, count - 1, reverse)) b = item if reverse: a, b = b, a return or_(a, b)
def repeatable(item, reverse=False): from yargy.api import forward, or_, rule temp = forward() a = rule(item, temp) b = item if reverse: a, b = b, a return temp.define( or_( a, b ) )
def max_bound(item, count, reverse=False): from yargy.api import rule, or_ if count == 1: return item else: a = rule( item, max_bound(item, count - 1, reverse) ) b = item if reverse: a, b = b, a return or_(a, b)
def repeatable_optional(item, reverse_repeatable=False, reverse_optional=False): from yargy.api import forward, or_, rule, empty temp = forward() a = empty() b = rule(item, temp) c = item if reverse_repeatable: b, c = c, b if reverse_optional: a, b, c = b, c, a return temp.define(or_(a, b, c))
def repeatable_optional(item, reverse_repeatable=False, reverse_optional=False): from yargy.api import forward, or_, rule, empty temp = forward() a = empty() b = rule(item, temp) c = item if reverse_repeatable: b, c = c, b if reverse_optional: a, b, c = b, c, a return temp.define( or_( a, b, c ) )
def visit_OptionalRule(self, item): from yargy.api import or_, empty child = self.visit(item.rule) return or_(child, empty())
def visit_RepeatableRule(self, item): from yargy.api import forward, or_, rule child = self.visit(item.rule) temp = forward() return temp.define(or_(child, rule(child, temp)))