use of com.intellij.lang.LighterASTNode 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;
}
use of com.intellij.lang.LighterASTNode in project Perl5-IDEA by Camelcade.
the class TemplateToolkitParserUtil method parseBlockContent.
/**
* Parses block content
*
* @param b builder
* @param l level
* @return result of end parsing.
*/
public static boolean parseBlockContent(PsiBuilder b, int l, PsiBuilder.Marker outerMarker, IElementType blockTokenType) {
boolean r = false;
while (!b.eof() && TemplateToolkitParser.element(b, l)) {
LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
if (latestDoneMarker != null && latestDoneMarker.getTokenType() == END_DIRECTIVE) {
r = true;
break;
}
}
outerMarker.done(blockTokenType);
if (// this can happen on incomplete block, missing end
!r) {
outerMarker.setCustomEdgeTokenBinders(WhitespacesBinders.DEFAULT_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
outerMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.block.directive"));
}
return r;
}
use of com.intellij.lang.LighterASTNode in project Perl5-IDEA by Camelcade.
the class TemplateToolkitParserUtil method parseIfSequence.
public static boolean parseIfSequence(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() == ELSIF_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = ELSIF_BRANCH;
} else if (latestDoneMarker.getTokenType() == ELSE_DIRECTIVE) {
branchMarker.doneBefore(branchTokenType, currentMarker);
branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
branchMarker = currentMarker.precede();
branchTokenType = ELSE_BRANCH;
} else {
currentMarker.error(PerlBundle.message("ttk2.else.elsif.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.LighterASTNode in project intellij-community by JetBrains.
the class LightTreeUtil method getChildrenOfType.
@NotNull
public static List<LighterASTNode> getChildrenOfType(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull TokenSet types) {
List<LighterASTNode> children = tree.getChildren(node);
List<LighterASTNode> result = null;
for (int i = 0, size = children.size(); i < size; ++i) {
LighterASTNode child = children.get(i);
if (types.contains(child.getTokenType())) {
if (result == null)
result = new SmartList<>();
result.add(child);
}
}
return result != null ? result : Collections.<LighterASTNode>emptyList();
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class ContractInferenceInterpreter method visitLogicalOperation.
private List<MethodContract> visitLogicalOperation(List<LighterASTNode> operands, boolean conjunction, List<ValueConstraint[]> states) {
ValueConstraint breakValue = conjunction ? FALSE_VALUE : TRUE_VALUE;
List<MethodContract> finalStates = ContainerUtil.newArrayList();
for (LighterASTNode operand : operands) {
List<PreContract> opResults = visitExpression(states, operand);
finalStates.addAll(ContainerUtil.filter(knownContracts(opResults), contract -> contract.returnValue == breakValue));
states = antecedentsReturning(opResults, negateConstraint(breakValue));
}
finalStates.addAll(toContracts(states, negateConstraint(breakValue)));
return finalStates;
}
Aggregations