Code with Finding: |
class ParserRunner {
/**
* Parses the JavaScript text given by a reader.
*
* @param sourceName The filename.
* @param sourceString Source code from the file.
* @param errorReporter An error.
* @param logger A logger.
* @return The AST of the given text.
* @throws IOException
*/
public static Node parse(String sourceName,
String sourceString,
Config config,
ErrorReporter errorReporter,
Logger logger) throws IOException {
Context cx = Context.enter();
cx.setErrorReporter(errorReporter);
cx.setLanguageVersion(Context.VERSION_1_5);
CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.initFromContext(cx);
compilerEnv.setRecordingComments(true);
compilerEnv.setRecordingLocalJsDocComments(true);
compilerEnv.setWarnTrailingComma(true);
if (config.isIdeMode) {
compilerEnv.setReservedKeywordAsIdentifier(true);
compilerEnv.setAllowMemberExprAsFunctionName(true);
}
Parser p = new Parser(compilerEnv, errorReporter);
AstRoot astRoot = null;
try {
astRoot = p.parse(sourceString, sourceName, 1);
} catch (EvaluatorException e) {
logger.info("Error parsing " + sourceName + ": " + e.getMessage());
} finally {
Context.exit();
}
Node root = null;
if (astRoot != null) {
root = IRFactory.transformTree(
astRoot, sourceString, config, errorReporter);
root.setIsSyntheticBlock(true);
}
return root;
}
}
|