Zero width assertion in PatternValue

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Steven Liu
Avatar
Hi,
I try to use zero-width assertion in comment state EndScope pattern:

<Scope>
  <ExplicitPatternGroup Type="StartScope" TokenKey="CommentStartToken" Style="CommentDelimiterStyle" PatternValue="!" />
  <RegexPatternGroup Type="EndScope" TokenKey="CommentEndToken" Style="CommentDelimiterStyle" PatternValue="$" />
</Scope>
This does not seems to work. SyntaxEditor finds a StartScope match but cannot find a EndScope match, so everything after the first comment char "!" is marked as comments.

The reason I use "$" instead of "\n" for EndScope pattern is that I don't want to consume "\n".

Please help. Thanks.

Steven

Comments (6)

Posted 13 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
How about...

<Styles>
  <Style Key="CommentStyle" ForeColor="Green" BackColor="Default" Bold="False" Italic="False" Underline="False" />
</Styles>
<States>
  <State Key="DefaultState">
    <!-- Comment -->
    <RegexPatternGroup Key="Comment" TokenKey="CommentToken" Style="CommentStyle" PatternValue="! {NonLineTerminatorMacro}*" LookAhead="{LineTerminatorMacro}" />
  </State>
</States>
Hope that helps,

Jason
Posted 13 years ago by Steven Liu
Avatar
That is clever. It would work, but there is no comment state anymore. That cause 2 issues:
1. I have to define that token in every state. This I can probably live with.
2. My app currently displays IntelliPrompt based on state. which means it will display the Intellipromt in comment line too. what is the right way to avoid that?
Thanks,
Steven
Posted 13 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
This would work. The only caveat to this solution is that the comment must have at least one character after the !

<State Key="CommentState" Style="CommentStyle">
  <Scopes>
    <Scope>
      <ExplicitPatternGroup Type="StartScope" TokenKey="CommentStartToken" PatternValue="!" />
      <RegexPatternGroup Type="EndScope" TokenKey="CommentEndToken" PatternValue="{NonLineTerminatorMacro}" LookAhead="{LineTerminatorMacro}" />
    </Scope>
  </Scopes>
</State>
Hope that helps,

Jason
Posted 13 years ago by Steven Liu
Avatar
I have tried this already, however sometimes users do use a comment line with "!" char only. don't know why but they do that. if that happens, SyntaxEditor cannot find CommentEndToken at the same line because there's no char left, as a result it will treat the next line as comment.
I appreciate your feedback. thanks.
Steven
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Steven,

Just reading this now. Jason suggested both things I would as well. As you pointed out, his state suggestion works except for the case where there is no character after !. This of course is because each pattern must match at least one character. Therefore the pattern-based (and not state-based) is the best way to go in this situation if you don't want to track the line feed.

A little technical background... SyntaxEditor has to match at least one character when looking at scopes. This ensures that a pattern is assigned to the text that was scanned and if incremental parsing picks up at that point, it can rebuild the state it was at. If we allows zero-width assertions for pattern matches, a parsing operation would probably work however recreating the state/scope stack for a future incremental parse at that location would be flawed.


Actipro Software Support

Posted 13 years ago by Steven Liu
Avatar
OK. I'll use the pattern based solution, then write code not to show IntelliPrompt member list if cursor is in CommentToken.
Thanks to support and Jason.
Steven
The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.