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
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 thisThe issue is if I do somethign like this as my code
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.
Edit:
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]
@{Classification[""Comment""]}
token CommentDelimited = ""{*"" CommentDelimitedContent* ""*}"";
@{Classification[""Comment""]}
token CommentDelimitedContent
= ^('*')
| '*' ^('/');
@{Classification[""Comment""]}
token CommentLine = ""//"" CommentLineContent*;
@{Classification[""Comment""]}
token CommentLineContent
= ^(
'\u000A' // New Line
| '\u000D' // Carriage Return
| '\u0085' // Next Line
| '\u2028' // Line Separator
| '\u2029' // Paragraph Separator
);
@{Classification[""Comment""]}
token tComment = Common.CommentDelimited | Common.CommentLine;
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;
{************************
Name t
Description t
************************}
asdfasdf
adsf
adsf
afd
Edit:
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]