loading SyntaxLanguage and bracket hightlighting bug

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Joris Koster - Paragon Decision Technology
Avatar
Hi,

I think I found a bug in loading the SyntaxLanguage object from an encoded XML stream.

Consider the following relevant language spec:

<SyntaxLanguage Key="BracketHLTest" LanguageDefinitionVersion="3.0" Secure="True"
                xmlns="http://ActiproSoftware/SyntaxEditor/3.0/LanguageDefinition">
    <!-- States -->
    <States>
        <!-- Code -->
        <State Key="DefaultState">
            <Scopes>
                <Scope BracketHighlight="True">
                    <ExplicitPatternGroup Type="StartScope" TokenKey="BracketStartToken" PatternValue="(" />
                    <ExplicitPatternGroup Type="EndScope" TokenKey="BracketEndToken" PatternValue=")" />
                </Scope>
            </Scopes>
            <ChildStates>
                <ChildState Key="DefaultState" />
            </ChildStates>
        </State>
    </States>        
</SyntaxLanguage>
when loading this language from a file- or memorystream, the bracket-highligting will fail if (and only if) the stream is encoded. When loading using a filename there seems to be no problem.


Small example code to demonstrate the problem; syntaxEditor1 and 2 both have the BracketHighlightingVisible property set to true, but nevertheless syntaxEditor2 will not show the brackethighlighting.

private void Form1_Load(object sender, System.EventArgs e)
{

    System.Int32 encodeKey            = 1234;
    System.String plainFilename        = "../../test.xml";
    System.String encodedFilename    = "../../test.enc";

    // create an encoded xml file
    ActiproSoftware.SyntaxEditor.SyntaxLanguage thePlainLanguage =
        ActiproSoftware.SyntaxEditor.SyntaxLanguage.LoadFromXml( plainFilename, 0 );
    thePlainLanguage.SaveToXml(encodedFilename, encodeKey);


    // open the plain text stream
    System.IO.FileStream streamPlain = 
        new System.IO.FileStream(plainFilename, 
            System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);

    // load the language from the plain text stream
    ActiproSoftware.SyntaxEditor.SyntaxLanguage languagePlain = 
        ActiproSoftware.SyntaxEditor.SyntaxLanguage.LoadFromXml(
        streamPlain, 0);

    // set the syntax-language for the first editor
    syntaxEditor1.Document.Language = languagePlain;

    // open the encoded text stream
    System.IO.FileStream streamEncoded = 
        new System.IO.FileStream(encodedFilename, 
            System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);

    // load the language from the encoded text stream
    ActiproSoftware.SyntaxEditor.SyntaxLanguage languageEncoded = 
        ActiproSoftware.SyntaxEditor.SyntaxLanguage.LoadFromXml(
        streamEncoded, encodeKey);

    // set the syntax-language for the second editor
    syntaxEditor2.Document.Language = languageEncoded;
}
I'm not sure if the problem is in my language-spec, but nevertheless I would expect both cases to be correct xor incorrect.

Comments (2)

Posted 13 years ago by Joris Koster - Paragon Decision Technology
Avatar
By toggling the "Secure" property to false, setting the "encodeKey" to 0, and examining the "test.enc" file, I found out that the "BracketHighlight" property of the "Scope" tag isn't serialized: (amongst other things) the generated key=0 XML file contains:

<!-- Scopes -->
<Scopes>
    <Scope>
        <ExplicitPatternGroup Type="StartScope" TokenKey="BracketStartToken" PatternValue="(" EndBracket="" />
        <ExplicitPatternGroup Type="EndScope" TokenKey="BracketEndToken" PatternValue=")" StartBracket="" />
    </Scope>
</Scopes>
in stead of the original:

<Scopes>
    <Scope BracketHighlight="True">
        <ExplicitPatternGroup Type="StartScope" TokenKey="BracketStartToken" PatternValue="(" />
        <ExplicitPatternGroup Type="EndScope" TokenKey="BracketEndToken" PatternValue=")" />
    </Scope>
</Scopes>
Maybe it is possible to achieve the same effect (nesting depth increase and highlighting) by defining the language differently... and thus circumventing this serialization/encoding problem. Any tips/bugfixes/workarounds?

thanks,
Joris
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, I am working on it now and found the same thing. It's a bug that will be fixed for the next maintenance release.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.