Outlining and SemanticParser

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
Here's a little background information. I'm setting up SyntaxEditor for a language loosely based on C/C++. I want to have automatic outlining performed on the body of functions (collapse text between the curly braces).

I created a class that inherits from SemanticDefaultParser and added the overrides for 'GetTokenOutliningAction' and 'PostParse'. Both of these methods look at the token stream to see if the "OpenCurlyBraceToken" and "ClosingCurlyBraceToken" are used for the body of a function (as opposed to an 'if' or 'for' block). Part of this validation looks for the "KeywordToken" with the text 'function' followed by the "OpenParenthesisToken" (whitespace ignored). If that sequence is not found within the proper context prior to the "OpenCurlyBraceToken", it is not a valid function definition, and should not be included in the outlining.

So far, everything works great. When I type the following code in SyntaxEditor:
function test_function()
{
    for (i = 0; i < 10; i++)
    {
        do_something;
    }
}
The body of the function is properly picked up for automatic outlining, and the body of the 'for' loop is not (as intended). Here comes my issue...

After the outlining is in place, I remove the 'function' keyword. At this point, the "OpenCurlyBraceToken" and "CloseCurlyBraceToken" should no longer use automatic outlining since that keyword validates when outlining should be performed. However, the 'GetTokenOutliningAction' method is never called on these two items. Therefore, the outlining persists. Oddly enough, if I type a space character after the CloseParenthesisToken" in the function declaration, the curly brace tokens DO get passed back to the 'GetTokenOutliningAction' method.

What determines when a token is passed to the 'GetTokenOutliningAction' method, because it doesn't appears to re-examine all the tokens?

I'm probably just missing something, so I appreciate any help.

Comments (2)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It starts with the Token at which the lexical parsing began. It goes at least until the Token at which lexical parsing ended. If outlining states potentially change, it may extend the semantic parsing range beyond that.

If you look at the modification, you can examine the LexicalParseOffsetRange to see what range of offsets were parsed by the lexical parser.


Actipro Software Support

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
For the benefit of others who might read this, here is some more information.

I am using tokens outside the starting and ending offsets of the area I am outlining to determine if the outlining should be done automatically. This works very well when initially setting up the outlining. The problem is that the DefaultSemanticParser is designed to be as efficient as possible and currently focuses on the area within the bounding offset of the outlining node. Since the changes I made were before the starting offset, it doesn't reparse the data.

It looks like the final solution will be to create a SemanticParser that doesn't inherit from DefaultSemanticParser.
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.