use of com.google.javascript.jscomp.parsing.parser.trees.Comment in project closure-compiler by google.
the class Scanner method skipMultiLineComment.
private void skipMultiLineComment() {
int startOffset = index;
// '/'
nextChar();
// '*'
nextChar();
while (!isAtEnd() && (peekChar() != '*' || peekChar(1) != '/')) {
nextChar();
}
if (!isAtEnd()) {
nextChar();
nextChar();
Comment.Type type = Comment.Type.BLOCK;
if (index - startOffset > 4) {
if (this.contents.charAt(startOffset + 2) == '*') {
type = Comment.Type.JSDOC;
} else if (this.contents.charAt(startOffset + 2) == '!') {
type = Comment.Type.IMPORTANT;
}
}
SourceRange range = lineNumberScanner.getSourceRange(startOffset, index);
String value = this.contents.substring(startOffset, index);
recordComment(type, range, value);
} else {
reportError("unterminated comment");
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.Comment in project closure-compiler by google.
the class ParserRunner method parse.
public static ParseResult parse(StaticSourceFile sourceFile, String sourceString, Config config, ErrorReporter errorReporter) {
// TODO(johnlenz): unify "SourceFile", "Es6ErrorReporter" and "Config"
String sourceName = sourceFile.getName();
try {
SourceFile file = new SourceFile(sourceName, sourceString);
boolean keepGoing = config.runMode() == Config.RunMode.KEEP_GOING;
Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, keepGoing);
com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = newParserConfig(config);
Parser p = new Parser(es6config, es6ErrorReporter, file);
ProgramTree tree = p.parseProgram();
Node root = null;
List<Comment> comments = ImmutableList.of();
FeatureSet features = p.getFeatures();
if (tree != null && (!es6ErrorReporter.hadError() || keepGoing)) {
IRFactory factory = IRFactory.transformTree(tree, sourceFile, config, errorReporter);
root = factory.getResultNode();
features = features.union(factory.getFeatures());
root.putProp(Node.FEATURE_SET, features);
if (config.jsDocParsingMode().shouldParseDescriptions()) {
comments = p.getComments();
}
}
return new ParseResult(root, comments, features, p.getSourceMapURL());
} catch (Throwable t) {
throw new RuntimeException("Exception parsing \"" + sourceName + "\"", t);
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.Comment in project closure-compiler by google.
the class IRFactory method parseNonJSDocCommentAt.
/**
* Creates a single NonJSDocComment from every comment associated with this node; or null if there
* are no such comments.
*
* <p>It would be legal to replace all comments associated with this node with that one string.
*/
@Nullable
private NonJSDocComment parseNonJSDocCommentAt(SourcePosition pos, boolean isInline) {
if (config.jsDocParsingMode() != JsDocParsing.INCLUDE_ALL_COMMENTS) {
return null;
}
if (!this.nonJsdocTracker.hasPendingCommentBefore(pos)) {
return null;
}
StringBuilder result = new StringBuilder();
Comment firstComment = this.nonJsdocTracker.current();
Comment lastComment = null;
while (this.nonJsdocTracker.hasPendingCommentBefore(pos)) {
Comment currentComment = this.nonJsdocTracker.current();
if (lastComment != null) {
for (int blankCount = currentComment.location.start.line - lastComment.location.end.line; blankCount > 0; blankCount--) {
result.append("\n");
}
}
result.append(currentComment.value);
lastComment = currentComment;
this.nonJsdocTracker.advance();
}
NonJSDocComment nonJSDocComment = new NonJSDocComment(firstComment.location.start, lastComment.location.end, result.toString());
nonJSDocComment.setEndsAsLineComment(lastComment.type == Comment.Type.LINE);
nonJSDocComment.setIsInline(isInline);
return nonJSDocComment;
}
use of com.google.javascript.jscomp.parsing.parser.trees.Comment in project closure-compiler by google.
the class IRFactory method getJSDocCommentAt.
private Comment getJSDocCommentAt(SourcePosition pos) {
Comment closestPreviousComment = null;
while (this.jsdocTracker.hasPendingCommentBefore(pos)) {
closestPreviousComment = this.jsdocTracker.current();
this.jsdocTracker.advance();
}
return closestPreviousComment;
}
use of com.google.javascript.jscomp.parsing.parser.trees.Comment in project closure-compiler by google.
the class IRFactory method transformTree.
public static IRFactory transformTree(ProgramTree tree, StaticSourceFile sourceFile, Config config, ErrorReporter errorReporter) {
IRFactory irFactory = new IRFactory(sourceFile, config, errorReporter, tree.sourceComments);
// don't call transform as we don't want standard jsdoc handling.
Node n = irFactory.transformDispatcher.process(tree);
irFactory.setSourceInfo(n, tree);
if (tree.sourceComments != null) {
for (Comment comment : tree.sourceComments) {
if ((comment.type == Comment.Type.JSDOC || comment.type == Comment.Type.IMPORTANT) && !irFactory.parsedComments.contains(comment)) {
irFactory.handlePossibleFileOverviewJsDoc(comment);
}
}
}
irFactory.setFileOverviewJsDoc(n);
irFactory.validateAll(n);
irFactory.resultNode = n;
return irFactory;
}
Aggregations