use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ArgumentList method argumentLabelStartCheck.
/**
* Checks for argument label. In case when it is so, a caret will not be restored at
* initial position
*
* @param builder
* @return pair of two booleans, first value indicates that label was parsed, second value indicates that argument was parsed.
* If first value is {@code true} then second is always {@code null}.
*/
public static Pair<Boolean, Boolean> argumentLabelStartCheck(PsiBuilder builder, GroovyParser parser) {
PsiBuilder.Marker marker = builder.mark();
if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mSTAR, GroovyTokenTypes.mCOLON)) {
builder.advanceLexer();
marker.done(GroovyElementTypes.ARGUMENT_LABEL);
return Pair.create(true, null);
}
final IElementType type = builder.getTokenType();
if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mIDENT, GroovyTokenTypes.mCOLON) || TokenSets.KEYWORDS.contains(type) || GroovyTokenTypes.mSTRING_LITERAL.equals(type) || GroovyTokenTypes.mGSTRING_LITERAL.equals(type)) {
builder.advanceLexer();
if (GroovyTokenTypes.mCOLON.equals(builder.getTokenType())) {
marker.done(GroovyElementTypes.ARGUMENT_LABEL);
return Pair.create(true, null);
} else {
marker.rollbackTo();
return Pair.create(false, false);
}
}
if (GroovyTokenTypes.mGSTRING_BEGIN.equals(type) || GroovyTokenTypes.mREGEX_BEGIN.equals(type) || GroovyTokenTypes.mDOLLAR_SLASH_REGEX_BEGIN.equals(type) || TokenSets.NUMBERS.contains(type) || GroovyTokenTypes.mLBRACK.equals(type) || GroovyTokenTypes.mLPAREN.equals(type) || GroovyTokenTypes.mLCURLY.equals(type)) {
PsiBuilder.Marker label = builder.mark();
if (AssignmentExpression.parse(builder, parser)) {
if (GroovyTokenTypes.mCOLON.equals(builder.getTokenType())) {
label.done(GroovyElementTypes.ARGUMENT_LABEL);
ParserUtils.getToken(builder, GroovyTokenTypes.mCOLON, GroovyBundle.message("colon.expected"));
if (AssignmentExpression.parse(builder, parser)) {
marker.done(GroovyElementTypes.NAMED_ARGUMENT);
} else {
builder.error(GroovyBundle.message("expression.expected"));
marker.drop();
}
} else {
label.drop();
marker.drop();
}
return Pair.create(false, true);
} else {
label.drop();
marker.rollbackTo();
}
} else {
marker.drop();
}
return Pair.create(false, false);
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class GroovyDocTagValueTokenType method parseImpl.
private ASTNode parseImpl(ASTNode chameleon) {
final PsiElement parentElement = chameleon.getTreeParent().getPsi();
final Project project = parentElement.getProject();
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), getLanguage(), chameleon.getText());
PsiBuilder.Marker rootMarker = builder.mark();
if (BUILT_IN_TYPES.contains(chameleon.getText())) {
builder.advanceLexer();
} else {
ReferenceElement.parse(builder, false, false, false, false, false);
while (!builder.eof()) {
builder.advanceLexer();
}
}
rootMarker.done(this);
return builder.getTreeBuilt().getFirstChildNode();
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class GroovyDocParsing method parseSeeOrLinkTagReference.
private boolean parseSeeOrLinkTagReference(PsiBuilder builder) {
IElementType type = builder.getTokenType();
if (!REFERENCE_BEGIN.contains(type))
return false;
PsiBuilder.Marker marker = builder.mark();
if (GroovyDocTokenTypes.mGDOC_TAG_VALUE_TOKEN == type) {
builder.advanceLexer();
}
if (GroovyDocTokenTypes.mGDOC_TAG_VALUE_SHARP_TOKEN == builder.getTokenType()) {
builder.advanceLexer();
RESULT result = parseFieldOrMethod(builder);
if (result == RESULT.ERROR) {
marker.drop();
} else if (result == RESULT.METHOD) {
marker.done(GroovyDocElementTypes.GDOC_METHOD_REF);
} else {
marker.done(GroovyDocElementTypes.GDOC_FIELD_REF);
}
return true;
}
marker.drop();
return true;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class PathExpression method pathElementParse.
@NotNull
private static Result pathElementParse(@NotNull PsiBuilder builder, @NotNull PsiBuilder.Marker marker, @NotNull GroovyParser parser, @NotNull Result result) {
// Property reference
if (isQualificationDot(builder)) {
if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mNLS, GroovyTokenTypes.mDOT)) {
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
}
ParserUtils.getToken(builder, DOTS);
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
TypeArguments.parseTypeArguments(builder, true);
GroovyElementType res = namePartParse(builder, parser);
if (res != GroovyElementTypes.WRONGWAY) {
PsiBuilder.Marker newMarker = marker.precede();
marker.done(res);
return parseAfterReference(builder, parser, newMarker);
} else {
builder.error(GroovyBundle.message("path.selector.expected"));
marker.drop();
return result;
}
} else if (checkForLParenth(builder)) {
PrimaryExpression.methodCallArgsParse(builder, parser);
return parseAfterArguments(builder, marker, parser);
} else if (checkForLCurly(builder)) {
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
appendedBlockParse(builder, parser);
return parseAfterArguments(builder, marker, parser);
} else if (checkForArrayAccess(builder)) {
indexPropertyArgsParse(builder, parser);
PsiBuilder.Marker newMarker = marker.precede();
marker.done(GroovyElementTypes.PATH_INDEX_PROPERTY);
return parseAfterReference(builder, parser, newMarker);
} else {
marker.drop();
return result;
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ShiftExpression method subParse.
private static void subParse(PsiBuilder builder, PsiBuilder.Marker marker, GroovyElementType shiftOrRange, GroovyParser parser) {
ParserUtils.getToken(builder, RANGES);
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
if (!BinaryExpression.ADDITIVE.parseBinary(builder, parser)) {
builder.error(GroovyBundle.message("expression.expected"));
}
PsiBuilder.Marker newMarker = marker.precede();
marker.done(shiftOrRange);
GroovyElementType newShiftOrRange = isRangeOrShift(builder);
if (RANGES.contains(builder.getTokenType()) || getCompositeSign(builder)) {
subParse(builder, newMarker, newShiftOrRange, parser);
} else {
newMarker.drop();
}
}
Aggregations