What is the difference between these lexers?

SyntaxEditor Web Languages Add-on for WPF Forum

Posted 8 years ago by Craig - Varigence, Inc.
Version: 11.1.0545
Avatar
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);
xmlClassificationTypeProvider.RegisterAll();

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

Thanks,

-Craig

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 (v2019.1 build 0682) was released 3 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.