Creating clean Psi tree

Hi,

I'm writing a Mathematica language-plugin. So far the file-registration, the lexer and basic highlighting are up and running. Instead of using the Grammar-Kit for parsing, I hand-crafted a Pratt-Parser since I want to learn something and I hope it fits better the operator-expression like Mathematica-language.

Although the class-structure to parse a great part of the language is already there, I first wanted to understand some details. So far I can correctly parse expression like a+b+c+.. Hooorray. The first thing I noticed is, that I don't know how to exclude certain elements from the Psi-tree. Consider this very small example

http://i.stack.imgur.com/V9O8t.png

As you can see the PsiElement(PLUS) is not required since I know the element-type from the "Plus" node. At which point during the built of the Psi-tree can I prevent the PsiElement(PLUS) to be in the final tree? Or is it required that all leafs stay in the tree because they have a connection to the source-code? Basically I want exactly what is depicted in the last step of this image from the "Custom language documenation":

http://www.jetbrains.com/idea/plugins/PsiBuilder.gif

Maybe I can ask a second question: The only reason for me to build a parser (and a Psi-tree) is that I want to be able to implement some nice features like camel-hump autocompletion and refactoring and advanced highlighting. When I understand this right, then my elements in the Psi tree need to implement certain interfaces, e.g. I assume my identifier-element needs to implement PsiNamedElement in order to support renaming.

Can someone point me to some further documentation? For instance ASTWrapperPsiElement seems to be really helpful but the java-doc is non-existent (in my version of the openapi). Maybe there are discussions here which I just haven't found.

Cheers
Patrick

2 comments

1. The PSI elements need to remain in the tree. The picture in the document is a bit of simplification; in fact the PSI elements need to cover the entire text of the file.

2. The custom language plugin development documentation describes specifically how features such as completion and rename are implemented. Most of them do not involve implementing any interfaces other than PsiNamedElement and PsiNameIdentifierOwner. If you have questions on implementing a specific feature, feel free to ask. ASTWrapperPsiElement is the default base class for a custom language PSI element; not sure what additional documentation on that you need.

0

Thanks Dmitry for the fast answer.

2. The custom language plugin development documentation describes specifically how features such as completion and rename are implemented. Most of them do not involve implementing any interfaces other than PsiNamedElement and PsiNameIdentifierOwner. If you have questions on implementing a specific feature, feel free to ask. ASTWrapperPsiElement is the default base class for a custom language PSI element; not sure what additional documentation on that you need.

You are right. Let me first complete the parser and try to implement a simple feature. Maybe I will get used to the overwhelmingly large openapi on the way.

Cheers
Patrick

0

Please sign in to leave a comment.