Help with Custom Lexer Integration in Actipro SyntaxEditor

SyntaxEditor for WPF Forum

The latest build of this product (v24.1.5) was released 1 month ago, which was before this thread was created.
Posted 1 days ago by kisame actipro learner
Version: 24.1.5
Avatar

Hi, I'm pretty new to Actipro, and I'm currently evaluating SyntaxEditor as part of a feasibility test before my team considers subscribing.

Right now, I'm trying to achieve basic syntax highlighting (changing word colors) without using the Language Designer, since I need a high level of customization later on. I believe it's important to fully understand and control the creation of a custom lexer and language definition.

I've gone through the Sample Browser, but I found it a bit hard to follow. So I'm using ChatGPT to help me build a minimal working sample. Unfortunately, I’m stuck on this part of the code — it’s not working as expected:

 public class FaizLangLexer : MergableLexerBase
 {
     public ILexicalState InitialState => null;

     public  IToken ScanToken(ITextSnapshotReader reader, IMergableToken state)
     {
         string a = reader.PeekText(2);
         if (reader.IsAtSnapshotLineStart && reader.PeekText(2) == "//")
         {
             
             reader.ReadCharacterThrough('\n');
             return new TextSnapshotToken(FaizLangClassificationTypes.Comment, reader.TokenText);
         }

         reader.ReadCharacter(); // default: read single character
         return null;
     }
 }



If possible, could you provide a complete but minimal working sample of a custom lexer that supports syntax highlighting, just as a reference? That would help me a lot.

Thank you very much!

Best regards,

Comments (1)

Posted 15 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for evaluating SyntaxEditor.  Our SyntaxEditor Getting Started series of QuickStart samples has small examples of how to build a syntax language.  In particular, Getting Started 3c is about building a programmatic lexer similar to what you're trying to do. 

Even if you want to write a lexer by hand, which we do recommend for advanced languages, we still suggest using the Language Designer to code generate the token ID and lexical state ID classes for you since it will be a timesaver.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.