Пример #1
0
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)
Пример #3
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)
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))
Пример #5
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(),
        ))
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)
Пример #7
0
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
        )
    )
Пример #8
0
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))
Пример #10
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
        )
    )
Пример #11
0
    def visit_OptionalRule(self, item):
        from yargy.api import or_, empty

        child = self.visit(item.rule)
        return or_(child, empty())
Пример #12
0
    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)))