def test(self): tests = ( ('var s = "', False), ('bogon()', True), ('int syntax_error;', True), ('a /* b', False), ('re = /.*', False), ('{ // missing curly', False) ) for text, expected in tests: encountered = is_compilable_unit(text, JSVersion.default()) self.assertEquals(encountered, expected) # NOTE: This seems like a bug. self.assert_(is_compilable_unit("/* test", JSVersion.default()))
def parse(script, jsversion, error_callback, startpos=None): """ All node positions will be relative to startpos. This allows scripts to be embedded in a file (for example, HTML). """ def _wrapped_callback(line, col, msg): assert msg.startswith('JSMSG_') msg = msg[6:].lower() error_callback(line, col, msg) startpos = startpos or NodePos(0,0) jsversion = jsversion or JSVersion.default() assert isvalidversion(jsversion) return spidermonkey.parse(script, jsversion.version, jsversion.e4x, _Node, _wrapped_callback, startpos.line, startpos.col)
def is_compilable_unit(script, jsversion): jsversion = jsversion or JSVersion.default() assert isvalidversion(jsversion) return spidermonkey.is_compilable_unit(script, jsversion.version, jsversion.e4x)