IMergableToken.Lexer is null

SyntaxEditor for WPF Forum

Posted 8 years ago by Kasper Tanggaard
Version: 11.1.0545
Avatar
Hi guys,

I'm still very new to the way you have built the highlighters in SyntaxEditor for WPF, so bear with me here :). I have the following in my HTML highlighter, which should be the proper way to make the language transition to JScript:
<State Id="15" Key="JScriptStartTag" DefaultTokenId="33" DefaultTokenKey="JScriptStartTagDefault" DefaultClassificationTypeKey="TagName">
    <State.Scopes>
        <Scope>
            <Scope.StartPatternGroup>
                <ExplicitPatternGroup TokenId="5" TokenKey="StartTagStart" ClassificationTypeKey="TagDelimiter" Pattern="&lt;" LookAheadPattern="script" />
            </Scope.StartPatternGroup>
            <Scope.EndPatternGroup>
                <RegexPatternGroup TokenId="6" TokenKey="StartTagEnd" ClassificationTypeKey="TagDelimiter" Pattern="/? &gt;" />
            </Scope.EndPatternGroup>
            <Scope.Transition>
                <StateTransition>
                    <StateTransition.ChildLanguage>
                        <LanguageRef FilePath="C:\long path\JScript.langdef" />
                    </StateTransition.ChildLanguage>
                    <StateTransition.ChildScope>
                        <Scope>
                            <Scope.EndPatternGroup>
                                <ExplicitPatternGroup TokenKey="EndTagStartDelimiter" ClassificationTypeKey="TagDelimiter" Pattern="&lt;/" LookAheadPattern="script" />
                            </Scope.EndPatternGroup>
                        </Scope>
                    </StateTransition.ChildScope>
                </StateTransition>
            </Scope.Transition>
        </Scope>
    </State.Scopes>
    <State.ChildStates>
        <StateRef Key="StartTagAttribute" />
    </State.ChildStates>
</State>
This works just fine, but in trying to add outlining to my application, I'm experiencing a problem where, once a </script> tag is reached, the Lexer property of the IMergableToken is null, and even worse: When I try to test it for a null value, SyntaxEditor is apparently throwing a NullReferenceException:
System.NullReferenceException occurred
  Message=Object reference not set to an instance of an object.
  Source=ActiproSoftware.Text.Net351
  StackTrace:
       at s.get_Lexer()
       at ActiproSoftware.Text.Lexing.Implementation.MergableToken.get_Lexer()
       at TSW.WebCoder.Classes.Html.HtmlOutliningSource.GetNodeActionForToken(IToken token, IOutliningNodeDefinition& definition) in C:\long path\HtmlOutliningSource.cs:line 39
  InnerException: 
The Id property of the token has the exact same behavior. How do I avoid this? The token looks fine otherwise, with its key set to EndTagStartDelimiter and everything. Have I done something wrong? :)

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

That sounds like it's probably a bug. Can you make a simple sample project (as small as possible) that shows it happening so we can debug it? Then perhaps I can give you a workaround until we find a fix.

Please e-mail us the sample and rename the .zip file extension so it doesn't get spam blocked.

[Modified at 09/27/2011 03:04 PM]


Actipro Software Support

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

Thanks for the sample. We needed to add a null check nested in the token's Lexer property. But in addition, we fixed things for the next version so that this scenario shouldn't even occur and Lexer will always return a valid value, even in the language transition scope patterns.

In the meantime, I believe you can check the token's LexicalState property. If that is null, don't call the Lexer property since that is the scenario in which this can occur.


Actipro Software Support

Posted 8 years ago by Kasper Tanggaard
Avatar
>Thanks for the sample. We needed to add a null check nested in the token's Lexer property. But in addition, we fixed things for the next version so that this scenario shouldn't even occur and Lexer will always return a valid value, even in the language transition scope patterns.

Great :)

>In the meantime, I believe you can check the token's LexicalState property. If that is null, don't call the Lexer property since that is the scenario in which this can occur.

I actually checked for a workaround like that, before posting here, but couldn't find one that worked. Checking it now, I can see that this doesn't help - I've just gotten a NullReferenceException on the Lexer property, even though LexicalState is not null. So I guess I'm looking forward to the next release :)
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.