Esempio n. 1
0
def parse(expression_string, **names):
    expression = expr_parser.parse(expression_string)
    expression = substitute(expression, **names)
    return expression
Esempio n. 2
0
 def finish():
     if name is None:
         return
     expression = substituteExpressions(parse(text), expressions)
     expression = substitute(expression, **symbols)
     expressions[name] = expression
Esempio n. 3
0
                  "don't know how to get argument names for '%r'" \
                  % arg
        # Construct the expression.
        subexprs = map(Symbol, symbol_names)
        expr = Call(Constant(arg), subexprs)

    # If it's numerical, wrap it in a constant.
    elif type(arg) in (int, float, long):
        expr = Constant(arg)

    # Don't know how to handle other things.
    else:
        raise TypeError, "argument must be an expression"

    # Substitute names.
    expr = substitute(expr, **names)
    # Set types.
    if types_from is not None:
        expr = setTypesFrom(expr, **types_from)
    if types is not None:
        expr = setTypes(expr, **types)
    # Compile it, if requested.
    if compile:
        expr = compiler.compile(expr)
    # All done.
    return expr


def parse(expression_string, **names):
    expression = expr_parser.parse(expression_string)
    expression = substitute(expression, **names)