Export (0) Print
Expand All

IScanner.ScanTokenAndProvideInfoAboutIt Method

Parses the next language token from the current line and returns information about it.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)

bool ScanTokenAndProvideInfoAboutIt(
	TokenInfo tokenInfo,
	ref int state
)

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.Boolean
Returns 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:
© 2014 Microsoft