Exemple #1
0
def eval_file(file_name):
    f = codecs.open(file_name, encoding='utf-8')
    file_contents = f.read()
    program = Parser().parse(file_contents)
    context = ExecutionContext(dict((name, UNDEFINED) for name in program.get_declared_vars()))
    result = program.eval(context)
    return result.value, context
Exemple #2
0
def eval_string(s, global_objects=None):
    if global_objects is None:
        global_objects = create_default_global_objects()
        
    # Parse file and create the execution context object
    program = Parser().parse(s)
    declared_vars = dict((name, UNDEFINED) for name in program.get_declared_vars())
    declared_vars.update(global_objects)
    context = ExecutionContext(declared_vars)

    # Run code
    result = program.eval(context)
    return result.value, context
Exemple #3
0
def eval_string(s, global_objects=None):
    if global_objects is None:
        global_objects = create_default_global_objects()

    # Parse file and create the execution context object
    program = Parser().parse(s)
    declared_vars = dict(
    )  #(name, UNDEFINED) for name in program.get_declared_vars())
    declared_vars.update(global_objects)
    context = ExecutionContext(declared_vars)

    # Run code
    result = program.eval(context)
    return result.value, context
Exemple #4
0
 def setUpClass(cls):
     cls.parser = Parser(start='program')
Exemple #5
0
 def setUpClass(cls):
     cls.parser = Parser(start='statement')
Exemple #6
0
 def setUpClass(cls):
     cls.parser = Parser(start='expression')