Question

I'm working on highlighting a small scripting language (that is not a derivative of any of the built in's) and I had a custom XML file setup for different syntax keywords and such.

I would really like to use the XSHD system that exists in AvalonEdit for loading custom keywords, but I need to have custom attributes in them.

So basically, after a lot of searching through the source code, I could not really pin-point the file that reads and specifies the keywords and rulesets.

Does anyone here know where I can edit the needed class to read some custom attributes and storing them?

I have all the XSHD and higlighting stuff in AvalonEdit down and working, so it's not using it that is the problem, per say, it's more the problem of using custom attributes in the keywords collection of the XSHD file.

In example:

<Keywords>
   <Word defaultValue="hello" requiresShader="shadertype1, shadertype2" someCustomAttr="value">wordname</word>
</Keyword>

So, I need to set some custom properties to the parser of the XSHD file to load these custom attributes and store them in a custom class I have made that handles a few logical components that are crucial to what I'm trying to do.

I already have a working parser that parses a XML file of all my keywords and their properties (but I wrote it to ScintillaNET, but found AvalonEdit afterwards, that works better with WPF and such).

I will edit the original post with this information, sorry about possible misinformation.

Thank you

Était-ce utile?

La solution

To load an XSHD file, you need to import the following libraries:

using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;    

And then wherever you create the text editor (omit the first line and just reference the TextEditor if you create it in XAML), use the following code to load def.xshd.

// TextEditor is an AvalonEdit.TextEditor
TextEditor edit = new TextEditor();
XmlReader reader = XmlReader.Create("def.xshd");
edit.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);

A good sample xshd file that I am using for a language in the works is this:

<SyntaxDefinition name="XAPL"
    xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" />
<Color name="String" foreground="Pink" />
<Color name="Xml" foreground="Orange" />
<!-- This is the main ruleset. -->
<RuleSet>
    <Span color="Comment" begin="//" />
    <Span color="Comment" multiline="true" 
       begin="/\*" end="\*/" />


    <Span color="String">
        <Begin>"</Begin>
        <End>"</End>
        <RuleSet>
            <!-- nested span for escape sequences -->
            <Span begin="\\" end="." />
        </RuleSet>
    </Span>

  <Span color="Xml" multiline="false">
    <Begin>spaz</Begin>
    <End>spaz</End>
  </Span>


    <Keywords fontWeight="bold" foreground="Blue">
        <Word>dealwith</Word>
        <Word>import</Word>
        <Word>end</Word>
        <Word>var</Word>
        <Word>default</Word>
        <Word>template</Word>
        <Word>sub</Word>
        <Word>category</Word>
        <Word>if</Word>
        <Word>otherwise</Word>
        <Word>and</Word>
        <Word>xor</Word>
        <Word>string</Word>
        <Word>int</Word>
        <Word>convert</Word>
        <Word>to</Word>
        <Word>escape</Word>
        <Word>native</Word>
        <Word>loop</Word>
        <Word>is</Word>
        <Word>to</Word>
        <Word>from</Word>
        <Word>by</Word>
    </Keywords>

    <!-- Digits -->
    <Rule foreground="DarkGray">
        \b0[xX][0-9a-fA-F]+  # hex number
    |    \b
        (    \d+(\.[0-9]+)?   #number with optional floating point
        |    \.[0-9]+         #or just starting with floating point
        )
        ([eE][+-]?[0-9]+)? # optional exponent
    </Rule>
</RuleSet>
</SyntaxDefinition>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top