Antlr3.Tool.Grammar.DefineLexerRuleForAliasedStringLiteral C# (CSharp) Method

DefineLexerRuleForAliasedStringLiteral() public method

public DefineLexerRuleForAliasedStringLiteral ( string tokenID, string literal, int tokenType ) : void
tokenID string
literal string
tokenType int
return void
        public virtual void DefineLexerRuleForAliasedStringLiteral( string tokenID,
                                                           string literal,
                                                           int tokenType )
        {
            if ( IsRoot )
            { // don't build lexers for delegates
                //[email protected]("defineLexerRuleForAliasedStringLiteral: "+literal+" "+tokenType);
                LexerGrammarTemplate.SetAttribute( "literals.{ruleName,type,literal}",
                                            tokenID,
                                            tokenType,
                                            literal );
            }
            // track this lexer rule's name
            composite.LexerRules.Add( tokenID );
        }

Usage Example

 protected override void AliasTokenIDsAndLiterals( Grammar root )
 {
     if ( root.type == GrammarType.Lexer )
     {
         return; // strings/chars are never token types in LEXER
     }
     // walk aliases if any and assign types to aliased literals if literal
     // was referenced
     foreach ( var alias in _aliases )
     {
         string tokenID = alias.Key;
         string literal = alias.Value;
         if ( literal[0] == '\'' && _stringLiterals.ContainsKey( literal ) )
         {
             int token;
             _tokens.TryGetValue(tokenID, out token);
             _stringLiterals[literal] = token;
             // an alias still means you need a lexer rule for it
             int typeI;
             _tokens.TryGetValue(tokenID, out typeI);
             if ( !tokenRuleDefs.Contains( tokenID ) )
             {
                 root.DefineLexerRuleForAliasedStringLiteral( tokenID, literal, typeI );
             }
         }
     }
 }
Grammar