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

GetTokenType() public method

public GetTokenType ( string tokenName ) : int
tokenName string
return int
        public virtual int GetTokenType( string tokenName )
        {
            int i;
            if ( tokenName[0] == '\'' )
            {
                if ( composite.StringLiteralToTypeMap.TryGetValue( tokenName, out i ) )
                    return i;
            }
            else
            {
                // must be a label like ID
                if ( composite.TokenIDToTypeMap.TryGetValue( tokenName, out i ) )
                    return i;
            }

            return Label.INVALID;
        }

Usage Example

Exemplo n.º 1
0
 /** Pull your token definitions from an existing grammar in memory.
  *  You must use Grammar() ctor then this method then setGrammarContent()
  *  to make this work.  This was useful primarily for testing and
  *  interpreting grammars until I added import grammar functionality.
  *  When you import a grammar you implicitly import its vocabulary as well
  *  and keep the same token type values.
  *
  *  Returns the max token type found.
  */
 public virtual int ImportTokenVocabulary( Grammar importFromGr )
 {
     var importedTokenIDs = importFromGr.TokenIDs;
     foreach ( string tokenID in importedTokenIDs )
     {
         int tokenType = importFromGr.GetTokenType( tokenID );
         composite.MaxTokenType = Math.Max( composite.MaxTokenType, tokenType );
         if ( tokenType >= Label.MIN_TOKEN_TYPE )
         {
             //[email protected]("import token from grammar "+tokenID+"="+tokenType);
             DefineToken( tokenID, tokenType );
         }
     }
     return composite.MaxTokenType; // return max found
 }
All Usage Examples Of Antlr3.Tool.Grammar::GetTokenType
Grammar