Hi there,
I'm getting started with the WPF syntax editor for a simple custom language we use. I've created a class inheriting from SyntaxParser and overridden the Outline method so it does region outlining for our language keywords - this works fine.
However the TextEditor is not applying any highlighting to the script. Right now I'm just loading the c#.xml scheme file that came with your demos, and my plan is to just copy it and edit it down to what I need. However when I type "class" or any other C# keyword it fails to highlight in the editor.
So, I am either missing something in my config, or in my parser implementation. My hope was to just use a custom parser for the region outlining and an xml file for the keywords and basic syntax highlighting.
What am I missing?
Here is my code below (I'm excluding the Outline implementation for brevity, as I assume that doesn't affect this)
public XParser()
{
Options = SyntaxOptions.Outline;
var fileInfo = new FileInfo(@"C:\..path to..\c#.xml");
if (fileInfo.Exists)
this.Scheme.LoadFile(fileInfo.FullName);
}
And in my main method:
public MainWindow()
{
InitializeComponent();
Parser parser1 = new XParser();
var sb = new StringBuilder();
sb.AppendLine("#for x in y");
sb.AppendLine("");
sb.AppendLine("#endfor");
TextSource textSource2 = new TextSource();
textSource2.Lexer = parser1;
textSource2.Text = sb.ToString();
edit.Source = textSource2;
edit.AllowOutlining = true;
edit.AllowDrop = true;
edit.Outlining.OutlineOptions = OutlineOptions.DrawLines | OutlineOptions.DrawButtons;
edit.LineNumbersVisible = true;
}
Thanks,
Luke.
Hi,
For the parsers derived from SyntaxParser you will need to set UseScheme property to true to use syntax scheme:
public XParser()
{
UseScheme = true;
...
}
Otherwise you will need to implement lexical analysis manually, which gives better performance comparing to one based on syntax scheme, but requires some work - we can send you an example how this can be done if needed.
Hope this helps.
regards,
Andrew
For the parsers derived from SyntaxParser you will need to set UseScheme property to true to use syntax scheme:
public XParser()
{
UseScheme = true;
...
}
Otherwise you will need to implement lexical analysis manually, which gives better performance comparing to one based on syntax scheme, but requires some work - we can send you an example how this can be done if needed.
Hope this helps.
regards,
Andrew
Thanks Andrew! That solved it.