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

SyntaxEditor for Windows Forms Forum

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

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 -->
<Scope BracketHighlight="True">
<ExplicitPatternGroup Type="StartScope" TokenID="30" TokenKey="StartQName" PatternValue="&quot;" />
<ExplicitPatternGroup Type="EndScope" TokenID="31" TokenKey="EndQName" PatternValue="&quot;" />
<!-- Patterns Groups -->
<ExplicitPatternGroup TokenKey="QNameEscaped" PatternValue="&quot;&quot;" />
<RegexPatternGroup TokenKey="QNameDefault" PatternValue="[^\&quot;]+" />

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?


Comments (3)

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

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 9 years ago by Michael Dempsey - Sr. Developer, Teradata Corp

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 9 years ago by Actipro Software Support - Cleveland, OH, USA

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 (v22.1.0) 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.