Search in sources :

Example 6 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project pmd by pmd.

the class EcmascriptParser method parseEcmascript.

protected AstRoot parseEcmascript(final String sourceCode, final List<ParseProblem> parseProblems) throws ParseException {
    final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
    compilerEnvirons.setRecordingComments(parserOptions.isRecordingComments());
    compilerEnvirons.setRecordingLocalJsDocComments(parserOptions.isRecordingLocalJsDocComments());
    compilerEnvirons.setLanguageVersion(parserOptions.getRhinoLanguageVersion().getVersion());
    // Scope's don't appear to get set right without this
    compilerEnvirons.setIdeMode(true);
    compilerEnvirons.setWarnTrailingComma(true);
    // see bug #1150 "EmptyExpression" for valid statements!
    compilerEnvirons.setReservedKeywordAsIdentifier(true);
    // TODO We should do something with Rhino errors...
    final ErrorCollector errorCollector = new ErrorCollector();
    final Parser parser = new Parser(compilerEnvirons, errorCollector);
    // TODO Fix hardcode
    final String sourceURI = "unknown";
    final int beginLineno = 1;
    AstRoot astRoot = parser.parse(sourceCode, sourceURI, beginLineno);
    parseProblems.addAll(errorCollector.getErrors());
    return astRoot;
}
Also used : CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) ErrorCollector(org.mozilla.javascript.ast.ErrorCollector) Parser(org.mozilla.javascript.Parser) AstRoot(org.mozilla.javascript.ast.AstRoot)

Aggregations

CompilerEnvirons (org.mozilla.javascript.CompilerEnvirons)6 Parser (org.mozilla.javascript.Parser)6 ErrorReporter (org.mozilla.javascript.ErrorReporter)2 NodeTransformer (org.mozilla.javascript.NodeTransformer)2 ScriptNode (org.mozilla.javascript.ast.ScriptNode)2 TestErrorReporter (org.mozilla.javascript.testing.TestErrorReporter)2 ToolErrorReporter (org.mozilla.javascript.tools.ToolErrorReporter)2 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 AstRoot (org.mozilla.javascript.ast.AstRoot)1 ErrorCollector (org.mozilla.javascript.ast.ErrorCollector)1 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)1