IScanner::ScanTokenAndProvideInfoAboutIt Method (TokenInfo^, Int32)
Visual Studio 2015
Parses the next language token from the current line and returns information about it.
Assembly: Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)
Parameters
- tokenInfo
-
Type:
Microsoft.VisualStudio.Package::TokenInfo^
[in, out] The TokenInfo structure to be filled in.
- state
-
Type:
System::Int32
[in, out] The scanner's current state value.
Return Value
Type: System::BooleanReturns true if a token was parsed from the current line and information returned; otherwise, returns false indicating no more tokens on the current line.
Call the SetSource method to set the line that is to be parsed. Then the ScanTokenAndProvideInfoAboutIt method is typically called repeatedly until all tokens are obtained.
This is an example of the way a colorizer might use this method.
using Microsoft.VisualStudio.TextManager.Interop; using Microsoft.VisualStudio.Package; namespace MyLanguagePackage { public class MyColorizer : IVsColorizer { IScanner scanner; public int ColorizeLine(int line, int length, IntPtr ptr, int state, uint[] attrs) { int linepos = 0; if (this.scanner != null) { try { string text = Marshal.PtrToStringUni(ptr, length); this.scanner.SetSource(text, 0); TokenInfo tokenInfo = new TokenInfo(); while (this.scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state)) { // Do something with tokenInfo } } catch (Exception) { // Catch and ignore exceptions } } return state; } } }
Show: