ReSharper DevGuide

Lexer Utility Methods

The LexerUtil class provides a number of utility and extension functions for lexing and parsing. Of particular interest are the LookaheadToken methods, GetTokenLength and GetCurrTokenText:

publicstaticclassLexerUtil{// Look ahead to the k'th token and return it, the roll back to the current positionstaticpublicTokenNodeTypeLookaheadToken(thisILexerlexer,intk);staticpublicTokenNodeTypeLookaheadToken<T>(thisILexer<T>lexer,intk);// Look ahead, but skip the given node typestaticpublicTokenNodeTypeLookaheadTokenSkipping(thisILexerlexer,intk,TokenNodeTypenodeTypeToSkip);// Get the length of the text of the current tokenpublicstaticintGetTokenLength(thisILexerlexer);// Get the text of the current token, with or without quotespublicstaticstringGetCurrTokenText(thisILexerlexer);publicstaticstringGetQuotedTokenText(thisILexerlexer,charquote);publicstaticstringGetQuotedTokenText(thisILexerlexer,charopenQuote,charcloseQuote);// Compare the current token text against the given string. Functionally equivalentpublicstaticboolCompareTokenText(ILexerlexer,stringstr,boolcaseSensitive=true);publicstaticboolCompareBufferText(ILexerlexer,stringstr,boolcaseSensitive=true);// Return a lazy enumerable of TokenNodeType by calling lexer.AdvancepublicstaticIEnumerable<TokenNodeType>Tokens(thisILexerlexer);// Advance lexer while the current token is the same as the skip token(s)publicstaticintAdvanceWhile<TLexer>(thisTLexerlexer,TokenNodeTypeskipToken);publicstaticintAdvanceWhile<TLexer>(thisTLexerlexer,NodeTypeSetskipTokens);}