Package org.mozilla.javascript

Examples of org.mozilla.javascript.Parser


    private static void parseAndPrintSource(String source) throws IOException {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
//        compilerEnv.setStrictMode(false);
        Parser parser = new Parser(compilerEnv);
        AstRoot astRoot = parser.parse(new StringReader(source), null, 1);
        System.out.println(astRoot.toSource());
    }
View Full Code Here


        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
        compilerEnv.setStrictMode(false);

        Bug784651 visitor = new Bug784651();
        addIncrement(new Parser(compilerEnv), visitor, "while (x)\n{\n  ;\n}");
        System.err.println("*************************");
        addIncrement(new Parser(compilerEnv), visitor, "while (x)\n  ;");
    }
View Full Code Here

    }
       
    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();

        Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());
       
        ScriptOrFnNode tree = parser.parse(source, null, lineno);
        String encodedSource = parser.getEncodedSource();
        if (encodedSource.length() == 0) { return ""; }
       
        Interpreter compiler = new Interpreter();
        compiler.compile(compilerEnv, tree, encodedSource, false);
        UintMap properties = new UintMap(1);
View Full Code Here

      Reader reader = new FileReader(jsFile);

      CompilerEnvirons compilerEnv = new CompilerEnvirons();
      ErrorReporter errorReporter = compilerEnv.getErrorReporter();

      Parser parser = new Parser(compilerEnv, errorReporter);

      String sourceURI;

      try {
        sourceURI = jsFile.getCanonicalPath();
      } catch (IOException e) {
        sourceURI = jsFile.toString();
      }

      nodeTree = parser.parse(reader, sourceURI, 1);
    }
    return nodeTree;
  }
View Full Code Here

    }
       
    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();

        Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());
       
        ScriptOrFnNode tree = parser.parse(source, null, lineno);
        String encodedSource = parser.getEncodedSource();
        if (encodedSource.length() == 0) { return ""; }
       
        Interpreter compiler = new Interpreter();
        compiler.compile(compilerEnv, tree, encodedSource, false);
        UintMap properties = new UintMap(1);
View Full Code Here

        compilerEnv.setGeneratingSource(false);
      }
      if (compilationErrorReporter == null) {
        compilationErrorReporter = compilerEnv.getErrorReporter();
      }
      Parser p = new Parser(compilerEnv, compilationErrorReporter);
      AstRoot ast = p.parse(in, file.toString(), 1);
      IRFactory irf = new IRFactory(compilerEnv, compilationErrorReporter);
      ScriptNode tree = irf.transformTree(ast);
      Object[] nameBytesPair = (Object[]) (Object[]) compiler.compile(
          compilerEnv, tree, tree.getEncodedSource(), false);
      String className = (String) nameBytesPair[0];
View Full Code Here

            CompilerEnvirons compilerEnv = new CompilerEnvirons();
            compilerEnv.initFromContext(cx);
            ErrorReporter compilationErrorReporter = compilerEnv
                    .getErrorReporter();
            Parser p = new Parser(compilerEnv, compilationErrorReporter);
            AstRoot ast = p.parse(source.toString(), "<eval>", 1);
            IRFactory irf = new IRFactory(compilerEnv);
            ScriptNode tree = irf.transformTree(ast);

            Codegen codegen = new Codegen();
            codegen.setMainMethodClass(mainMethodClassName);
View Full Code Here

        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(jsdoc);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = null;
        try {
          script = p.parse(string, null, 0);
        } catch (EvaluatorException e) {
          if (errors == null) {
            // EvaluationExceptions should not occur when we aren't expecting
            // errors.
            throw e;
View Full Code Here

        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(true);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = p.parse(new StringReader(string), null, 0);

        assertTrue(testErrorReporter.hasEncounteredAllErrors());
        assertTrue(testErrorReporter.hasEncounteredAllWarnings());

        return script;
View Full Code Here

    private AstRoot parse(CharSequence cs) {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.initFromContext(cx);
        ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
        Parser p = new Parser(compilerEnv, compilationErrorReporter);
        return p.parse(cs.toString(), "<eval>", 1);
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.