Embedded source editor for expression from custom language?

I need to be able to show an embedded instance of the source editor for an ad hoc expression from my custom language.  This is very similar to the Evaluate Expression window from the Java debugger, though the usage is different.  I've been looking at that code and trying to understand how it works, but it's pretty dense.  As a result, I was hoping for guidance on how best to do this from the community.  As I see it, there are two primary questions here...

The first question is whether I need to have my parser explicitly support these expressions as an entry point for parsing.  Right now the only entry points are standard compilation units, e.g., classes, interfaces, enums, etc.  I can obviously do this, but if it's possible to specify an alternative entry point for parsing for a specific purpose, that would be ideal.  If it is possible to tell parsing to begin at some other non-terminal, how does that work?  Is there some example out there for reference?

The second question is how I can host a fully-functional source editor in my own panel.  I want the user experience to be just as if the expression were being edited in a file editor if possible...syntax highlighting, completion, references, etc.  Then I just need to be able to get the source body and use it.  Again, any pointers to existing code that does this is HUGELY appreciated!

Thanks much for any help!

UPDATE: It looks like LanguageTextField exists for exactly this purpose assuming your Language can handle the expression/block as an entry point for parsing.  For the moment I think I'll proceed under the assumption that I'll need to allow that, but any tips on how to start parsing at alternative grammar rules are appreciated.

1 comment
Comment actions Permalink

I pretty much have this working, so I'll mark the question as answered.  I never did figure out if I could have my parser use an alternative entry point, but it was pretty easy to set it up for an entry point for an expression and to adjust my reference and completion logic to facilitate that.  Well, that's not entirely true...references are calculated properly, but on navigation through references, e.g., go to declaration, the target is opened in a dedicated editor instead of my ad hoc editor.  Not sure how to get it to stay in the same editor component.  Anyway, I think it's good enough for my immediate needs now.


Please sign in to leave a comment.