StateTransition to child language

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Joachim Schwieren
Version: 4.0.0283
Avatar
Hi,

in online help you show how to do a language state transition from HTML to CSS when the "<style>" tag is matched in a HTML document.

But CSS can also be used as "inline" code, e.g. <body style="background-color:red;">

In order to make the language transition, I defined a new state in the HTML language definition:

    <!-- Start Tag Attribute String Inline CSS Values -->
    <State Key="StartTagAttributeInlineStyleValueState" TokenKey="StartTagAttributeStringValueDefaultToken">
      <!-- Scopes -->
      <Scopes>
        <Scope>
          <RegexPatternGroup LookBehind="style" Type="StartScope" TokenKey="StartTagAttributeStringValueStartToken" Style="TagAttributeValueStyle" PatternValue="= {LineTerminatorWhitespaceMacro}* \&quot;" />
          <RegexPatternGroup Type="EndScope" TokenKey="StartTagAttributeStringValueEndToken" Style="TagAttributeValueStyle" PatternValue="\&quot;" />
          <StateTransition Filename="CSS.xml" ChildLanguageBackColor="WhiteSmoke">
            <ExplicitPatternGroup TokenKey="StartTagAttributeStringValueEndToken" Style="TagAttributeValueStyle" PatternValue="&quot;" />
          </StateTransition>
        </Scope>
      </Scopes>
    </State>
However this does not work as expected. Also the problem is that DefaultState of the CSS language is not the right one here. But defining the state="ValueState" (which is my state for the CSS code within the { }) for the StateTransition - I get an error saying:

"When a child language is specified for a scope state transition, the language's state key must be 'DefaultState'."; but according to the online help, this should work!)

Any idea how I can get this working?

Regards,

Joe

Comments (6)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joe,

Right now the code does require that DefaultState be used when doing a transition there. What you can do is clone the CSS language definition and take out the parts that deal with selectors so that your default state in that goes directly to property specifications. Then merge that in how you were doing in your sample code.


Actipro Software Support

Posted 14 years ago by Joachim Schwieren
Avatar
Hi,

I tried to do it the way you proposed, but it does not work as expected. Here is an excerpt from my "HTML" language definition. Again: I want to make any style="..." code in the HTML code to transition to my Inline.CSS.xml language that is able to highlight CSS code like "color:#ff00ff;padding:5px;" in the default state:

 <!-- Start Tag Attributes -->
    <State Key="StartTagAttributeState" TokenKey="StartTagDefaultToken" Style="TagAttributeStyle">
      <!-- Scopes -->
      <Scopes>
        <Scope>
          <RegexPatternGroup Type="StartScope" TokenID="1" TokenKey="StartTagNameToken" Style="TagNameStyle" PatternValue="{LineTerminatorWhitespaceMacro}* {TagNameMacro}+ {LineTerminatorWhitespaceMacro}*" />
        </Scope>
      </Scopes>
      <!-- Patterns Groups -->
      <PatternGroups>
        <!-- Brackets -->
        <RegexPatternGroup TokenKey="StartTagAttributeToken" Style="TagAttributeStyle" LookAhead="{NonWordMacro}|\z" PatternValue="{WordMacro}+" />
      </PatternGroups>
      <!-- Child States -->
      <ChildStates>
        <ChildState Key="CssInlineCode" />
        <ChildState Key="StartTagAttributeStringValueState" />
        <ChildState Key="StartTagAttributeValueState" />
      </ChildStates>
    </State>

    <!-- Start Tag Attribute String Inline CSS Values -->
    <State Key="CssInlineCode" TokenKey="CssInlineCode">
      <Scopes>
        <Scope>
          <RegexPatternGroup LookBehind="style" Type="StartScope" TokenKey="StartTagAttributeInlineStyleValueStartToken" Style="TagAttributeValueStyle" PatternValue="= {LineTerminatorWhitespaceMacro}* \&quot;" />
          <RegexPatternGroup Type="EndScope" TokenKey="StartTagAttributeInlineStyleValueEndToken" Style="TagAttributeValueStyle" PatternValue="\&quot;" />

          <StateTransition Filename="Inline.CSS.xml" ChildLanguageBackColor="WhiteSmoke">
            <ExplicitPatternGroup TokenKey="StartTagAttributeInlineStyleValueEndToken" Style="TagAttributeValueStyle" PatternValue="&quot;" />
          </StateTransition>

        </Scope>
      </Scopes>
    </State>
    
    <!-- Start Tag Attribute Values -->
    <State Key="StartTagAttributeValueState" TokenKey="StartTagAttributeValueDefaultToken" Style="TagAttributeValueStyle">
      <!-- Scopes -->
      <Scopes>
        <Scope>
          <RegexPatternGroup Type="StartScope" TokenKey="StartTagAttributeValueStartToken" Style="TagAttributeValueStyle" PatternValue="= {LineTerminatorWhitespaceMacro}*" />
          <RegexPatternGroup Type="EndScope" TokenKey="StartTagAttributeValueEndToken" Style="TagAttributeValueStyle" PatternValue="{LineTerminatorWhitespaceMacro}+" />
        </Scope>
      </Scopes>
      <!-- Patterns Groups -->
      <PatternGroups>
        <RegexPatternGroup TokenKey="StartTagAttributeValueDefaultToken" PatternValue="{WordMacro}+" />
      </PatternGroups>
    </State>
