Partager via


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)

Syntax

'Declaration
Function ScanTokenAndProvideInfoAboutIt ( _
    tokenInfo As TokenInfo, _
    ByRef state As Integer _
) As Boolean
bool ScanTokenAndProvideInfoAboutIt(
    TokenInfo tokenInfo,
    ref int state
)
bool ScanTokenAndProvideInfoAboutIt(
    TokenInfo^ tokenInfo, 
    int% state
)
abstract ScanTokenAndProvideInfoAboutIt : 
        tokenInfo:TokenInfo * 
        state:int byref -> bool
function ScanTokenAndProvideInfoAboutIt(
    tokenInfo : TokenInfo, 
    state : int
) : boolean

Parameters

  • state
    Type: Int32%

    [in, out] The scanner's current state value.

Return Value

Type: 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.

Remarks

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.

Examples

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;
        }
    }
}

.NET Framework Security

See Also

Reference

IScanner Interface

Microsoft.VisualStudio.Package Namespace