Posted 17 years ago by Chris Morris
Version: 4.0.0245

I have a question in regards to the Dynamic Syntax Language and outlining.

I'm designing a dynamic language definition for a basic language, which requires the REPEAT/UNTIL method to be folded.

It's general format is:

UNTIL expression

The problem I have is folding the expresion associated with the UNTIL command.

This is the code in the xml file:
<ExplicitPatternGroup TokenKey="RepeatRegionStartToken" Style="KeywordStyle" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect"> 
   <ExplicitPattern Value="REPEAT" />
<ExplicitPatternGroup TokenKey="EndRepeatRegionStartToken" Style="KeywordStyle" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
   <ExplicitPattern Value="UNTIL" />        
Example code in the Editor:
0 'Outlining Open
2    a := a + 1
3 UNTIL a < 10
5 'Outlining Closed
6 REPEAT (...) a < 10
I have looked at the other Actipro examples but could not seen a similar example where the rest of the line after the final end keyword is folded.

Any suggestion would be appreciated?


Comments (5)

Posted 17 years ago by Dave Sparks
Hi Chris,

I thought I would chime in because I did something similar.

Try this within your state:

          <ExplicitPatternGroup Type="StartScope" TokenKey="RepeatRegionStartToken" PatternValue="REPEAT" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect" />
          <RegexPatternGroup Type="EndScope" TokenKey="RepeatRegionEndToken" Style="DefaultStyle" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />
          <ExplicitPatternGroup Type="StartScope" TokenKey="EndRepeatRegionStartToken" PatternValue="UNTIL" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect" />
          <RegexPatternGroup Type="EndScope" TokenKey="EndRepeatRegionEndToken" Style="DefaultStyle" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />
        <RegexPatternGroup TokenKey="RepeatRegionWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
        <RegexPatternGroup TokenKey="RepeatRegionWordToken" PatternValue="\w+" />
        <RegexPatternGroup TokenKey="RepeatRegionDefaultToken" PatternValue="{NonLineTerminatorMacro}" />
And in your codebehind (SetOutliningNodeCollapsedText method):

                case "EndRepeatRegionStartToken": {
                    string collapsedText = String.Empty;
                    while (++tokenIndex < tokens.Count) {
                        if (tokens[tokenIndex].Key == "EndRepeatRegionEndToken")

                        collapsedText += tokens.Document.GetTokenText(tokens[tokenIndex]);
                    node.CollapsedText = collapsedText.Trim();
I cant test for sure. It should give you a start though.

[Modified at 03/22/2007 11:47 AM]

[Modified at 03/22/2007 11:49 AM]
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Chris,

No we don't have any samples on this particular thing but if you are using dynamic languages, then what Dave suggested might do the trick.

This sort of thing is easier when you have an advanced AST model to base your nodes on. But in most cases, it takes weeks/months to build that sort of thing for a language. So you're probably best off as you have it.

Actipro Software Support

Posted 17 years ago by Chris Morris
Thanks Dave for your kind response.

Unfortunately the problem I have found with trying to use ChildStates and Scopes is that any other predefined rules for highlighting keyword syntax are no longer used.

So in my example I could define some syntax for highlighting identifiers (variables) which would be displayed in the statement section but not in the expression syntax.

For example variable abc is no longer recognized in the scope declaration so is not highlighted (bold) in the expression syntax.

0 'Outlining Open
2 abc := abc + 1
3 UNTIL abc < 10

I think I would have to duplicate all my existing rules for this new scope declaration which is not ideal.

I was hoping there might be a simpler solution that I may have over looked.

Kind regards,


[Modified at 03/26/2007 03:24 AM]

[Modified at 03/26/2007 03:26 AM]
Posted 17 years ago by Dave Sparks
Actually, I bet if you try it, you'll find this isn't true.

I use a similar setup and it works fine. The reason is, that everything in-between is not part of the REPEAT state (which is why there are two scopes). Only the REPEAT and UNTIL line will exist within that state.

Please, try it. If it still doesnt work, I'll eat my shoe :) I say this in confidence because I have already done it within my language.

To give you further proof, please look at the C# example for the region preprocessor directive in the samples. That has a collapsable code block based on two unique lines and everything between highlights just fine. There is no duplication of any states.

[Modified at 03/26/2007 08:49 AM]
Posted 17 years ago by Chris Morris
I think ther may be slight misunderstanding in my initial response.

I agree that all the existing syntax rules in the statement code between the REPEAT and UNTIL work fine :) and the code does fold :)

However, there would be an inconsistancy of the highlighting for the user after the UNTIL and in the expresion code part (as this is now part of the scope region). I would have to copy all my existing rules (which there are many in my syntax langauge - most of the xml file) in to the PatternGroups of the scope.

In my language the same rules need to be supplied for both the statement and expression in the REPEAT/UNTIL loop.

I could change the EndScope not to go to the end of line (so not to include the expression code) but then that would not help the folding which was my original problem.

I don't think there is an ideal solution but I thought I would ask!
The latest build of this product (v24.1.0) was released 5 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.