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

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

本文整理了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

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;
 }
}

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

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;
 }
}

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

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;
}

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

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

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

/**
 * Scan the given file for class definitions and accumulate dependencies.
 */
private void scan(final File source) throws IOException {
 log.debug("Scanning: " + source);
 ErrorReporter errorReporter = new LogErrorReporter(log);
 CompilerEnvirons env = new CompilerEnvirons();
 env.setErrorReporter(errorReporter);
 Parser parser = new Parser(env, errorReporter);
 Reader reader = new BufferedReader(new FileReader(source));
 try {
  AstRoot root = parser.parse(reader, source.getAbsolutePath(), 0);
  DependencyAccumulator visitor = new DependencyAccumulator(source);
  root.visit(visitor);
  // complain if no def was found in this source
  if (visitor.current == null) {
   log.warn("No class definition was found while processing: " + source);
  }
 }
 finally {
  reader.close();
 }
}

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

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

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

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

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

public void parseScript(String scriptText, TypeDeclarationOptions options)
{
  if(scriptText != null && scriptText.length() > 0)
  {
    CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
    Parser parser = new Parser(env);
    StringReader r = new StringReader(scriptText);
    try {
      AstRoot root = parser.parse(r, null, 0);
      CodeBlock block = provider.iterateAstRoot(root, preProcessingCompletions, "", Integer.MAX_VALUE, options);
      provider.recursivelyAddLocalVars(preProcessingCompletions, block, 0, null, false, true);
    }
    catch(IOException io) {
      //ignore this
    }
  }
}

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

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());

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

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

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

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

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

@Override
  public TreeContext generate(Reader r) throws IOException {
    CompilerEnvirons env = new CompilerEnvirons();
    env.setRecordingLocalJsDocComments(true);
    env.setAllowSharpComments(true);
    env.setRecordingComments(true);
    Parser p = new Parser(env);
    AstRoot root = p.parse(r, null, 1);
    RhinoTreeVisitor visitor = new RhinoTreeVisitor(root);
    root.visitAll(visitor);
    return visitor.getTree(root);
  }
}

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

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

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

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

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

/**
 * Compiles Text and resolves the type.
 * e.g 
 * "Hello World".length; //resolve as a Number
 * 
 * @param text to compile and resolve  
 */
@Override
public JavaScriptType compileText(String text) throws IOException {
  CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
  
  String parseText = JavaScriptHelper.removeLastDotFromText(text);
  
  int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(parseText);
  env.setRecoverFromErrors(true);
  Parser parser = new Parser(env);
  StringReader r = new StringReader(parseText);
  AstRoot root = parser.parse(r, null, 0);
  CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
  root.visitAll(visitor);
  return lastJavaScriptType;
}

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

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

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

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

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

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

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

Parser parser = new Parser(env);
StringReader r = new StringReader(text);
ParseText pt = new ParseText();

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

/**
 * Resolve node type to TypeDeclaration. Called instead of #compileText(String text) when document is already parsed
 * @param text The node to resolve
 * @return TypeDeclaration for node or null if not found.
 */
@Override
public TypeDeclaration resolveParamNode(String text) throws IOException {
  
  if(text != null) {
    CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
    
    
    int charIndex = JavaScriptHelper.findIndexOfFirstOpeningBracket(text);
    env.setRecoverFromErrors(true);
    Parser parser = new Parser(env);
    StringReader r = new StringReader(text);
    AstRoot root = parser.parse(r, null, 0);
    CompilerNodeVisitor visitor = new CompilerNodeVisitor(charIndex == 0);
    root.visitAll(visitor);
  }
  
  return lastJavaScriptType != null ? lastJavaScriptType.getType()
      : provider.getTypesFactory().getDefaultTypeDeclaration();
}

相关文章

Parser类方法