use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.
the class MojoliciousParser method parseTerm.
@Override
public boolean parseTerm(PsiBuilder b, int l) {
IElementType tokenType = b.getTokenType();
if (tokenType == MOJO_BEGIN) {
PsiBuilder.Marker subMarker = b.mark();
b.advanceLexer();
PsiBuilder.Marker blockMarker = b.mark();
PerlParserImpl.block_content(b, l);
if (b.getTokenType() == MOJO_END) {
blockMarker.done(BLOCK);
blockMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
subMarker.done(SUB_EXPR);
return true;
} else {
blockMarker.drop();
subMarker.rollbackTo();
}
}
return super.parseTerm(b, l);
}
use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.
the class PerlLazyBlockElementType method parseContents.
@Override
public ASTNode parseContents(ASTNode chameleon) {
PsiElement parentElement = chameleon.getTreeParent().getPsi();
Project project = parentElement.getProject();
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, getLexer(parentElement.getProject()), getLanguage(), chameleon.getText());
return getParser().parse(this, builder).getFirstChildNode();
}
use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.
the class MMPsiParser method recursiveParseTopic.
private int recursiveParseTopic(@Nonnull final PsiBuilder builder, final int level) {
while (!builder.eof()) {
final PsiBuilder.Marker marker = builder.mark();
final IElementType token = builder.getTokenType();
if (token == null) {
marker.drop();
} else {
if (token == MMTokens.TOPIC_LEVEL) {
final PsiBuilder.Marker levelMarker = builder.mark();
levelMarker.done(token);
final int theTopicLevel = ModelUtils.calcCharsOnStart('#', builder.getTokenText());
if (theTopicLevel <= 1) {
marker.done(MMTokens.UNKNOWN);
} else {
if (theTopicLevel <= level) {
marker.rollbackTo();
return theTopicLevel;
} else {
builder.advanceLexer();
final int parsedTopicLevel = recursiveParseTopic(builder, theTopicLevel);
marker.done(MMTokens.TOPIC);
if (parsedTopicLevel < theTopicLevel)
return parsedTopicLevel;
if (parsedTopicLevel == theTopicLevel)
continue;
}
}
} else if (token == MMTokens.TOPIC_TITLE || token == MMTokens.CODE_SNIPPET_BODY || token == MMTokens.CODE_SNIPPET_END || token == MMTokens.CODE_SNIPPET_START || token == MMTokens.ATTRIBUTES) {
marker.done(token);
} else if (token == MMTokens.EXTRA_TYPE) {
try {
if (parseExtraBlock(builder))
continue;
} finally {
marker.done(MMTokens.EXTRA_DATA);
}
} else if (token == MMTokens.WHITE_SPACE) {
marker.done(token);
} else {
marker.done(MMTokens.UNKNOWN);
}
}
builder.advanceLexer();
}
return level;
}
use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.
the class MMPsiParser method parseExtraBlock.
private boolean parseExtraBlock(@Nonnull final PsiBuilder builder) {
// read type
final PsiBuilder.Marker type = builder.mark();
if (builder.getTokenType() != MMTokens.EXTRA_TYPE)
throw Assertions.fail("Unexpected token " + builder.getTokenType());
builder.advanceLexer();
type.done(MMTokens.EXTRA_TYPE);
boolean dataFound = false;
// read body
while (!builder.eof()) {
final PsiBuilder.Marker marker = builder.mark();
if (builder.eof() || builder.getTokenType() == null) {
marker.drop();
break;
} else {
final IElementType token = builder.getTokenType();
if (token == MMTokens.TOPIC_LEVEL || token == MMTokens.EXTRA_TYPE) {
marker.rollbackTo();
return true;
} else if (token == MMTokens.EXTRA_BODY || token == MMTokens.WHITE_SPACE) {
if (dataFound && token == MMTokens.EXTRA_BODY) {
builder.advanceLexer();
marker.done(MMTokens.UNKNOWN);
break;
} else {
builder.advanceLexer();
marker.done(token);
dataFound = dataFound || token == MMTokens.EXTRA_BODY;
}
} else {
marker.done(MMTokens.UNKNOWN);
break;
}
}
}
return false;
}
use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.
the class MMPsiParser method parseHeader.
private void parseHeader(@Nonnull final PsiBuilder builder) {
boolean doLoop = true;
while (doLoop && !builder.eof()) {
final PsiBuilder.Marker marker = builder.mark();
if (builder.getTokenType() == null) {
marker.drop();
} else {
final IElementType token = builder.getTokenType();
if (token == MMTokens.HEADER_DELIMITER) {
marker.done(token);
doLoop = false;
} else if (token == MMTokens.HEADER_LINE || token == MMTokens.UNKNOWN || token == MMTokens.WHITE_SPACE || token == MMTokens.ATTRIBUTES) {
marker.done(token);
} else {
throw Assertions.fail("Unexpected header token : " + token);
}
}
builder.advanceLexer();
}
}
Aggregations