Simultaneously HighLighting and Outlining

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by rconde01
Avatar
I've just hit something kind of surprising and I wondered if you had a solution. I have a keyword "While" which I want syntax colored...but I also need the pattern "While(x < y);" (i.e. the regular expression we discussed last week) to trigger an outlining start. Likewise, I have a keyword "End" that I want syntax Colored, and a pattern "End;" which i want to stop outlining. Trouble is, depending on the order they appear in the xml language spec one overrides the other.

Also it would be nice if I had the option to not show outlining until the outlining start and stops have been typed.

Thanks in Advance

Comments (8)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You have to add your patterns in the order where the most specific, longer patterns occur first in the language definition and the more generic shorter ones come last.

I added your suggestion about the outlining indicators to our TODO list.


Actipro Software Support

Posted 14 years ago by rconde01
Avatar
I thought I was doing that. Here is my langauge definition - hopefully you can point out where I'm going wrong:

<?xml version="1.0" encoding="utf-8" ?>
<SyntaxLanguage Key="TestLang" LanguageDefinitionVersion="2.0" Secure="True">

<Styles>
<Style Key="CommandKeyWord" ForeColor="Blue" BackColor="White" Bold="False" Italic="False" Underline="False" />
</Styles>

<States>
<State Key="DefaultState">
<PatternGroups>
<!--Outlining-->
<RegexPatternGroup Token="WhileLoopToken" PatternValue="While\s*\(([^\)]*)\)\s*;" />
<RegexPatternGroup Token="EndToken" PatternValue="End\s*;"/>

<!-- Whitespace -->
<RegexPatternGroup Token="WhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />

<!-- Line Terminators -->
<RegexPatternGroup Token="LineTerminatorToken" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />

<!-- Syntax Coloring -->
<ExplicitPatternGroup Token="CommandWordToken" Style="CommandKeyWord" LookAhead="{NonWordMacro}" CaseSensitivity="Sensitive">
<ExplicitPatterns>
While End
</ExplicitPatterns>
</ExplicitPatternGroup>

<RegexPatternGroup Token="IdentifierToken" PatternValue="(_ | {AlphaMacro})({WordMacro})*" />

</PatternGroups>

</State><!-- End Default State -->
</States>
</SyntaxLanguage>

[ 10-08-2004: Message edited by: rconde01 ]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I loaded your language def and added the following text and it lexically parsed it correctly:

While();
While
End;
End


Actipro Software Support

Posted 14 years ago by rconde01
Avatar
It parses...but try this:

Type "While"...it will be blue.

Now finish it off to "While();"...now no longer blue. Thats the problem.

Rob
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You just forgot to set the style for your special versions of the keyword, that's all. Add Style="CommandKeyWord" to your two special patterns. If you load the language def in our sample application you can see that the tokens are parsing fine (look in the statusbar), even though they appear black since they are currently using DefaultStyle.


Actipro Software Support

Posted 14 years ago by rconde01
Avatar
I didn't forget...if I do that then the entire phrase "While();" will be blue - only "While" should be blue.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok then you should place the part that shouldn't be colored blue in a look-ahead pattern. There's a LookAhead attribute that you can use.


Actipro Software Support

Posted 14 years ago by rconde01
Avatar
thats it!!! thx
The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.