No syntax highlighting after overriding GetNextToken of a DynamicLexer

SyntaxEditor for WPF Forum

Posted 10 years ago by Aernout van Groen
Version: 13.2.0591
Avatar

Hi,

I want to override the lexing for a specific lexical state.
So I implemented this in my Dynamic lexer. Here is a simplified version:

 

public override ActiproSoftware.Text.Lexing.MergableLexerResult GetNextToken(ActiproSoftware.Text.ITextBufferReader reader, ActiproSoftware.Text.Lexing.ILexicalState lexicalState)
{

if (((ActiproSoftware.Text.Lexing.Implementation.LexicalStateBase)(lexicalState)).Key != "PrimaryString")
{
return base.GetNextToken(reader, lexicalState);
}
else
{
// Custom lexing logic: 
reader.Read();
return new MergableLexerResult(MatchType.ExactMatch, new LexicalStateTokenData(lexicalState, MyScriptTokenId.PrimaryStringText));
}

} 

 

The token is created, but there is no syntax highlighting
The problem is that the property ClassificationType in the LexicalStateTokenData is null.
I cannot find a way to set this property; it is readonly.
(When I call the base.GetNextToken, it is working OK)

Do you have any suggestions?

 

Thanks and regards,

Aernout

Comments (2)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi,

The second parameter to MergableLexerResult can be any IMergableTokenLexerData.  The LexicalStateTokenData you are using always returns null for the ClassificationType.  I would recommend that you make your own class that implements IMergableTokenLexerData so that you can pass in the property classification type you want.  That's one way to do it.

Another thing you can do is what we do in the Getting Started #3c sample for programmatic lexers where in the token tagger class, we override the ClassifyToken method and derive the classification type based on the token ID.  If you go with that approach instead, you would check the token to see if it's your custom kind and return the classification type if it is.  Otherwise, you would call the base method.


Actipro Software Support

Posted 10 years ago by Aernout van Groen
Avatar

Great, thanks. Implementing the IMergableTokenLexerData works for me.

Aernout

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.