本文整理汇总了Java中com.google.javascript.jscomp.parsing.ParserRunner.parse方法的典型用法代码示例。如果您正苦于以下问题:Java ParserRunner.parse方法的具体用法?Java ParserRunner.parse怎么用?Java ParserRunner.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.parsing.ParserRunner
的用法示例。
在下文中一共展示了ParserRunner.parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
private void parse(AbstractCompiler compiler, String sourceName,
String sourceStr) {
try {
logger_.fine("Parsing: " + sourceName);
root = ParserRunner.parse(sourceName, sourceStr,
compiler.getParserConfig(),
compiler.getDefaultErrorReporter(),
logger_);
} catch (IOException e) {
compiler.report(JSError.make(AbstractCompiler.READ_ERROR, sourceName));
}
if (root == null || compiler.hasHaltingErrors()) {
// There was a parse error or IOException, so use a dummy block.
root = new Node(Token.BLOCK);
} else {
compiler.prepareAst(root);
}
// Set the source name so that the compiler passes can track
// the source file and module.
root.putProp(Node.SOURCENAME_PROP, sourceName);
}
示例2: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
private void parse(AbstractCompiler compiler) {
try {
logger_.fine("Parsing: " + sourceFile.getName());
ParserRunner.ParseResult result = ParserRunner.parse(sourceFile, sourceFile.getCode(),
compiler.getParserConfig(),
compiler.getDefaultErrorReporter(),
logger_);
root = result.ast;
compiler.setOldParseTree(sourceFile.getName(), result.oldAst);
} catch (IOException e) {
compiler.report(
JSError.make(AbstractCompiler.READ_ERROR, sourceFile.getName()));
}
if (root == null || compiler.hasHaltingErrors()) {
// There was a parse error or IOException, so use a dummy block.
root = IR.script();
} else {
compiler.prepareAst(root);
}
// Set the source name so that the compiler passes can track
// the source file and module.
root.setStaticSourceFile(sourceFile);
}
示例3: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
/**
* Parses the given JavaScript string into an abstract syntax tree.
*
* @param js The JavaScript code.
* @param inputFileName The source filename to associate with the input JS.
* @return An abstract syntax tree.
* @throws JavaScriptParsingException if parse errors were encountered.
*/
private static Node parse(String js, String inputFileName) throws JavaScriptParsingException {
StaticSourceFile file = new SimpleSourceFile(inputFileName, false);
Config config = ParserRunner.createConfig(LanguageMode.ECMASCRIPT6, null, StrictMode.SLOPPY);
JavaScriptErrorReporter errorReporter = new JavaScriptErrorReporter(js);
Node script = ParserRunner.parse(file, js, config, errorReporter).ast;
if (script == null) {
throw new JavaScriptParsingException(errorReporter.getWarningAndErrorOutput());
}
return script;
}
示例4: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
/** Internal implementation to produce the {@link FileInfo} object. */
private static FileInfo parse(String code, String filename, @Nullable Reporter reporter) {
ErrorReporter errorReporter = new DelegatingReporter(reporter);
Compiler compiler = new Compiler();
compiler.init(
ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), new CompilerOptions());
Config config =
ParserRunner.createConfig(
// TODO(sdh): ES8 STRICT, with a non-strict fallback - then give warnings.
Config.LanguageMode.ECMASCRIPT8,
Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE,
Config.RunMode.KEEP_GOING,
/* extraAnnotationNames */ ImmutableSet.<String>of(),
/* parseInlineSourceMaps */ true,
Config.StrictMode.SLOPPY);
SourceFile source = SourceFile.fromCode(filename, code);
FileInfo info = new FileInfo(errorReporter);
ParserRunner.ParseResult parsed = ParserRunner.parse(source, code, config, errorReporter);
parsed.ast.setInputId(new InputId(filename));
String version = parsed.features.version();
if (!version.equals("es3")) {
info.loadFlags.add(JsArray.of("lang", version));
}
for (Comment comment : parsed.comments) {
if (comment.type == Comment.Type.JSDOC) {
parseComment(comment, info);
}
}
NodeTraversal.traverseEs6(compiler, parsed.ast, new Traverser(info));
return info;
}
示例5: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
private void parse(AbstractCompiler compiler) {
int startErrorCount = compiler.getErrorManager().getErrorCount();
try {
ParserRunner.ParseResult result = ParserRunner.parse(sourceFile, sourceFile.getCode(),
compiler.getParserConfig(sourceFile.isExtern()
? AbstractCompiler.ConfigContext.EXTERNS
: AbstractCompiler.ConfigContext.DEFAULT),
compiler.getDefaultErrorReporter(),
logger_);
root = result.ast;
compiler.addComments(sourceFile.getName(), result.comments);
} catch (IOException e) {
compiler.report(
JSError.make(AbstractCompiler.READ_ERROR, sourceFile.getName()));
}
if (root == null ||
// Most passes try to report as many errors as possible,
// so there may already be errors. We only care if there were
// errors in the code we just parsed.
(compiler.getErrorManager().getErrorCount() > startErrorCount && !compiler.isIdeMode())) {
// There was a parse error or IOException, so use a dummy block.
root = IR.script();
} else {
compiler.prepareAst(root);
}
// Set the source name so that the compiler passes can track
// the source file and module.
root.setStaticSourceFile(sourceFile);
}
示例6: parse
import com.google.javascript.jscomp.parsing.ParserRunner; //导入方法依赖的package包/类
private void parse(AbstractCompiler compiler) {
int startErrorCount = compiler.getErrorManager().getErrorCount();
try {
ParserRunner.ParseResult result = ParserRunner.parse(sourceFile, sourceFile.getCode(),
compiler.getParserConfig(),
compiler.getDefaultErrorReporter(),
logger_);
root = result.ast;
compiler.setOldParseTree(sourceFile.getName(), result.oldAst);
} catch (IOException e) {
compiler.report(
JSError.make(AbstractCompiler.READ_ERROR, sourceFile.getName()));
}
if (root == null ||
// Most passes try to report as many errors as possible,
// so there may already be errors. We only care if there were
// errors in the code we just parsed.
(compiler.getErrorManager().getErrorCount() > startErrorCount && !compiler.isIdeMode())) {
// There was a parse error or IOException, so use a dummy block.
root = IR.script();
} else {
compiler.prepareAst(root);
}
// Set the source name so that the compiler passes can track
// the source file and module.
root.setStaticSourceFile(sourceFile);
}