Exemplo n.º 1
0
def _logical(op):
    return lexeme(pc.char('(').skip(
                  lexeme(string(op.call_name)).skip(
                  many_list(expr).bind(lambda exprs:
                  pc.char(')').skip(
                  inject(op(*exprs)))))))
Exemplo n.º 2
0
identifier = concat(extended_alph_char, many(choice(extended_alph_char, digit))).drop_whitespace() \
    .with_name('identifier')

primitive = pc.char('(').skip(
    identifier.bind(lambda i: cond(i in Primitive.__registry__.keys(),
    many_list(expr).bind(lambda args:
    pc.char(')').skip(
    inject(Primitive[i](*args)))))))\
    .with_name('primitive')


conditional = pc.char('(').skip(
    lexeme(string('if')).skip(
    expr.bind(lambda condition:
    expr.bind(lambda if_branch:
    expr.bind(lambda else_branch:
    pc.char(')').skip(
    inject(If(condition, if_branch, else_branch))))))))\
    .with_name('conditional')

def _logical(op):
    return lexeme(pc.char('(').skip(
                  lexeme(string(op.call_name)).skip(
                  many_list(expr).bind(lambda exprs:
                  pc.char(')').skip(
                  inject(op(*exprs)))))))

and_ = _logical(And).with_name('and')
or_ = _logical(Or).with_name('or')

logical = choice(and_, or_)