Posted 17 years ago by Scott Green - Owner, BoneSoft Software
Version: 3.1.0210
Avatar
Actually, this isn't really about snippets per se, but I'm not sure what to title it.

I have a list of type level snippets, and a list of member level snippets. The member list is under the type list directory. When outside a type, I want the types listed and the member folder visible, that's easy enough. But when inside a type, I only want the member list visible. My question is this... What is the best way to go about determining if the carot is inside a type? My grammar is similar to C# in that members are enclosed within braces {}. Is this something that a SemanticParser can handle? KeyPressTriggers are not smart enough since typing isn't the only way to move the carot, but I'm not sure where to look for a solution.

Comments (4)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Scott,

There are numerous techniques to do this sort of thing and many are advanced. For instance in v4.0, like in our .NET Languages Add-on, we create a complete CompilationUnit of the document via semantic parsing and then use that CompilationUnit (which is an AST) to determine if we are in a type or member, etc. A simpler way is to do token scanning via a TextStream and go backwards to look for keywords that would indicate you are in a type or member.

You are in v3.1 though where semantic parsers didn't do much other than outlining. So perhaps doing the token scanning before displaying the snippets would be best in your scenario.


Actipro Software Support

Posted 17 years ago by Scott Green - Owner, BoneSoft Software
Avatar
Yeah, I assumed I'd have to do something like a compilation unit scenario. But I was wondering if there was a way I could avoid doing the whole document. But it may be quick enough to not be a problem. I was looking for the best place to examine the token stream, and was trying to understand the modification model in the Pre and PostParse methods of the SemanticParser. I still need to figure out how to determine where the cursor is in that comp unit once I do parse it though.

Thanks
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I would suggest in this case at least just doing a token scan upon demand. So when the snippet is to be inserted, run some code to figure out what you are in. If you do token scans backwards you can look for sequences of tokens. Or even tap into the outlining node tree and use that to iterate up and when you get to a {...} block, look at the tokens in front of the { to see if it is a method, type declaration or some other statement.


Actipro Software Support

Posted 17 years ago by Scott Green - Owner, BoneSoft Software
Avatar
Looking at the outlining tree is something I hadn't thought of. That's actually a great idea for what I need. Thanks.
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.