NullReferenceException if using $ pattern

SyntaxEditor for Windows Forms Forum

Posted 20 years ago by Steven Liu
Avatar
Trying to create syntax definition file for this:

SECTION s1
a=1
!comment
SECTION s2
b=1
I created 2 states: SectionState and CommentState.
Since SectionState has no closing keyword, it needs to look ahead to the next SECTION keyword to terminate current scope:
PatternValue="\n" LookAhead="[ \n]*SECTION"
There's still a problem: the "!comment" line consumes "\n", so "SECTION s2" is not recognized. To fix this, I changed the EndScope pattern of CommentState from "\n" to "$", so the "\n" is left over to end the SECTION scope.
(Complete syntax definition is attached at the end).

This solution appears OK, but I encountered a NullReferenceException when I do this:
position cursor at the end of "!comment" line, press backspace key 3 times to delete character "t", "n", "e", then re-type "e","n","t".

Would you please take a look? Thanks a lot.

Steven Liu

<SyntaxLanguage Key="TEST" LanguageDefinitionVersion="2.0" Secure="True" xmlns="http://ActiproSoftware/SyntaxEditor/2.0/LanguageDefinition">

    <!-- Highlighting Styles -->    
    <Styles>
        <Style Key="SectionWordStyle" ForeColor="Blue" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="CommentDelimiterStyle" ForeColor="Green" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="CommentDefaultStyle" ForeColor="Green" BackColor="Default" Bold="False" Italic="False" Underline="False" />
    </Styles>
    
    <!-- States -->
    <States> 
        <!-- Code -->
        <State Key="DefaultState"> 
            <!-- Child States -->
            <ChildStates>
                <ChildState Key="SectionState" />
                <ChildState Key="CommentState" />
            </ChildStates>
        </State>
        
        <State Key="SectionState" >
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" Token="SectionStartToken" Style="SectionWordStyle" PatternValue="SECTION" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect" />
                    <RegexPatternGroup Type="EndScope" Token="SectionEndToken" Style="DefaultStyle" PatternValue="\n" LookAhead="[ \n]*SECTION" CaseSensitivity="Insensitive" IsContentDivider="True" />
                </Scope>
            </Scopes>
            <ChildStates>
                <ChildState Key="CommentState" />
            </ChildStates>
        </State>
      
        <State Key="CommentState" Token="CommentDefaultToken" Style="CommentDefaultStyle">
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" Token="CommentStartToken" Style="CommentDelimiterStyle" PatternValue="!" />
                    <RegexPatternGroup Type="EndScope" Token="CommentEndToken" Style="CommentDelimiterStyle" PatternValue="$" />
                </Scope>
            </Scopes>
        </State>
    </States>
    
</SyntaxLanguage>

Comments (2)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
This was caused by a bug in the lexical parser that didn't like zero-width assertion-only patterns. It has been fixed for the next release.


Actipro Software Support

Posted 20 years ago by Steven Liu
Avatar
That's great. I am impressed by your prompt support. Thank you!
Steven
The latest build of this product (v24.1.1) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.