Posted 20 years ago
by Boyd
-
Sr. Software Developer,
Patterson Consulting, LLC
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: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.
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;
}
}
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.