Standalone Parser Dependencies


I created a plugin with Grammar-Kit. Now I want to use the parser and the generated PsiFile in other applications, without having IDEA installed.

(Am I allowed to do this, I am not sure?)

I was not able to get 

java -jar grammar-kit.jar <output-dir> <grammar1>

up and running. Many dependencies are missing, I used the psi-light-all.jar. This did not work for me.

Now I got my standalone parser running with 


But I had to add multiple dependencies, which I copied from the Intellij SDK (it was hard and ugly to do this by hand) and my standalone parser file got 18 MB right now. It is working good, but the JAR is way too huge. (I tried first with light-psi-all.jar, but a lot was missing too)

Can you help me to gather the least necessary dependencies in order to get the LightPsi parser up and running?

Best Regards




Due to its nature light-psi-all.jar needs to be rebuilt for each version.

The process is hacky yet simple:

1. run the java code you want to run with -verbose:class option and save the output

2. Place all mentioned (and thus required) classes in a jar


Grammar-Kit can help you with that. See the shared run configurations here:

    LightPsi_All__classes.xml runs some parser generation and outputs "classes.log.txt"

    LightPsi_All__package.xml packages classes mentioned in the log file in a jar


The size depends on what functionality you want to have access to in a standalone version.

PsiBuilder / Lexer / LighterAST will be pretty small

AST and PSI will require lot's of other services, APIs & etc.


EDIT fixed java option to -verbose:class




I am not able to run "Light-Psi-All: classes" because 

import com.intellij.diagram.*;
import com.intellij.diagram.extras.DiagramExtras;
import com.intellij.diagram.presentation.DiagramLineType;
import com.intellij.diagram.presentation.DiagramState;

import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.request.ClassPrepareRequest;
are missing (I use the IntelliJ SDK).

Can you please tell me how I can build it? Or how I can just get LighterAST with minimum amount of code?

public static LighterAST parse(String text) {

Please provide some code to achieve this with the least necessary amount of dependencies.

Best Regards

Just "Exclude from Compile" or delete everything related to diagramming. One doesn't need that for parsing ;-)



OK creating light-psi-all.jar worked, thanks. When I use

LightPsi.parseFile or LightPsi.parseText

outside of IDEA I get the following exception: [java.lang.NoClassDefFoundError: com/intellij/psi/scope/PsiScopeProcessor]

This is what I got with the light-psi-all.jar from Grammar-Kit Github site. How do I tell the light parser to use the LighterAST? I think the issue is that it uses the standard AST which requires more dependencies as you described.

Best Regards



I've just added parseLight method that demonstrate the LighterAST usage:

You can use SyntaxTraverser API or PsiBuilder.getLightTree() directly.

The latest dev build is here:



Thank you for this addition. I built the new psi-light-all.jar.

Now I get "Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/psi/SyntaxTraverser$FlyweightApi$1" when I use it without the IntelliJ SDK. 

Could you also please provide an example, where I can print the AST including the PsiComment and PsiError elements?


Best Regards



If a class is not present in the created jar and is not present in classes.log.txt then it wasn't loaded.

Run exactly same code with IntelliJ SDK and -verbose:class option first and then collect all logged classes:

java -cp <intellij-sdk>;<project-out> -verbose:class  <your-main> > classes.log.txt

java -cp grammar-kit.jar org.intellij.grammar.LightPsi . classes.log.txt

to verify that the new jar is sufficient:

java -cp ligh-psi-all.jar;<project-out> <your-main>



For error elements and whitespaces it seem safer to use the result of PsiBuilder.lightTree directly.

Here's why they are missing in SyntaxTraverser.FlyweightApi:


Please sign in to leave a comment.