How can I get lexical transitions within attributes?

SyntaxEditor for WPF Forum

Posted 13 years ago by Craig - Varigence, Inc.
Version: 11.1.0544
Avatar
Looking at the Language Transitions sample (that uses <% %>), let's say I alter the top element tag by adding an attribute that contains transition delimiters, as follows:

<element bob="<% %>">
How might I change your sample's code so that the delimiters within the attribute are recognized as language transitions, instead of just being attribute text?

Thanks,

-Craig

Comments (8)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Right now I believe that sample only injects the child "ASPDirective" state to the default state in the parent language. It would need to be added to the other states as a child state too.


Actipro Software Support

Posted 13 years ago by Craig - Varigence, Inc.
Avatar
I tried solving this, in your sample code, by adding these two statements

parentLexer.LexicalStates[2].ChildLexicalStates.Insert(0, lexicalState);
parentLexer.LexicalStates[3].ChildLexicalStates.Insert(0, lexicalState);
directly after

// Insert the transition lexical state at the beginning of the parent language's 
// default state's child states list so that it has top matching priority
parentLexer.DefaultLexicalState.ChildLexicalStates.Insert(0, lexicalState);
This approach works for examples like:

<element bob="<% %>">
<element bob="<% %>randomTextAfter">
However, it doesn't work when there's text in the attribute value to the left of the delimiter. For instance:

<element bob="textBeforeDelimiter<% %>">
In this case, the lexical transition is still treated as part of the attribute value. Is there something I can do so the lexical transition will be recognized in this scnario as well? Is this a bug?

Thanks again,

-Craig
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Yes, the patterns are greedy meaning when you enter a pattern, they will attempt to keep consuming characters until they cease to match. So the attribute value state probably has some pattern that says match all characters except a quote. You'd want to add the '<' character to that list so that the token being constructed by that pattern can break and allow the exit transition to be matched when appropriate.


Actipro Software Support

Posted 13 years ago by Craig - Varigence, Inc.
Avatar
Could you be more specific as to where the list is, that I'd need to add the '<' character to? Perhaps a small code sample showing how I'd do it in the lexical transition sample?

Thanks,

-Craig
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Well in the states you updated that can possibly call into your new child state, a lot of them have something like (this one is for double quote attribute values):
<RegexPatternGroup Pattern="[^\&quot;\&gt;]+" />
That would need to be modified to:
<RegexPatternGroup Pattern="[^\&quot;\&gt;\&lt;]+" />


Actipro Software Support

Posted 13 years ago by Craig - Varigence, Inc.
Avatar
That's what I needed - thanks.
Posted 13 years ago by Craig - Varigence, Inc.
Avatar
So, another question:

Using the language transition sample, let's say I have the following XML:

<element bob="<% "sam" %>">
Right now, I see that <% is highlighted as a language transition. However, the quote before 'sam' seems to be treated as ending the attribute value. My expectation is that it'd be treated as a C# quote within the attribute value (due to the language transition), rather than ending the attribute value.

What change can I make so the quotes within the language transition don't affect the XML attribute value quote delimiters?

Thanks,

-Craig
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Each lexical scope has an IsAncestorEndScopeCheckEnabled property that defaults to true. You can set that to false on your scope that transitions to ASP. That way it won't look for the double quotes as an end scope.


Actipro Software Support

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