org.mozilla.javascript.Parser.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 JavaScript  
字(7.7k)|赞(0)|评价(0)|浏览(375)

本文整理了Java中org.mozilla.javascript.Parser.<init>()方法的一些代码示例,展示了Parser.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.<init>()方法的具体详情如下:
包路径:org.mozilla.javascript.Parser
类名称:Parser
方法名:<init>

Parser.<init>介绍

暂无

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

  1. public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName,
  2. int lineno, Object securityDomain ) {
  3. // Interpreter compiler = new Interpreter();
  4. CompilerEnvirons evn = new CompilerEnvirons();
  5. // evn.setLanguageVersion(Context.VERSION_1_5);
  6. evn.setOptimizationLevel( -1 );
  7. evn.setGeneratingSource( true );
  8. evn.setGenerateDebugInfo( true );
  9. ErrorReporter errorReporter = new ToolErrorReporter( false );
  10. Parser p = new Parser( evn, errorReporter );
  11. ScriptNode tree = p.parse( source, "", 0 ); // IOException
  12. new NodeTransformer().transform( tree );
  13. // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
  14. return tree;
  15. }
  16. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName,
  2. int lineno, Object securityDomain ) {
  3. // Interpreter compiler = new Interpreter();
  4. CompilerEnvirons evn = new CompilerEnvirons();
  5. // evn.setLanguageVersion(Context.VERSION_1_5);
  6. evn.setOptimizationLevel( -1 );
  7. evn.setGeneratingSource( true );
  8. evn.setGenerateDebugInfo( true );
  9. ErrorReporter errorReporter = new ToolErrorReporter( false );
  10. Parser p = new Parser( evn, errorReporter );
  11. ScriptNode tree = p.parse( source, "", 0 ); // IOException
  12. new NodeTransformer().transform( tree );
  13. // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
  14. return tree;
  15. }
  16. }

代码示例来源:origin: pmd/pmd

  1. protected AstRoot parseEcmascript(final String sourceCode, final List<ParseProblem> parseProblems)
  2. throws ParseException {
  3. final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
  4. compilerEnvirons.setRecordingComments(parserOptions.isRecordingComments());
  5. compilerEnvirons.setRecordingLocalJsDocComments(parserOptions.isRecordingLocalJsDocComments());
  6. compilerEnvirons.setLanguageVersion(parserOptions.getRhinoLanguageVersion().getVersion());
  7. // Scope's don't appear to get set right without this
  8. compilerEnvirons.setIdeMode(true);
  9. compilerEnvirons.setWarnTrailingComma(true);
  10. // see bug #1150 "EmptyExpression" for valid statements!
  11. compilerEnvirons.setReservedKeywordAsIdentifier(true);
  12. // TODO We should do something with Rhino errors...
  13. final ErrorCollector errorCollector = new ErrorCollector();
  14. final Parser parser = new Parser(compilerEnvirons, errorCollector);
  15. // TODO Fix hardcode
  16. final String sourceURI = "unknown";
  17. final int beginLineno = 1;
  18. AstRoot astRoot = parser.parse(sourceCode, sourceURI, beginLineno);
  19. parseProblems.addAll(errorCollector.getErrors());
  20. return astRoot;
  21. }

代码示例来源:origin: org.zkoss.zats/zats-mimic

  1. Parser parser = new Parser();
  2. AstRoot root = parser.parse(src.toString(), null, 0);

代码示例来源:origin: sonatype/nexus-public

  1. /**
  2. * Scan the given file for class definitions and accumulate dependencies.
  3. */
  4. private void scan(final File source) throws IOException {
  5. log.debug("Scanning: " + source);
  6. ErrorReporter errorReporter = new LogErrorReporter(log);
  7. CompilerEnvirons env = new CompilerEnvirons();
  8. env.setErrorReporter(errorReporter);
  9. Parser parser = new Parser(env, errorReporter);
  10. Reader reader = new BufferedReader(new FileReader(source));
  11. try {
  12. AstRoot root = parser.parse(reader, source.getAbsolutePath(), 0);
  13. DependencyAccumulator visitor = new DependencyAccumulator(source);
  14. root.visit(visitor);
  15. // complain if no def was found in this source
  16. if (visitor.current == null) {
  17. log.warn("No class definition was found while processing: " + source);
  18. }
  19. }
  20. finally {
  21. reader.close();
  22. }
  23. }

