IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo, Int32) Method

Definition

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

public bool ScanTokenAndProvideInfoAboutIt (Microsoft.VisualStudio.Package.TokenInfo tokenInfo, ref int state);
Parameters
tokenInfo
TokenInfo

[in, out] The TokenInfo structure to be filled in.

state
Int32

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

Returns

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.

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