Example #1
0
def to_ast(s):
    print s
    tp = parse(s)
    print tp
    astb = ASTBuilder()
    astb.sourcename = "test"
    return astb.dispatch(tp)
Example #2
0
def to_ast(s):
    print s
    tp = parse(s)
    print tp
    astb = ASTBuilder()
    astb.sourcename = "test"
    return astb.dispatch(tp)
Example #3
0
def parse_to_ast(code):
    #assert isinstance(code, unicode)
    from js.jsparser import parse
    from js.runistr import encode_unicode_utf8
    src = encode_unicode_utf8(code)
    parse_tree = parse(src)
    ast = parse_tree_to_ast(parse_tree)
    return ast
Example #4
0
 def Call(self, ctx, args=[], this=None):
     tam = len(args)
     if tam >= 1:
         fbody  = args[tam-1].ToString(ctx)
         argslist = []
         for i in range(tam-1):
             argslist.append(args[i].ToString(ctx))
         fargs = ','.join(argslist)
         functioncode = "function (%s) {%s}"%(fargs, fbody)
     else:
         functioncode = "function () {}"
     #remove program and sourcelements node
     funcnode = parse(functioncode).children[0].children[0]
     ast = ASTBUILDER.dispatch(funcnode)
     bytecode = JsCode()
     ast.emit(bytecode)
     func = bytecode.make_js_function()
     return func.run(ctx)
Example #5
0
def load_source(script_source, sourcename):
    temp_tree = parse(script_source)
    ASTBUILDER.sourcename = sourcename
    return ASTBUILDER.dispatch(temp_tree)