nested languages breaking out even when inside comments or s

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by SamWare
Avatar
i'm having trouble with JScript code blocks inside of HTML not being completely recognized as JScript.

here's a simple example you should be able to reproduce in the "SyntaxEditor Sample Editor Application". just change the language to HTML, and paste this code pretty much anywhere.

<script>
var test = "</script>";
hmm.
</script>

Comments (9)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes we're aware of this... please see a posting from a while back named "Nested Language Support". That explains it and what we might be able to do in the future for handling it.


Actipro Software Support

Posted 19 years ago by SamWare
Avatar
anyone else looking for the answer should goto the <A HREF="http://www.actiprosoftware.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=11&t=000016" TARGET=_blank>Related Post</A>.

doh! i appologize for not using the search feature. :|

you guys had a great idea 'bout moving the string pattern into the default state (seems like it'd be faster), rather than having it as it's own state (which, imo makes the parsing slower).

thanks again for your help!

[ 10-02-2004: Message edited by: SamWare ]
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
No problem at all... glad our workaround helped you.


Actipro Software Support

Posted 19 years ago by SamWare
Avatar
i wanted to share my findings after spending a lot of time trying to figure out the right regular expression for the job.

i hope this helps somebody out there. <IMG SRC="smile.gif" border="0">


put this code in the PatternGroups of the DefaultState for whatever language.

&lt;!-- Strings --&gt;
&lt;RegexPatternGroup Token="Static_String" Style="StringDelimiterStyle" PatternValue="' ([^'\\\n]|\\.)* '" /&gt;
&lt;RegexPatternGroup Token="Normal_String" Style="StringDelimiterStyle" PatternValue="\&amp;quot; ([^\&amp;quot;\\\n]|\\.)* \&amp;quot;" /&gt;    
NOTE: if the language-to-be-formatted supports Multiline Strings, then just remove the \n's in the expressions.

[ 10-02-2004: Message edited by: SamWare ]
Posted 19 years ago by Gareth - Director, Slyce Software Limited
Avatar
I have exactly the opposite problem to the original poster! I need a state transition to occur in the middle of a comment line, but it is being ignored. I am using the latest version of SyntaxEditor (2.5.0154). Any ideas?

Thanks,
Gareth.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Gareth,

The lexical parser will continue matching a pattern as long as it can. So say your comments are currently being parsed into a single really long token. There is no way for a state transition to occur.

In that scenario, it's better to break up word tokens, whitespace, etc. so that when the parser gets to a "%" character (assumer we're in an ASP block), it is about to start a new token on the "%" character and at that point will look for state transitions. Make a little better sense?


Actipro Software Support

Posted 19 years ago by Gareth - Director, Slyce Software Limited
Avatar
Thanks for the reply. I understand what you are saying, but can't seem to implement a workable solution. I have tried adding a StateTransition, but can't get that to work.

A good example is to use the C# Sample Editor Application, which ships with SyntaxEditor. It is the one accessed via Language -&gt; Dynamically Create -&gt; option 2 (using &lt;% %&gt; ).

Please can you tell me how to modify the 2 xml files to get the following text to display correctly:

&lt;!-- This is a &lt;% This is NOT ok %&gt; comment --&gt;
&lt;parser version="1.0"&gt;&lt;% This is ok %&gt;

Many thanks for any help you are able to offer.
Gareth.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok using that sample, to get the transition to work in a comment, you have to do a couple things.

First, in the XML language definition, right now the CommentDefaultToken spans the entire range of the comment and only breaks on a "-" character. You need to update the line in the def to include the "&lt;" character like this:
&lt;RegexPatternGroup Token="CommentDefaultToken" PatternValue="[^\-&lt;]+" /&gt;

Also, in the CreateDirectiveXmlToCSharpLanguage method, you need to add another line under this one:
language.LexicalStates["DefaultState"].ChildLexicalStates.Insert(0, lexicalState);

The line to add is:
language.LexicalStates["CommentState"].ChildLexicalStates.Insert(0, lexicalState);

If you do those two changes, it works in comments.


Actipro Software Support

Posted 19 years ago by Gareth - Director, Slyce Software Limited
Avatar
Fantastic! Works a treat. Thanks for your help.

Cheers,
Gareth.
The latest build of this product (v24.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.