/**
* Assign constant values to custom channels defined in a grammar.
*
* @param g The grammar.
* @param channelDefs A collection of AST nodes defining individual channels
* within a {@code channels{}} block in the grammar.
*/
internal virtual void AssignChannelTypes(Grammar g, IList<GrammarAST> channelDefs)
{
Grammar outermost = g.GetOutermostGrammar();
foreach (GrammarAST channel in channelDefs)
{
string channelName = channel.Text;
// Channel names can't alias tokens or modes, because constant
// values are also assigned to them and the ->channel(NAME) lexer
// command does not distinguish between the various ways a constant
// can be declared. This method does not verify that channels do not
// alias rules, because rule names are not associated with constant
// values in ANTLR grammar semantics.
if (g.GetTokenType(channelName) != TokenConstants.InvalidType)
{
g.tool.errMgr.GrammarError(ErrorType.CHANNEL_CONFLICTS_WITH_TOKEN, g.fileName, channel.Token, channelName);
}
if (LexerATNFactory.COMMON_CONSTANTS.ContainsKey(channelName))
{
g.tool.errMgr.GrammarError(ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, channel.Token, channelName);
}
if (outermost is LexerGrammar)
{
LexerGrammar lexerGrammar = (LexerGrammar)outermost;
if (lexerGrammar.modes.ContainsKey(channelName))
{
g.tool.errMgr.GrammarError(ErrorType.CHANNEL_CONFLICTS_WITH_MODE, g.fileName, channel.Token, channelName);
}
}
outermost.DefineChannelName(channel.Text);
}
}