How do I write a parser? Follow
Hi,
I decided to learn plugin development by writing a bash language plugin.
So far I have the highlighting done, basic folding and a start of a parser.
IMHO it's not that easy to write a parser for IntelliJ. I have basic parsing working - but:
- I don't know how to test the parser in unit tests. Any possibility for that? Starting the second instance is not that productive
- What is the recommended way to write a parser which fits to a certain grammar? I'm not very experienced writing parsers and still make many mistakes doing that, I think.Anything like a parser generator available (antlr...)?
- Is there some language plugin source code which is not that difficult to read, small and well structured to be an example?
More questions will follow, I think
Wallaby
Please sign in to leave a comment.
Hello wallaby.pouch,
Yes, of course. Here's one example from our own plugins:
http://svn.jetbrains.org/idea/Trunk/bundled/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ParserTest.java
No, IDEA currently does not have a ready solution for using generated parsers.
The typical approach when writing parsers in IDEA is to create a method parseSmth()
for each rule in the grammar, and implement the rule in terms of PsiBuilder
markers.
The Clojure parser is probably the simplest and smallest of all the custom
language plugins that are maintained by us:
http://svn.jetbrains.org/idea/Trunk/clojure-plugin/src/org/jetbrains/plugins/clojure/parser/ClojureParser.java
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"