currentRule = null;
}
}
private boolean tryMatchRule() {
ATEToken start = T(0);
if(start == null) return false;
// Match any modifiers
if(ruleModifiers.contains(start.getAttribute())) {
// skip the modifier
if(!nextToken()) return false;
}
// Match the name (it has to be an ID)
ElementToken tokenName = (ElementToken) T(0);
String name = tokenName.getAttribute();
if(!matchID(0)) return false;
// Match any optional argument
matchArguments();
// Match any comments
while(true) {
if(matchSingleComment(0)) continue;
if(matchComplexComment(0)) continue;
break;
}
// Match any returns
if(matchID(0, "returns")) {
matchArguments();
}
// Match any optional "!"
matchChar(0, "!");
// Match any comments, scopes and blocks
while(true) {
if(matchScopeUse()) continue;
if(matchBlock()) continue;
if(matchSingleComment(0)) continue;
if(matchComplexComment(0)) continue;
if(isCOLON(0)) {
// When a colon is matched, we are at the beginning of the content of the rule
nextToken();
break;
} else {
// Invalid rule matching
return false;
}
}
// Parse the content of the rule (after the ':')
final ATEToken colonToken = T(-1);
final int oldRefsSize = references.size();
final int oldBlocksSize = blocks.size();
final int oldActionsSize = actions.size();
currentRule = new ElementRule(this, name, start, colonToken, null);
labels.clear();