use of org.python.pydev.parser.jython.ast.Module in project Pydev by fabioz.
the class PyParser method createCythonAst.
public static ParseOutput createCythonAst(ParserInfo info) {
ParseOutput parseOutput = null;
if (USE_NEW_CYTHON_PARSER) {
PyParserCython parserCython = new PyParserCython(info);
try {
parseOutput = parserCython.parse();
parseOutput.isCython = true;
} catch (Exception e) {
// If cython is not available, an error is expected.
Log.log(e);
}
}
if (parseOutput == null || parseOutput.ast == null) {
// If we couldn't parse with cython, try to give something even if not really complete.
List<stmtType> classesAndFunctions = FastParser.parseCython(info.document);
Module ast = new Module(classesAndFunctions.toArray(new stmtType[classesAndFunctions.size()]));
parseOutput = new ParseOutput(ast, parseOutput != null ? parseOutput.error : null, ((IDocumentExtension4) info.document).getModificationStamp());
parseOutput.isCython = true;
}
return parseOutput;
}
use of org.python.pydev.parser.jython.ast.Module in project Pydev by fabioz.
the class FastDefinitionsParser method parse.
public static SimpleNode parse(char[] cs, String moduleName, int len, File f) {
FastDefinitionsParser parser = new FastDefinitionsParser(cs, len, moduleName, f);
try {
parser.extractBody();
} catch (SyntaxErrorException e) {
throw new RuntimeException(e);
} catch (StackOverflowError e) {
RuntimeException runtimeException = new RuntimeException(e);
Log.log("Error parsing: " + moduleName + " - " + f + "\nContents:\n" + new String(cs, 0, len > 1000 ? 1000 : len), // report at most 1000 chars...
runtimeException);
throw runtimeException;
}
List<stmtType> body = parser.body;
Module ret = new Module(body.toArray(new stmtType[body.size()]));
ret.beginLine = 1;
ret.beginColumn = 1;
if (parseCallbacks.size() > 0) {
Tuple<String, SimpleNode> arg = new Tuple<String, SimpleNode>(moduleName, ret);
for (ICallback<Object, Tuple<String, SimpleNode>> c : parseCallbacks) {
c.call(arg);
}
}
return ret;
}
use of org.python.pydev.parser.jython.ast.Module in project Pydev by fabioz.
the class PyParser25Test method testSuiteLineNumber.
public void testSuiteLineNumber() throws Exception {
setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
String str = "" + "class Process:\n" + "\n" + " def Foo(self):\n" + " if a == 1:\n" + " pass\n" + " elif a == 1:\n" + " pass\n" + "\n" + "";
SimpleNode ast = parseLegalDocStr(str);
stmtType[] body = ((Module) ast).body;
assertEquals(1, body.length);
ClassDef classFound = (ClassDef) body[0];
body = classFound.body;
assertEquals(1, body.length);
FunctionDef func = (FunctionDef) body[0];
If ifFound = (If) func.body[0];
assertEquals(6, ifFound.orelse.beginLine);
}
use of org.python.pydev.parser.jython.ast.Module in project Pydev by fabioz.
the class PyParser25Test method testNewWithStmt2.
public void testNewWithStmt2() {
setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
String str = "" + "from __future__ import with_statement\n" + "with foo as x:\n" + " print 'bla'\n" + "";
// we'll actually treat this as a try..finally with a body with try..except..else
Module mod = (Module) parseLegalDocStr(str);
assertEquals(2, mod.body.length);
assertTrue(mod.body[1] instanceof With);
With w = (With) mod.body[1];
assertTrue(((WithItem) w.with_item[0]).optional_vars != null);
}
use of org.python.pydev.parser.jython.ast.Module in project Pydev by fabioz.
the class PyParser25Test method testNewRelativeImport3.
public void testNewRelativeImport3() {
setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
String str = "from ... import foo\n";
Module mod = (Module) parseLegalDocStr(str);
ImportFrom f = (ImportFrom) mod.body[0];
assertEquals(3, f.level);
assertEquals("", ((NameTok) f.module).id);
}
Aggregations