private void PromoteEOL(ParserRuleReturnScope rule)
{
// Get current token and its type (the possibly offending token).
IToken lt = input.LT(1);
int la = lt.Type;
// We only need to promote an EOL when the current token is offending (not a SEMIC, EOF, RBRACE, EOL or MultiLineComment).
// EOL and MultiLineComment are not offending as they're already promoted in a previous call to this method.
// Promoting an EOL means switching it from off channel to on channel.
// A MultiLineComment gets promoted when it contains an EOL.
if (!(la == SEMIC || la == EOF || la == RBRACE || la == EOL || la == MultiLineComment))
{
// Start on the possition before the current token and scan backwards off channel tokens until the previous on channel token.
for (int ix = lt.TokenIndex - 1; ix > 0; ix--)
{
lt = input.Get(ix);
if (lt.Channel == Token.DEFAULT_CHANNEL)
{
// On channel token found: stop scanning.
break;
}
else if (lt.Type == EOL || (lt.Type == MultiLineComment && (lt.Text.EndsWith("\r") || lt.Text.EndsWith("\n"))))
{
// We found our EOL: promote the token to on channel, position the input on it and reset the rule start.
lt.Channel = Token.DEFAULT_CHANNEL;
input.Seek(lt.TokenIndex);
if (rule != null)
{
rule.Start = lt;
}
break;
}
}
}
}