int elementCounter = 0;
int matchedTokens = 0;
//TokenType tokenType = (TokenType) builder.getTokenType();
// check if the token objectType can be part of this iteration
//if (isDummyToken(builder.getTokenText()) || isSuppressibleReservedWord(tokenType, node) || iteratedElementType.containsToken(tokenType)) {
ParseResult result = iteratedElementType.getParser().parse(node, optional, depth + 1, context);
// check first iteration element
if (result.isMatch()) {
if (node.isRecursive(node.getStartOffset())) {
return stepOut(marker, depth, ParseResultType.FULL_MATCH, matchedTokens, node, context);
}
while (true) {
elementCounter++;
// check separator
// if not matched just step out
if (separatorTokens != null) {
for (TokenElementType separatorToken : separatorTokens) {
result = separatorToken.getParser().parse(node, false, depth + 1, context);
matchedTokens = matchedTokens + result.getMatchedTokens();
if (result.isMatch()) break;
}
if (result.isNoMatch()) {
// if NO_MATCH, no additional separator found, hence then iteration should exit with MATCH
ParseResultType resultType = matchesElementsCount(elementCounter) ?
ParseResultType.FULL_MATCH :
ParseResultType.PARTIAL_MATCH;
return stepOut(marker, depth, resultType, matchedTokens, node, context);
} else {
node.setCurrentOffset(builder.getCurrentOffset());
}
}
// check consecutive iterated element
// if not matched, step out with error
result = iteratedElementType.getParser().parse(node, true, depth + 1, context);
if (result.isNoMatch()) {
// missing separators permit ending the iteration as valid at any time
if (separatorTokens == null) {
ParseResultType resultType = matchesElementsCount(elementCounter) ?
ParseResultType.FULL_MATCH :
ParseResultType.PARTIAL_MATCH;
return stepOut(marker, depth, resultType, matchedTokens, node, context);
} else {
boolean exit = advanceLexerToNextLandmark(parentNode, false, context);
if (exit){
return stepOut(marker, depth, ParseResultType.PARTIAL_MATCH, matchedTokens, node, context);
}
}
} else {
matchedTokens = matchedTokens + result.getMatchedTokens();
}
}
}
//}
if (!optional) {