SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

AvalonEdit: Complex syntax highlighting file

Last post 12-10-2009 8:12 PM by FBSC97. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-07-2009 6:46 PM

    • FBSC97
    • Not Ranked
    • Joined on 12-07-2009
    • Posts 4

    AvalonEdit: Complex syntax highlighting file

    First of all, hi :D

    I need to create a syntax highlighting file for a html syntax wich includes c#... in facts it is like

    <html>

    <csharp_method>

    private void DoSomething() {

    }

    </csharp_method>

    <!-- ... -->

    </html>

     

    But i don't know how to define a syntax that resides into another syntax... Can anyone help me?

  • 12-08-2009 1:12 AM In reply to

    Re: AvalonEdit: Complex syntax highlighting file

    Take a look at SharpDevelop\src\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\Highlighting\Resources\CSharp-Mode.xshd - it is importing the definition of XmlDoc literals (e.g. /// <summary>) from XmlDoc.xshd.

    Basically, in both color and ruleset references, you can use the syntax "DefinitionName/RuleSetName" to reference a ruleset from another syntax highlighting definition. The empty string is referring to the root ruleset.

    So, for referencing the root ruleset of the C# highlighting, use:

            <Span ruleSet="C#/">
                <Begin>&lt;csharp_method&gt;</Begin>
                <End>&lt;/csharp_method&gt;</End>
            </Span>

  • 12-08-2009 7:17 PM In reply to

    • FBSC97
    • Not Ranked
    • Joined on 12-07-2009
    • Posts 4

    Re: AvalonEdit: Complex syntax highlighting file

    Hi Daniel,

    I have copied the html file and under the scripts&co spans I have added

    <Span color="DarkRed" name="csharp_method_tag">
       <Begin>&lt;csharp_method&gt;</Begin>
       <End>&lt;/csharp_method&gt;</End>
       <RuleSet>
          <Import ruleSet="C#/"/>
       </RuleSet>
    </Span>

    But it throws an exception at runtime:

    "The element 'Span' has an invalid child 'RuleSet'"

    I don't know how to solve this...

    Thanks for your help.

       Francesco

     

  • 12-09-2009 12:40 AM In reply to

    Re: AvalonEdit: Complex syntax highlighting file

    There are two .xshd file formats (old format from ICSharpCode.TextEditor; and new format for ICSharpCode.AvalonEdit), you seem to be mixing them up.

    You should convert the whole file to the new format so that you can use all features of the AvalonEdit highlighting engine. In the new file format, the root element must use the XML namespace 'http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008'. If your root element doesn't have that, your file will get loaded by an importer in AvalonEdit that is there for compatibility with old syntax definitions.

    Please read the syntax highlighting section in my code project article, and check CSharp-Mode.xshd as an example. Other .xshds coming with AvalonEdit are still using the old file format.

    Note that the importer in AvalonEdit can perform most of the conversion work for you:

        XshdSyntaxDefinition xshd;
        using (XmlTextReader reader = new XmlTextReader("input.xshd")) {
            xshd = HighlightingLoader.LoadXshd(reader);
        }
        using (XmlTextWriter writer = new XmlTextWriter("output.xshd", System.Text.Encoding.UTF8)) {
            writer.Formatting = Formatting.Indented;
            new SaveXshdVisitor(writer).WriteDefinition(xshd);
        }

  • 12-10-2009 1:28 PM In reply to

    • FBSC97
    • Not Ranked
    • Joined on 12-07-2009
    • Posts 4

    Re: AvalonEdit: Complex syntax highlighting file

    Oh, so I have to translate the HTML declaration into new format... Ok, i'll try it :D

  • 12-10-2009 8:12 PM In reply to

    • FBSC97
    • Not Ranked
    • Joined on 12-07-2009
    • Posts 4

    Re: AvalonEdit: Complex syntax highlighting file

    Thanks a lot! It works perfectly!!

    (I suggest to you to translate all the files into correct version in next release)

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.