Highlighting and comments

SyntaxEditor for WPF Forum

Posted 15 years ago by Bradley
I'm probably doing something wrong but I can't figure out what (obviously). I'm trying to get highlighting working with my MGrammar, and it works as expected except for the comments. Here's my grammar for comments

                    token CommentDelimited = ""{*"" CommentDelimitedContent* ""*}"";  
                    token CommentDelimitedContent  
                           = ^('*')  
                          | '*'  ^('/');  
                    token CommentLine = ""//"" CommentLineContent*;  
                    token CommentLineContent  
                          = ^(  
                                '\u000A' // New Line  
                             |  '\u000D' // Carriage Return  
                             |  '\u0085' // Next Line  
                             |  '\u2028' // Line Separator  
                             |  '\u2029' // Paragraph Separator  

                    token tComment       = Common.CommentDelimited | Common.CommentLine;
Which was taken from a couple example grammars I found around the net, and is exactly what actipro uses in their example EXCEPT FOR the multiline comments in my language are defined as {* *} instead of /* */, which may be part of the problem.

My C# code to do the highlighting is this

            IHighlightingStyleRegistry registry = AmbientHighlightingStyleRegistry.Instance;
            registry.Register(ClassificationTypes.Identifier, new HighlightingStyle("Identifier", Brushes.Olive)); 
            registry.Register(ClassificationTypes.Keyword, new HighlightingStyle("Keyword", Brushes.Orange)); 
            registry.Register(new ClassificationType("Numeric"), new HighlightingStyle("Number", Brushes.Purple)); 
            registry.Register(new ClassificationType("Comment"), new HighlightingStyle("Comment", Brushes.Green));

            // Construct a SyntaxLanguage based on the DynamicParser and IHighlightingStyleRegistry
            SyntaxLanguage language = new SyntaxLanguage("Lang");
            language.LexicalParser = new DataflowLexicalParser(ezl.parser);
            language.ClassifierFactory = new DataflowClassifierFactory(ezl.parser, registry);

            // Assign the SyntaxLanguage to the SyntaxEditor's document
            this.TextEditor.Document.Language = language;
The issue is if I do somethign like this as my code

    Name t
    Description t


It'll color everything after the comment as green, the comment color. Anything placed before the comment will color correctly, i.e. the # 12 displays in purple. Thanks for any help you can provide.

changed my grammar to
token CommentDelimited = ""{"" ""*""* CommentDelimitedContent* ""*""* ""*}""; and it worked, though I think it should have worked before as Oslo properly detects it. BTW, the double quotes are because I'm loading the grammar as a string in my code not as an .mx file.

[Modified at 06/24/2009 01:05 PM]

Comments (1)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Your CommentDelimitedContent looks for a / instead of a }. Maybe that is the problem.

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.