Keep track of the currently active "variable" in an InfoTip?

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Karl Grambow
Avatar
I've been trying to build InfoTips that behave like those we see in VS. It's probably easier to explain this by example:

In vb.net the InfoTip for the Function Instr looks like:

Instr(String1, String2, ...and so on)
String1: String expression being searched.

If you then place a comma, the InfoTip updates itself to make String2 bold and the description will also update to reflect the String2. Subsequently, if you move the caret position to either side of the comma the info tip will update itself accordingly.

I've created a couple of clases that pretty much enable me to do this but it suffers from a couple of issues (namely, if either of the Strings have commas in them then I need to start searching for commas that exist in strings and it gets kind of messy).

In general I just feel like my solution is not very elegant.

I was just wondering what some of you were doing to arrive at this type of solution.

I'm happy to share my code if anyone would like to see it or if they feel it would help.

Comments (5)

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
It sounds like you're doing text-based parsing and should use token-based parsing instead. One of the powerful features that SyntaxEditor provides is semantic parsing. The syntax language definition breaks everything up into tokens, and then you can search the tokens. Tokens are given Keys and LexicalStates based on the syntax language.

You mentioned that strings have commas in them, and that was messing up your search. On the token level, there is a difference between a comma in a string and a comma used to separate parameters. It really depends on how your syntax language is defined, but a comma is likely a "PunctuationToken" and a comma within a string is some form of a string token (like "StringDefaultToken"). This can be determined by the 'Key' property of a Token object. You can also use states to help you out. A comma within a string will be in a lexical state called "StringState" and a comma in a parameter list will be in the lexical state called "DefaultState".

Use the TokenStream object to traverse the tokens in your document (syntaxEditor.Document.GetTokenStream method).

Hope this leads you in the right direction.

Boyd
Posted 19 years ago by Karl Grambow
Avatar
Thanks Boyd, Thanks for the reply. You're right I was doing text-based parsing.

I had thought of using the token object previously but the I couldn't figure out how to use it in my situation. You mentioning it though has given me an idea.

Take the following text that has been typed in - and let's say that the caret is inside the second variable (by the text marked in bold).

Instr("Test 1","Test , comma"

All I have to do is count the number of "PunctuationToken" tokens between the current caret position and the start of the Instr function (which start at the first opening bracket). In the above example I'd get 1 "PunctuationToken" token, which tells me that the second variable is the active one and I go go ahead and make the relevant InfoTip description bold. That's easy enough.

Maybe you can help me with the next situation (let's say the caret position is by the bold number 5):

Instr("Test 1", Mid("Some string", 5)

What I want to do in this case is, again, find the number of "PunctuationToken" tokens between the caret position and start of the Instr function. But I want to ignore any "PunctuationToken" tokens that are inside the Mid function. The answer I should get is one.

There's a couple of ways I can think of doing it but in my experience of using SyntaxEditor over the last month there is often a better way that exists by using the existing SyntaxEditor functionality :-)

Almost every day I'm picking up some new, cool functionality in SyntaxEditor that makes my work easier.

Karl
Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
In you second situation, your caret is within in the 'Mid' function, so any InfoTips you display in there should be for the 'Mid' function and not for 'InStr' (at least, that's the way Visual Studio behaves).

To handle those situations, I keep an internal count of what group level I'm in. When I encounter a ")" character (CloseParenthesisToken), I adjust my group level value down by one. When I encounter a "(" character (OpenParenthesisToken), I adjust my group level value up by one. I know, based on that group value, whether to include or exclude the "," characters I encounter.

I'm not aware of any built-in way to handle that in SyntaxEditor, so you'll just have to code the logic you want while using the TokenStream object to navigate the tokens.
Posted 19 years ago by Karl Grambow
Avatar
I thought that was going to have to be the case. Shouldn't be too difficult.

Thanks a lot for you help, it's much appreciated.

Karl
Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
No problem... happy to help.
The latest build of this product (v24.1.1) 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.