How to read the PatternValue [in code] for a specific Pattern group in a Dynamic language fi

SyntaxEditor for Windows Forms Forum

Posted 11 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Version: 12.1.0303
Avatar

My app works with many different SQL dialects.

I define a separate Dynamic language file for each one.

My app needs to know what characters were defined for the Begin/End quotes around a quoted name.
For example, SQL Server uses [name] while Oracle uses "name".

In the example below I need to read the PatternValues specified for the TokenKey="StartQName" and TokenKey="EndQName"

<!-- Quoted Names -->
<State Key="QNameState" TokenKey="QNames" Style="NameStyle">
<!-- Scopes -->
<Scopes>
<Scope BracketHighlight="True">
<ExplicitPatternGroup Type="StartScope" TokenID="30" TokenKey="StartQName" PatternValue="&quot;" />
<ExplicitPatternGroup Type="EndScope" TokenID="31" TokenKey="EndQName" PatternValue="&quot;" />
</Scope>
</Scopes>
<!-- Patterns Groups -->
<PatternGroups>
<ExplicitPatternGroup TokenKey="QNameEscaped" PatternValue="&quot;&quot;" />
<RegexPatternGroup TokenKey="QNameDefault" PatternValue="[^\&quot;]+" />
</PatternGroups>
</State> 

Looking at the methods available in the DynamicOutliningSyntaxLanguage class I thought I needed to use the GetTokenString(ID) function, but when I use that function it always returns Null.

How do I read a PatternValue from the language class?

Thanks
Mike

Comments (3)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

You can look at the DefaultLexicalState (if they are in that) or the LexicalStates collection.  Each of those will be a DynamicLexicalState.  Then that has a LexicalPatternGroups collection on it.  You can find your pattern group and examine it.


Actipro Software Support

Posted 11 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Avatar

The above answer would be correct if I were trying to read the PatternValue from a pattern group but the real question here was how to get the Start/End tokens that define a child state.

So for anyone who needs to do that the answer is to use the following:

  Dim st As DynamicLexicalState = myLanguage.LexicalStates("QNameState")
  Dim sc As DynamicLexicalScope = st.LexicalScopes(0)
  Dim startName As String = sc.StartLexicalPatternGroup(0).Pattern
  Dim endName As String = sc.EndLexicalPatternGroup(0).Pattern

Note that you must either use intermediate variables or cast the function return values since the functions return LexicalState and LexicalScope rather than DynamicLexicalState and DynamicLexicalScope.

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Whoops, I apologize and was looking at the wrong pattern groups in your sample.  You are exactly right, for the others you'd go through the scopes.


Actipro Software Support

The latest build of this product (v24.1.0) 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.