Refine search
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; }
private AstRoot parseRuntime(String name) throws IOException { CompilerEnvirons env = new CompilerEnvirons(); env.setRecoverFromErrors(true); env.setLanguageVersion(Context.VERSION_1_8); JSParser factory = new JSParser(env); ClassLoader loader = RuntimeRenderer.class.getClassLoader(); try (InputStream input = loader.getResourceAsStream("org/teavm/backend/javascript/" + name); Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) { return factory.parse(reader, null, 0); } }
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; } }
/** * Returns a {@code CompilerEnvirons} suitable for using Rhino * in an IDE environment. Most features are enabled by default. * The {@link ErrorReporter} is set to an {@link ErrorCollector}. */ public static CompilerEnvirons ideEnvirons() { CompilerEnvirons env = new CompilerEnvirons(); env.setRecoverFromErrors(true); env.setRecordingComments(true); env.setStrictMode(true); env.setWarnTrailingComma(true); env.setLanguageVersion(170); env.setReservedKeywordAsIdentifier(true); env.setIdeMode(true); env.setErrorReporter(new ErrorCollector()); return env; }
if (compilerEnv.isAllowMemberExprAsFunctionName()) { AstNode memberExprHead = name; name = null; if (compilerEnv.isAllowMemberExprAsFunctionName()) { FunctionNode fnNode = new FunctionNode(functionSourceStart, name); fnNode.setFunctionType(type); if (lpPos != -1) fnNode.setLp(lpPos - functionSourceStart); fnNode.setJsDocNode(getAndResetJsDoc()); fnNode.setLength(ts.tokenEnd - functionSourceStart); if (compilerEnv.isStrictMode() && !fnNode.getBody().hasConsistentReturnUsage()) { String msg = (name != null && name.length() > 0) if (compilerEnv.isIdeMode()) { fnNode.setParentScope(currentScope);
/** * Creates options for Rhino based off of the user's preferences. * * @param errorHandler The container for errors found while parsing. * @return The properties for the JS compiler to use. */ public static CompilerEnvirons createCompilerEnvironment(ErrorReporter errorHandler, JavaScriptLanguageSupport langSupport) { CompilerEnvirons env = new CompilerEnvirons(); env.setErrorReporter(errorHandler); env.setIdeMode(true); env.setRecordingComments(true); env.setRecordingLocalJsDocComments(true); env.setRecoverFromErrors(true); if(langSupport != null) { env.setXmlAvailable(langSupport.isXmlAvailable()); env.setStrictMode(langSupport.isStrictMode()); int version = langSupport.getLanguageVersion(); if (version > 0) { Logger.log("[JavaScriptParser]: JS language version set to: " + version); env.setLanguageVersion(version); } } return env; }
CompilerEnvirons compilerEnv = new CompilerEnvirons(); compilerEnv.initFromContext(this); if (compilationErrorReporter == null) { compilationErrorReporter = compilerEnv.getErrorReporter();
private CompilerEnvirons createEnvironment() { // Since this is only used in our own project, we hard-code these. A "real" plugin would // have them all configurable CompilerEnvirons env = new CompilerEnvirons(); env.setLanguageVersion(Context.VERSION_1_8); env.setGenerateDebugInfo(debugInfo); env.setOptimizationLevel(optimizationLevel); env.setGeneratingSource(generateSource); env.setRecordingComments(false); env.setRecoverFromErrors(false); env.setGenerateObserverCount(generateObserverCount); return env; }
CompilerEnvirons env = new CompilerEnvirons(); env.setRecoverFromErrors(true); env.setLanguageVersion(Context.VERSION_1_8); env.setIdeMode(true); JSParser parser = new JSParser(env, errorReporter); AstRoot rootNode; throw new RuntimeException("IO Error occurred", e); AstNode body = ((FunctionNode) rootNode.getFirstChild()).getBody();
import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Parser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] args) throws IOException { class Printer implements NodeVisitor { @Override public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowSharpComments(true); env.setRecordingComments(true); AstRoot node = new Parser(env).parse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } }
public Parser() { this(new CompilerEnvirons()); }
public Main() { reporter = new ToolErrorReporter(true); compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compiler = new ClassCompiler(compilerEnv); }
CompilerEnvirons compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compilerEnv.setReservedKeywordAsIdentifier(true); compilerEnv.setIdeMode(true); Parser P = new Parser(compilerEnv, compilerEnv.getErrorReporter());
CompilerEnvirons env = new CompilerEnvirons(); env.setIdeMode(true); env.setErrorReporter(new ErrorReporter() { env.setRecoverFromErrors(true); Parser parser = new Parser(env); StringReader r = new StringReader(text);
compilerEnv.setGenerateDebugInfo(false); // default to no symbols for (int i=0; i < args.length; i++) { String arg = args[i]; if (arg.equals("-version") && ++i < args.length) { int version = Integer.parseInt(args[i]); compilerEnv.setLanguageVersion(version); continue; compilerEnv.setOptimizationLevel(optLevel); continue; compilerEnv.setGeneratingSource(false); continue; compilerEnv.setGenerateDebugInfo(true); continue; compilerEnv.setGenerateObserverCount(true);
private JsDoc parseContent(String moduleContents, final Set<String> dependencies) CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingComments(true); env.setRecordingLocalJsDocComments(true); Parser parser = new Parser(env, new ErrorReporter()
if (result != Token.EOF) { if ((result == Token.LET || result == Token.YIELD) && parser.compilerEnv.getLanguageVersion() < Context.VERSION_1_7) return result; } else if (!parser.compilerEnv. isReservedKeywordAsIdentifier())
private static ArrayList parse(final Reader in, final ErrorReporter reporter) throws IOException, EvaluatorException { final CompilerEnvirons env = new CompilerEnvirons(); env.setLanguageVersion(Context.VERSION_1_7); final Parser parser = new Parser(env, reporter); final AstRoot ast = parser.parse(in, null, 1);
if (!compilerEnv.isXmlAvailable()) { int maybeName = nextToken(); if (maybeName != Token.NAME && !(compilerEnv.isReservedKeywordAsIdentifier() && TokenStream.isKeyword(ts.getString()))) { reportError("msg.no.name.after.dot"); if (compilerEnv.isReservedKeywordAsIdentifier()) {
decompiler.addName(name); if (!matchToken(Token.LP)) { if (compilerEnv.isAllowMemberExprAsFunctionName()) { } else { name = ""; if (compilerEnv.isAllowMemberExprAsFunctionName()) { if (compilerEnv.isStrictMode() && !body.hasConsistentReturnUsage())