コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
    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(),
        ))
コード例 #4
0
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))
コード例 #5
0
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
        )
    )
コード例 #6
0
    def visit_OptionalRule(self, item):
        from yargy.api import or_, empty

        child = self.visit(item.rule)
        return or_(child, empty())