StartTagAttributeState defines the attribute state of HTML tags and CssInlineCode matches on style="..." attributes (StartTagAttributeValueState is for normal attribute values). If I remove the StateTransition and apply a style to CssInlineCode, the text between "..." in the style= attribute gets the appropriate color, so the matching is correct so far. But when I apply the StateTransition to the Inline.CSS.xml, it does not highlight the text between style="...". Even more strange: If I press return several times the highlighting suddenly appears but only starting in the next line; here is a code sample that might help to understand the problem:

<body style="color:red;

padding:12px;">
Only padding:12px; and the blank line above get the CSS highlighting, but not the color:red; part in the first line. Also the highlighting seems to be very instable; when I delete text, the whole CSS highlighting is lost.

Any ideas what might be wrong here?

Thanks for your help,

Regards,

Joe
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joe,

It's hard to tell without debugging with the full definition. However at a glance what you have does look correct.

What I would recommend is to load your language definition into the SDI Editor sample. As you move around, the status bar will tell you what token is under the caret. So by going to the problem area with your code sample loaded in the SDI Editor, you can see which pattern groups are being used for the tokens. Then you can use that info to debug and figure out where things are going wrong in your language definition.

Try that out and if you get completely stuck, email us the full dynamic language files so that we can load them in our SDI Editor sample.


Actipro Software Support

Posted 14 years ago by Joachim Schwieren
Avatar
Hi,

I tried as suggested but it does not work; inside the style="..." the text is in the correct state as defined in the HTML language defintion; when I press enter several times to insert new lines, suddenly the language transition is applied but not to the first line.

I e-mailed you the two language files. Maybe you can help. I can't find the reason for this problem.

Regards,

Joe
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

I see now, there are two language transition types. You were doing a Scope Lexical State Transition (with the StateTransition tag), but what you really wanted to do was a Direct Lexical State Transition, more like how ASP <% %> delimiters do. Although in this case your delimiters are quotes.

This revised code seems to work:
<State Key="CssInlineCode" TokenKey="CssInlineCode" Filename="mirabyte.CSS.inline.xml" ChildLanguageBackColor="WhiteSmoke">
  <Scopes>
    <Scope>
      <RegexPatternGroup LookBehind="style" Type="StartScope" TokenKey="StartTagAttributeInlineStyleValueStartToken" Style="TagAttributeValueStyle" PatternValue="= {LineTerminatorWhitespaceMacro}* \&quot;" />
      <RegexPatternGroup Type="EndScope" TokenKey="StartTagAttributeInlineStyleValueEndToken" Style="TagAttributeValueStyle" PatternValue="\&quot;" />
    </Scope>
  </Scopes>
</State>


Actipro Software Support

Posted 14 years ago by Joachim Schwieren
Avatar
Hi,

yes that did the trick. I even got rid of the special CSS.inline.xml by applying the state transition manually from code and assigning a dedicated state for that from my "normal" CSS.xml which is mainly used for highlighting complete CSS files.

Thanks for the very good/quick support and help on this issue!!! Just in case anyone is interested to see that application that makes heavy use of SyntaxEditor, have a look at Web Architect, a code-based HTML/Web editor with an integrated Desktop CMS. Very soon also HTML5 support will be added by the way! :-)

Best regards,

Joe
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.