Odd language constructs

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Alex Lyman - Woodland Park, CO
Avatar
I've been asked to evaluate SyntaxEditor for use in one of my company's future products. It involves an obscure language, which seems to have no other coralary in any other language.

There are many constructs that look like this:

DO WHILE (x < 5);
   x = x + 1;
END;
My question is: Is there any way to make 'DO WHILE' a StartScope, 'END;' an EndScope,
and highlight the expression '(x < 5)' specially (it has special context in the specific language in many places -- this example is not one of them, but is the best example I could find that would be understood by someone not familiar with the language)? If so, what is the best way to do this?

So far, my best attempt was to make a ChildState that matched a () delimited expression, but I could find no way to impliment any kind of context requiring it to be after a 'DO WHILE' and before a ';'.

Alex Lyman
Lead Developer
Savian Software, LLC

Comments (4)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
A question before I can answer, does the DO WHILE always have a ( ... ); expression follow it?

Also, if we see a ( ... ), would it be ok to determine that it is the special expression type simply by looking at the DO WHILE before it and not necessarily the ; after it?


Actipro Software Support

Posted 14 years ago by Alex Lyman - Woodland Park, CO
Avatar
.In the case of DO WHILE, yes, it will always have the expression. In other places, it may or may not.

I'm not worried about whats after the expression so much -- what came before it is much more important.

If you're interested, the language I'm trying to highlight for is one created and constantly modified since the mid-60's, so it's completely lacking in any recognizable sanity. Most commands and functions have both optional and required, named parameters, though some have unnamed order-dependant ones.

The main problem I have is that inside the expression, things that look like variables might not be (they can be variables, data tables, or named parameters -- maybe more) -- and thats wholly dependant on what kind of statement its in -- and I need to color them all differently.

Alex Lyman
Lead Developer
Savian Software, LLC

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, in that case, I think your best bet might be to do semantic parsing. To do this, you would create a class that inherits SemanticParser and then implement its PostParse method. That method tells you the offset range that was lexically parsed.

In that method, you could get a TokenStream and iterate through the tokens that were modified. If they are in one of those special (...) expressions, you can set a custom highlighting style via code to them. This is done with the Token.CustomHighlightingStyle property.

You want to set up the highlighting styles in the language ahead of time and use those instances of the HighlightingStyle class at run-time.

The reason I recommend using semantic parsing to assign highlighting styles programmatically to tokens in the special expression is that a lexical parser can only recognize patterns but cannot determine if the pattern represents a variable or parameter. That is unless you have special syntax in your language that can denote each. Not sure if your language does or not.

Another feature that is already complete for the next major release of SyntaxEditor is the concept of look-behinds in pattern definitions for lexical pattern groups. Look-behinds will enable you to make a special state (and scope) for a ( character that follows DO WHILE text. You could add other scopes for things like a ( that follows an IF, etc. and have them use the same special expression state.

Hope this helps a little.


Actipro Software Support

Posted 14 years ago by Alex Lyman - Woodland Park, CO
Avatar
Is there any chance theres a current ETA on that release you mentioned?

Alex Lyman
Lead Developer
Savian Software, LLC

The latest build of this product (v2018.1 build 0341) was released 7 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.