* grammars where indentation is important (e.g. Python, etc.)
* @return Token
*/
@Override
protected Token nextToken() {
Token token;
// Indent virtual terminals
if (useIndentVirtualTerminals) {
if (ivtTokens.isEmpty()) {
// Get next token from stream
token = produceToken();
// Token's position in source - initialize indentLevel stack
Position position = token.getPosition();
if (ivtIndentLevels.isEmpty()) {
ivtLine = position.getLine();
ivtIndentLevels.push(position);
}
// Trigger on change of line number
if (position.getLine() != ivtLine) {
ivtLine = position.getLine();
int ivtColumn = ivtIndentLevels.peek().getColumn();
if (position.getColumn() > ivtColumn) {
ivtTokens.push(token);
ivtIndentLevels.push(position);
token = new Token(getSymbolByName(VT_INDENT_INCREASE), getIndentLevels(), position);
} else if (token.getPosition().getColumn() < ivtColumn) {
ivtTokens.push(token);
while (!ivtIndentLevels.isEmpty() && ivtIndentLevels.peek().getColumn() > position.getColumn()) {
ivtIndentLevels.pop();
ivtTokens.push(new Token(getSymbolByName(VT_INDENT_DECREASE), getIndentLevels(), position));
}
token = ivtTokens.pop();
}
}