Standalone Parser Dependencies

Hi,

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 

org.intellij.grammar.LightPsi.parseFile

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

 

0
7 comments

Hi,

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:

https://github.com/JetBrains/Grammar-Kit/tree/master/.idea/runConfigurations

    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

 

0

Hi,

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
0

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

0

Hi,

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

 

0

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

https://github.com/JetBrains/Grammar-Kit/commit/4bf573ce0ac

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

The latest dev build is here:

https://teamcity.jetbrains.com/project.html?projectId=IntellijIdeaPlugins_GrammarKit

0

Hi,

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?

thanks!

Best Regards

0

NoClassDefFoundError:

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>

 

PsiErrorElements:

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:

https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/psi/SyntaxTraverser.java#L405

0

Please sign in to leave a comment.