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 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 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())