代码示例来源:origin: com.yahoo/yuicompressor

  1. Parser parser = new Parser(env, reporter);
  2. parser.parse(in, null, 1);
  3. String source = parser.getEncodedSource();

代码示例来源:origin: com.namics.oss.spring.support.terrific/spring-terrific-support

  1. final Parser parser = new Parser(env, reporter);
  2. final AstRoot ast = parser.parse(in, null, 1);
  3. final IRFactory irf = new IRFactory(env, reporter);

代码示例来源:origin: com.fifesoft/languagesupport

  1. public void parseScript(String scriptText, TypeDeclarationOptions options)
  2. {
  3. if(scriptText != null && scriptText.length() > 0)
  4. {
  5. CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
  6. Parser parser = new Parser(env);
  7. StringReader r = new StringReader(scriptText);
  8. try {
  9. AstRoot root = parser.parse(r, null, 0);
  10. CodeBlock block = provider.iterateAstRoot(root, preProcessingCompletions, "", Integer.MAX_VALUE, options);
  11. provider.recursivelyAddLocalVars(preProcessingCompletions, block, 0, null, false, true);
  12. }
  13. catch(IOException io) {
  14. //ignore this
  15. }
  16. }
  17. }

代码示例来源:origin: org.dojotoolkit/dojo-shrinksafe

  1. public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
  2. CompilerEnvirons compilerEnv = new CompilerEnvirons();
  3. Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());

代码示例来源:origin: org.zkoss.zats/zats-mimic

  1. Parser parser = new Parser();
  2. AstRoot root = parser.parse(code, null, 0);

代码示例来源:origin: rhino/js

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: GumTreeDiff/gumtree

  1. @Override
  2. public TreeContext generate(Reader r) throws IOException {
  3. CompilerEnvirons env = new CompilerEnvirons();
  4. env.setRecordingLocalJsDocComments(true);
  5. env.setAllowSharpComments(true);
  6. env.setRecordingComments(true);
  7. Parser p = new Parser(env);
  8. AstRoot root = p.parse(r, null, 1);
  9. RhinoTreeVisitor visitor = new RhinoTreeVisitor(root);
  10. root.visitAll(visitor);
  11. return visitor.getTree(root);
  12. }
  13. }

代码示例来源:origin: ro.isdc.wro4j/rhino

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: com.sun.phobos/phobos-rhino

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: com.fifesoft/languagesupport

  1. /**
  2. * Compiles Text and resolves the type.
  3. * e.g
  4. * "Hello World".length; //resolve as a Number
  5. *
  6. * @param text to compile and resolve
  7. */
  8. @Override
  9. public JavaScriptType compileText(String text) throws IOException {
  10. CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
  11. String parseText = JavaScriptHelper.removeLastDotFromText(text);
  12. int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(parseText);
  13. env.setRecoverFromErrors(true);
  14. Parser parser = new Parser(env);
  15. StringReader r = new StringReader(parseText);
  16. AstRoot root = parser.parse(r, null, 0);
  17. CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
  18. root.visitAll(visitor);
  19. return lastJavaScriptType;
  20. }

代码示例来源:origin: geogebra/geogebra

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: io.apigee/rhino

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: com.github.tntim96/rhino

  1. Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
  2. try {
  3. p.parse(source, null, 1);

代码示例来源:origin: com.fifesoft/languagesupport

  1. Parser parser = new Parser(env);
  2. StringReader r = new StringReader(text);
  3. ParseText pt = new ParseText();

代码示例来源:origin: com.fifesoft/languagesupport

  1. /**
  2. * Resolve node type to TypeDeclaration. Called instead of #compileText(String text) when document is already parsed
  3. * @param text The node to resolve
  4. * @return TypeDeclaration for node or null if not found.
  5. */
  6. @Override
  7. public TypeDeclaration resolveParamNode(String text) throws IOException {
  8. if(text != null) {
  9. CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
  10. int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(text);
  11. env.setRecoverFromErrors(true);
  12. Parser parser = new Parser(env);
  13. StringReader r = new StringReader(text);
  14. AstRoot root = parser.parse(r, null, 0);
  15. CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
  16. root.visitAll(visitor);
  17. }
  18. return lastJavaScriptType != null ? lastJavaScriptType.getType()
  19. : provider.getTypesFactory().getDefaultTypeDeclaration();
  20. }

相关文章

Parser类方法