def to_ast(s): print s tp = parse(s) print tp astb = ASTBuilder() astb.sourcename = "test" return astb.dispatch(tp)
def test_get_pos(self): from pypy.lang.js import operations from pypy.rlib.parsing.tree import Symbol astb = ASTBuilder() t = self.parse('6') assert isinstance(t, Symbol) pos = astb.get_pos(t) assert pos.lineno == 0 t = self.parse('[1,]') assert not isinstance(t, Symbol) pos = astb.get_pos(t) assert pos.start == 0
import math from pypy.lang.js.jsparser import parse, ParseError from pypy.lang.js.astbuilder import ASTBuilder from pypy.lang.js.operations import * from pypy.lang.js.jsobj import ThrowException from pypy.rlib.objectmodel import we_are_translated from pypy.rlib.streamio import open_file_as_stream ASTBUILDER = ASTBuilder() def writer(x): print x def load_source(script_source, sourcename): temp_tree = parse(script_source) ASTBUILDER.sourcename = sourcename return ASTBUILDER.dispatch(temp_tree) def load_file(filename): f = open_file_as_stream(filename) t = load_source(f.readall(), filename) f.close() return t class W_NativeObject(W_Object): def __init__(self, Class,
def to_ast(self, s): return ASTBuilder().dispatch(self.parse(s))