Using ANTLR for IntelliPrompt

SyntaxEditor for Windows Forms Forum

Posted 11 years ago by J.R.
Version: 13.1.0311
Avatar

Hello,

We are using an ANTLR grammar for a custom proprietary language. We would like to implement the IntelliPrompt feature of SyntaxEditor for WinForms. I have read that there is ANTLR support for the WPF version of SyntaxEditor, but was wondering if there was any way to use an ANTLR generated lexer/parser to implement some form of IntelliPrompt. Can an AST from ANTLR be used and what disadvantages would this have as opposed to the full ANTLR support? If not, is there any plan to update the WinForms project with this support?

Thank you for your help.

Comments (7)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The ANTLR support in the WPF version basically wraps our buffer reader, making it compatible with ANTLR's ICharStream.  A parser service is also included that allows the ANTLR parser to be called and its AST results returned back to the document.  The SyntaxEditor infrastructure between WPF and WinForms is quite different right now so at the moment, there aren't plans to port it over.

But really, all we get from ANTLR is the AST results.  There isn't anything that supports doing automated IntelliPrompt based on it.  That beign said, you can use a combination of token scanning and AST examination, like we do in our advanced language implementations, and with that information, determine when to show IntelliPrompt and with what content.


Actipro Software Support

Posted 11 years ago by J.R.
Avatar

Great, so it sounds like I should be able to manually get IntelliPrompt working once I have the lexing done within SyntaxEditor. I have been reading through the documentation and haven't found much on how to get the lexing working for a custom language aside from the Simple language. I have been looking at the Simple Language definition and believe I need to follow the SimpleSyntaxLanauge file as an example, but it looks like there is some sort of grammar generator that creates some the files (the AST files). I assume that I wouldn't need to generate the AST files as I will be using ANTLR to retrieve that information.

I guess what my question boils down to is do I also need to have the language add-on package to do add all this functionality (IntelliPrompt/Syntax Highlighting/etc) for a custom language?

Thanks again for your help.

[Modified 11 years ago]

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi J.R.,

No, you just need the basic SyntaxEditor control if you are doing a custom language.  A lexer could be made for your language programmatically (such as the Simple language example shows), or you could make a dynamic language that does the lexing (which is faster/easier to set up).

Either way you go, any semantic parser can be hooked up into the language and will execute in a worker thread as long as you've started the SemanticParserService.

The grammar part you saw was for our own custom grammar-based parser implementation.  But you can ignore all that since you would be using an ANTLR one instead.


Actipro Software Support

Posted 10 years ago by J.R.
Avatar

Thank you for your help so far. I have been working on getting this up and running, but I am still not clear on a few details. I have set a dynamic language to handle the lexing, and have been trying to get the SemanticParserService running, but am not entirely sure how to go about doing this. The documentation provides some examples, but I do not believe they mention anything about hooking up a third party parser and reading tokens,  so I am a little lost on where to go from here. Is there some part of the documentation that I am missing? My assumption is that in addition to overriding the PerformSemanticParse method, I will need to use the ISemanticParserServiceProcessor.Process method to call the ANTLR parser. Is this correct, or where would I actually do the hooking up? Thanks again for all the help.

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi J.R.,

You have it exactly right.  In PerformSemanticParse, make a parse request to the SemanticParserService like we do in the SimpleSyntaxLanguage.  Then handle ISemanticParserServiceProcessor.Process and call your ANTLR parser from there.  That latter method will be executed in a worker thread if you have the SemanticParserService started.


Actipro Software Support

Posted 10 years ago by J.R.
Avatar

Thank you again for bearing with me!

I have successfully been able to wire up the SemanticParserService, and I am not sure where to go from here. My next assumption was to assign the resulting ANTLR AST to the SemanticParseData of the SemanticParserServiceRequest. I don't see how I am supposed to cast the ITree as ISemanticParseData? I do not think this is correct as I am getting a null value after setting the SemanticParseData property (I know I must be doing something very obviously wrong). Nonetheless, how am I supposed to retrieve the results back from the ISemanticParserServiceProcessor.Process event?

Once I am able to solve this issue, I know I'll need to start working on examining the AST along with the tokens to determine what to populate the IntelliPrompt memberlist or show syntax errors. Could you possible point me to the method(s) in the advanced language implementation project that does this (as you mentioned in your first reply)?

Sorry for the remedial questions!

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi J.R.,

Yes you want to make an object that implements ISemanticParseData and you can put a custom property on that that is an ITree.  Then set that prop on a new instance of your parse data object, and assign the parse data object to request.SemanticParseData.  This will all occur in a worker thread.  So later on when it's done, the resulting parse data object will be in your Document.SemanticParseData property.

The SimpleSyntaxLanguage.ShowIntelliPromptMemberList method does some very basic AST examination and token scanning, so that's an example.  For a full production language, you'd probably want to get a lot more complex though.

Have a good weekend!


Actipro Software Support

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.