MergableLexerBase Class
Represents the base implementation of a lexer (lexical analyzer) for a language that supports merging with other languages.
public abstract class MergableLexerBase : IMergableLexer, ILexer, IKeyedObject
- Inheritance:
- Object Object
- Implements:
- IMergableLexer ILexer IKeyedObject
Remarks
Instances of this object can be registered with an ISyntaxLanguage using the RegisterService(Object, Object) method. Once an instance is registered with the language for the ILexer interface type, its features can be used by the language.
Constructors
MergableLexerBase()
Initializes a new instance of the MergableLexerBase
class.
protected MergableLexerBase()
Properties
DefaultLexicalStateCore
Gets or sets the root ILexicalState for when the language is entered.
protected ILexicalState DefaultLexicalStateCore { get; set; }
Property Value
- ILexicalState:
The root ILexicalState for when the language is entered.
KeyCore
Gets or sets a string that identifies the lexer, generally the related language name.
protected string KeyCore { get; set; }
Property Value
- String:
A string that identifies the lexer, generally the related language name.
LexicalStateIdProviderCore
Gets or sets the ILexicalStateIdProvider that provides access to all the lexical state IDs and keys used by this lexer.
protected ILexicalStateIdProvider LexicalStateIdProviderCore { get; set; }
Property Value
- ILexicalStateIdProvider:
The ILexicalStateIdProvider that provides access to all the lexical state IDs and keys used by this lexer.
TokenIdProviderCore
Gets or sets the ITokenIdProvider that provides access to all the token IDs and keys used by this lexer.
protected ITokenIdProvider TokenIdProviderCore { get; set; }
Property Value
- ITokenIdProvider:
The ITokenIdProvider that provides access to all the token IDs and keys used by this lexer.
Methods
CreateChangeBatch()
Creates an IDisposable object such that while the object is not disposed, the lexer can be modified without any change events being fired, thereby allowing batch updates to occur.
public IDisposable CreateChangeBatch()
Returns
- IDisposable:
An IDisposable object. Once disposed, the batch is ended.
CreateDocumentEndToken(Int32, TextPosition, ILexicalState)
Creates an IMergableToken that represents the end of a document.
public virtual IMergableToken CreateDocumentEndToken(int startOffset, TextPosition startPosition, ILexicalState lexicalState)
Parameter | Type | Description |
---|---|---|
startOffset | Int32 | The start offset of the IToken. |
startPosition | TextPosition | The start TextPosition of the IToken. |
lexicalState | ILexicalState | The ILexicalState that contains the token. |
Returns
- IMergableToken:
An IMergableToken that represents the end of a document.
CreateToken(Int32, Int32, TextPosition, TextPosition, MergableLexerFlags, ILexicalState, IMergableTokenLexerData)
Creates an IMergableToken that represents the range of text with the specified lexer data.
public virtual IMergableToken CreateToken(int startOffset, int length, TextPosition startPosition, TextPosition endPosition, MergableLexerFlags lexerFlags, ILexicalState lexicalState, IMergableTokenLexerData lexerData)
Parameter | Type | Description |
---|---|---|
startOffset | Int32 | The start offset of the token. |
length | Int32 | The length of the token. |
startPosition | TextPosition | The TextPosition of the first character in the token. |
endPosition | TextPosition | The TextPosition after the last character in the token. |
lexerFlags | MergableLexerFlags | The MergableLexerFlags for the token. |
lexicalState | ILexicalState | The ILexicalState that contains the token. |
lexerData | IMergableTokenLexerData | The IMergableTokenLexerData that contains lexer information about the token. |
Returns
- IMergableToken:
An IMergableToken that represents the range of text with the specified lexer data.
GetAllLexicalStateTransitions()
Returns a collection containing all ILexicalStateTransition objects within the lexer.
public abstract IEnumerable<ILexicalStateTransition> GetAllLexicalStateTransitions()
Returns
- IEnumerable<ILexicalStateTransition>:
A collection containing all ILexicalStateTransition objects within the lexer.
Remarks
This method allows consumers to see which language transitions can be made within the lexer.
GetDefaultToken(ITextBufferReader, ILexicalState)
Returns a single-character MergableLexerResult representing the lexer result for the default token in the ILexicalState and seeks forward one position in the ITextBufferReader
public virtual MergableLexerResult GetDefaultToken(ITextBufferReader reader, ILexicalState lexicalState)
Parameter | Type | Description |
---|---|---|
reader | ITextBufferReader | An ITextBufferReader that is reading a text source. |
lexicalState | ILexicalState | The ILexicalState that specifies the current state. |
Returns
- MergableLexerResult:
A MergableLexerResult indicating the lexer result.
GetIncrementalParseRange(TextSnapshotRange)
Returns a TextSnapshotRange that indicates the minimum range to parse when incremental parsing for the specified TextSnapshotRange is requested.
protected virtual TextSnapshotRange GetIncrementalParseRange(TextSnapshotRange snapshotRange)
Parameter | Type | Description |
---|---|---|
snapshotRange | TextSnapshotRange | The requested TextSnapshotRange to incrementally parse. |
Returns
- TextSnapshotRange:
The actual TextSnapshotRange to incrementally parse.
Remarks
When performing incremental parsing, a larger snapshot range than the actual modified snapshot range should usually be parsed. For instance, if the end user types text at the end of a word that should make the word a keyword, incremental parsing should start at least at the start of the word or else it won't be recognized as a keyword.
The default implementation of this method starts incremental parsing at the start of the line at which the requested snapshot range begins.
This method is called by the default Parse(TextSnapshotRange, ILexerTarget) implementation to modify the snapshot range to parse.
GetNextToken(ITextBufferReader, ILexicalState)
Performs a lex to return the next MergableLexerResult from a ITextBufferReader and seeks past it if there is a match.
public abstract MergableLexerResult GetNextToken(ITextBufferReader reader, ILexicalState lexicalState)
Parameter | Type | Description |
---|---|---|
reader | ITextBufferReader | An ITextBufferReader that is reading a text source. |
lexicalState | ILexicalState | The ILexicalState that specifies the current state. |
Returns
- MergableLexerResult:
A MergableLexerResult indicating the lexer result.
OnChanged(EventArgs)
Raises the Changed event.
protected virtual void OnChanged(EventArgs e)
Parameter | Type | Description |
---|---|---|
e | EventArgs | The |
Parse(TextSnapshotRange, ILexerTarget)
Lexically parses the specified TextRange of the ITextSnapshot.
public virtual TextRange Parse(TextSnapshotRange snapshotRange, ILexerTarget parseTarget)
Parameter | Type | Description |
---|---|---|
snapshotRange | TextSnapshotRange | A TextSnapshotRange indicating the offset range to parse. |
parseTarget | ILexerTarget | The ILexerTarget that receives the parsing output. |
Returns
Events
Changed
Occurs after the lexer is changed via a block of code surrounded by CreateChangeBatch().
Explicit Interface Implementations
ILexer.TokenIdProvider
Gets the ITokenIdProvider that provides access to all the token IDs and keys used by this lexer.
ITokenIdProvider ILexer.TokenIdProvider { get; }
Returns
- ITokenIdProvider:
The ITokenIdProvider that provides access to all the token IDs and keys used by this lexer.
IMergableLexer.DefaultLexicalState
Gets the root ILexicalState for when the language is entered.
ILexicalState IMergableLexer.DefaultLexicalState { get; }
Returns
- ILexicalState:
The root ILexicalState for when the language is entered.
IMergableLexer.LexicalStateIdProvider
Gets the ILexicalStateIdProvider that provides access to all the lexical state IDs and keys used by this lexer.
ILexicalStateIdProvider IMergableLexer.LexicalStateIdProvider { get; }
Returns
- ILexicalStateIdProvider:
The ILexicalStateIdProvider that provides access to all the lexical state IDs and keys used by this lexer.
IKeyedObject.Key
Gets a string that identifies the lexer, generally the related language name.
string IKeyedObject.Key { get; }
Returns
- String:
A string that identifies the lexer, generally the related language name.