Custom SQL Syntax Question

SyntaxEditor for WPF Forum

Posted 15 years ago by David Mullin
Version: 9.1.0503
Avatar
In our application, we support SQL that contains custom macros of the form "[[token]]" I'm attempting to use the SyntaxEditor for this, but am encountering some issues (almost certainly because I don't know what I'm doing :->).

First, I've tried to modify the SQL Language definition XML so that [[token]] is colored a certain way. I removed the Squery String group tag, since that would be a clear conflict, and added my new thing to the ChildStates key. The XML I've put in is:

<!-- Ask Tokens -->
<State Key="SystemMacroState" TokenKey="SystemMacroToken" Style="SystemVariableStyle">
  <!-- Scopes -->
  <Scopes>
    <Scope BracketHighlight="True">
      <RegexPatternGroup Type="StartScope" TokenKey="SystemMacroStartToken" Style="SystemVariableStyle" PatternValue="[[" />
      <RegexPatternGroup Type="EndScope" TokenKey="SystemMacroEndToken" Style="SystemVariableStyle" PatternValue="]]" />
    </Scope>
  </Scopes>
  <!-- Patterns Groups -->
  <PatternGroups>
    <RegexPatternGroup TokenKey="SystemMacroToken" PatternValue="{NonLineTerminatorMacro}+" />
  </PatternGroups>
</State>
My understanding is that this should look for things that start with "[[" and end with "]]" and style it after the SystemVariableState style (i.e., green and bold). However, this doesn't happen at all. I figure that there is something that I'm just not getting, but I don't see what.

Also, I created a SyntaxLanguage class to service this, and implemented the IEditorDocumentTextChangeEventSink interface (just like the HtmlDynamicSyntaxLanguage example). I'm trying to trap when the user types "[[", but e.TypedText always only contains a single character. How do I trap that the user has typed two "[" in a row?

Thanks in advance.

David Mullin

Comments (5)

Posted 15 years ago by David Mullin
Avatar
I don't know if this makes any sense, but I change my XML a little and (apparently more significantly) moved it up above the CommentState block, and it started working. My new XML is:

    <!-- Ask Tokens -->
    <State Key="SystemMacroState" TokenKey="SystemMacroToken" Style="SystemVariableStyle">
      <!-- Scopes -->
      <Scopes>
        <Scope BracketHighlight="True">
          <RegexPatternGroup Type="StartScope" TokenKey="SystemMacroStartToken" Style="SystemVariableStyle" PatternValue="\[\[" />
          <RegexPatternGroup Type="EndScope" TokenKey="SystemMacroEndToken" Style="SystemVariableStyle" PatternValue="\]\]" />
        </Scope>
      </Scopes>
      <!-- Patterns Groups -->
      <PatternGroups>
        <RegexPatternGroup TokenKey="SystemMacroToken" PatternValue="[^\]]+" />
      </PatternGroups>
    </State>
Posted 15 years ago by David Mullin
Avatar
One other thing, the SystemVariableStyle says to make the text bold, and yet the text is not being bold. What am I missing?

Also, under what circumstances would the horizontal scroll bar not be visible? I have set WordWrapMode to "None", and my text clearly runs off the right side of the screen, but I don't have a horizontal scroll bar. I expect that it is something bizarre in the way that I'm consuming the control, but what could it be?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

One thing I noticed is that you are using RegexPatternGroups but you aren't escaping the [ characters in the scope patterns. I would change those to be ExplicitPatternGroups instead to be sure everything is parsed correctly.

It looks like our temporary dynamic XML definition deserialization code wasn't loading the bold/italic settings. We'll fix that for the next release, although please note we're currently working on and updated XML format to use with the WPF version. We hope to get the new format out in the next build or two. We'll have a converter in the Language Designer that will take the SE4 format and convert it to the new one for you.

The horizontal scrollbar should be showing up. I'd make sure you don't have something in front of it accidentally that is blocking it from view. If you still think there is a bug on our end, please make a simple sample project that shows the issue and email it over. Thanks!


Actipro Software Support

Posted 15 years ago by David Mullin
Avatar
Thanks for the information. My changes to the Language Definition are pretty small, so I have no problem replicating them in your new Definition file (I'm just taking the SQL definition that you give in the Sample application).

You didn't say anything about handling NotifyDocumentTextChanges to cope with detecting "[[" (since e.TypedText always only contains a single character). Can you point me to a resource to figure out how to do that more intelligently?

On a related topic, I'd like the intellisence popup to always contain the complete text of the macro, rather than just the part after what the user has types (right now, if I hit CTRL+SPACE, the list looks on way, but if I trap "[", the list looks a different way, and if I make the list look the same, then what I end up with is [[[macro]] rather than [[macro]]). I'm sure there is something that I'm just not understanding...

I figured out the scrollbar thing. In my application, I have a custom ScrollBar Template for vertical scrollbars, and override the default style for ScrollBar as:

<Style TargetType="{x:Type ScrollBar}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Style.Triggers>
        <Trigger Property="Orientation" Value="Vertical">
            <Setter Property="Width" Value="18"/>
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Template" Value="{DynamicResource VerticalScrollBar}" />
        </Trigger>
    </Style.Triggers>
</Style>
If I change it to this:

<Style TargetType="{x:Type ScrollBar}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Style.Triggers>
        <Trigger Property="Orientation" Value="Vertical">
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Width" Value="18"/>
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Template" Value="{DynamicResource VerticalScrollBar}" />
        </Trigger>
    </Style.Triggers>
</Style>
everything works - which makes sense. I hadn't encountered this in other places in my application (i.e., I hadn't seen a place where a Horizontal ScrollBar wasn't working), but maybe those places are not using custom style. Anyway, it was my problem, so never mind :-).
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry missed the NotifyDocumentTextChanged question. e.TypedText will always contain a single character (unless IME allows multiple characters to be typed at once for some foreign languages). You'd be best off looking for a single "[" and if found, look in the snapshot at the character before where that is inserted to see if it is also a '['. If so, you know there were two in a row.

CompletionSession.Open has an overload that lets you specify a TextRange with which to initialize it. If you do that then you can have it replace existing text including the '['.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.