use of com.intellij.lang.PsiBuilder in project intellij-plugins by JetBrains.
the class GherkinParser method parseFeatureElements.
private static void parseFeatureElements(PsiBuilder builder) {
while (builder.getTokenType() != GherkinTokenTypes.FEATURE_KEYWORD && !builder.eof()) {
final PsiBuilder.Marker marker = builder.mark();
// tags
parseTags(builder);
// scenarios
IElementType startTokenType = builder.getTokenType();
final boolean outline = startTokenType == GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD;
builder.advanceLexer();
parseScenario(builder, outline);
marker.done(outline ? GherkinElementTypes.SCENARIO_OUTLINE : GherkinElementTypes.SCENARIO);
}
}
use of com.intellij.lang.PsiBuilder in project intellij-plugins by JetBrains.
the class GherkinParser method parseFeature.
private static void parseFeature(PsiBuilder builder) {
final PsiBuilder.Marker marker = builder.mark();
assert builder.getTokenType() == GherkinTokenTypes.FEATURE_KEYWORD;
final int featureEnd = builder.getCurrentOffset() + getTokenLength(builder.getTokenText());
PsiBuilder.Marker descMarker = null;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == GherkinTokenTypes.TEXT && descMarker == null) {
if (hadLineBreakBefore(builder, featureEnd)) {
descMarker = builder.mark();
}
}
if (tokenType == GherkinTokenTypes.SCENARIO_KEYWORD || tokenType == GherkinTokenTypes.BACKGROUND_KEYWORD || tokenType == GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD || tokenType == GherkinTokenTypes.TAG) {
if (descMarker != null) {
descMarker.done(GherkinElementTypes.FEATURE_HEADER);
descMarker = null;
}
parseFeatureElements(builder);
if (builder.getTokenType() == GherkinTokenTypes.FEATURE_KEYWORD) {
break;
}
}
builder.advanceLexer();
if (builder.eof())
break;
}
if (descMarker != null) {
descMarker.done(GherkinElementTypes.FEATURE_HEADER);
}
marker.done(GherkinElementTypes.FEATURE);
}
use of com.intellij.lang.PsiBuilder in project intellij-plugins by JetBrains.
the class GherkinParser method parseTable.
private static void parseTable(PsiBuilder builder) {
final PsiBuilder.Marker marker = builder.mark();
PsiBuilder.Marker rowMarker = builder.mark();
int prevCellEnd = -1;
boolean isHeaderRow = true;
PsiBuilder.Marker cellMarker = null;
IElementType prevToken = null;
while (builder.getTokenType() == GherkinTokenTypes.PIPE || builder.getTokenType() == GherkinTokenTypes.TABLE_CELL) {
final IElementType tokenType = builder.getTokenType();
final boolean hasLineBreakBefore = hadLineBreakBefore(builder, prevCellEnd);
// cell - is all between pipes
if (prevToken == GherkinTokenTypes.PIPE) {
// it's not a cell, we just need to close a row
if (!hasLineBreakBefore) {
cellMarker = builder.mark();
}
}
if (tokenType == GherkinTokenTypes.PIPE) {
if (cellMarker != null) {
closeCell(cellMarker);
cellMarker = null;
}
}
if (hasLineBreakBefore) {
closeRowMarker(rowMarker, isHeaderRow);
isHeaderRow = false;
rowMarker = builder.mark();
}
prevCellEnd = builder.getCurrentOffset() + getTokenLength(builder.getTokenText());
prevToken = tokenType;
builder.advanceLexer();
}
if (cellMarker != null) {
closeCell(cellMarker);
}
closeRowMarker(rowMarker, isHeaderRow);
marker.done(GherkinElementTypes.TABLE);
}
use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.
the class TemplateToolkitParserUtil method parseTryCatchBlock.
public static boolean parseTryCatchBlock(PsiBuilder b, int l, PsiBuilder.Marker branchMarker, IElementType branchTokenType) {
while (!b.eof()) {
PsiBuilder.Marker currentMarker = b.mark();
if (TemplateToolkitParser.element(b, l)) {
LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
if (latestDoneMarker != null) {
if (latestDoneMarker.getTokenType() == END_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
currentMarker.drop();
branchMarker = null;
break;
} else if (latestDoneMarker.getTokenType() == CATCH_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = CATCH_BRANCH;
} else if (latestDoneMarker.getTokenType() == FINAL_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = FINAL_BRANCH;
} else {
currentMarker.error(PerlBundle.message("ttk2.catch.final.end.expected"));
}
currentMarker.drop();
}
} else {
b.advanceLexer();
currentMarker.error(PerlBundle.message("ttk2.unexpected.token"));
}
}
if (branchMarker != null) {
branchMarker.done(branchTokenType);
branchMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.block.directive"));
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
}
return true;
}
use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.
the class TemplateToolkitParserUtil method parsePerlCode.
/**
* Collapses perl code for lazy parsing
*
* @param b builder
* @param l level
* @return result of end parsing.
*/
public static boolean parsePerlCode(PsiBuilder b, int l, PsiBuilder.Marker outerMarker, IElementType perlTokenType, IElementType blockTokenType) {
PsiBuilder.Marker perlMarker = b.mark();
while (!b.eof() && !isEndTagAhead(b, l)) {
b.advanceLexer();
}
boolean recoverBlock = true;
if (isEndTagAhead(b, l)) {
perlMarker.collapse(perlTokenType);
perlMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
} else {
perlMarker.drop();
}
if (TemplateToolkitParser.element(b, l)) {
LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
if (latestDoneMarker != null && latestDoneMarker.getTokenType() == END_DIRECTIVE) {
outerMarker.done(blockTokenType);
recoverBlock = false;
}
}
if (recoverBlock) {
while (!b.eof() || b.getTokenType() == TT2_OUTLINE_TAG || b.getTokenType() == TT2_OPEN_TAG) {
b.advanceLexer();
}
outerMarker.done(blockTokenType);
outerMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
outerMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.perl.block"));
}
return true;
}
Aggregations