IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo, Int32) Method

Definition

Scan the next token and fill in syntax coloring details about it in tokenInfo.

public:
 bool ScanTokenAndProvideInfoAboutIt(Microsoft::VisualStudio::Package::TokenInfo ^ tokenInfo, int % state);
bool ScanTokenAndProvideInfoAboutIt(Microsoft::VisualStudio::Package::TokenInfo const & tokenInfo, int & state);
public bool ScanTokenAndProvideInfoAboutIt (Microsoft.VisualStudio.Package.TokenInfo tokenInfo, ref int state);
abstract member ScanTokenAndProvideInfoAboutIt : Microsoft.VisualStudio.Package.TokenInfo *  -> bool

Parameters

tokenInfo
TokenInfo

Keeps information about token.

state
Int32

Keeps track of scanner state. In: state after last token. Out: state after current token.

Returns

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

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.

Applies to