What is the difference between these lexers?

SyntaxEditor Web Languages Add-on for WPF Forum

Posted 13 years ago by Craig - Varigence, Inc.
Version: 11.1.0545
I'm creating a new SyntaxLanguage by extending the SyntaxLanguage class. In my constructor, I want to register a lexer. I want the Lexer to be the same Lexer that's used by the XmlSyntaxLanguage. When I register using:

RegisterService(new XmlSyntaxLanguage().GetLexer());
everything works as expected, such as syntax highlighting.

However, if I instead use:

var xmlClassificationTypeProvider = new XmlClassificationTypeProvider(AmbientHighlightingStyleRegistry.Instance);

var xmlLexer = new XmlLexer(xmlClassificationTypeProvider);
I don't get syntax highlighting. Can you explain why the former example works but the latter doesn't? What am I missing?



Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Craig,

When you call RegisterService and don't give it an explicit type argument you register the service with the service class' type name. In this case you are registering it as a XmlLexer service, not an ILexer service. So the language doesn't know it's there. Use our RegisterLexer extension method instead to keep things easy or do RegisterService<ILexer>(xmlLexer) instead.

Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.