Skip to content

Conversation

@KrylovBoris
Copy link
Contributor

In this pull request, @Chr1sps and I have introduced a generation of parsers that use a new multiplatform Syntax API.

Why the changes were made?

Currently, generated parsers depend heavily on IntelliJ IDEA PSI-related functionality, which is written in Java and is not KMP-compatible. Syntax API alleviates this issue by reducing the number of dependencies and enabling Kotlin-based parsers.

These changes make Fleet-compatible generation obsolete, thus we had to remove associated functionality.

What has changed

We introduced KotlinParserGenerator class that is responsible for generating Kotlin-based files. To access new functionality, you need to add generate=[parser-api="syntax"] to your grammar file. This allows us to use the same "Generated Parser Code" for both old Java parser generation and new Kotlin one.

PSI support

To continue to support PSI-related functionality and keep it compatible with KMP, we added a setting that specifies a path to a separate module that will contain all generated PSI classes. This path must be relative to the project root.

Putting psiOutputPath="your-psi-plugin" in your BNF file would generate files in the '/your-psi-plugin / gen' folder. This allows the user to keep their Java code and KMP code separated.

.
├── your-plugin/
│  └── gen/
│     ├── GeneratedParser.kt                     # Parser implementation
│     └── GeneratedSyntaxElementHolder.kt        # Holds SyntaxElementType instances
└── your-psi-plugin/
    └── gen/
        ├── psi/                                      # PSI-related files
        │    ├── your.java                            # Your PSI classes
        │    ├── psi.java                             #
        │    ├── files.java                           #
        │    └── GeneratedSyntaxElementConverter.java  # ElementTypeConverter implementation
        └── GeneratedElementHolder.java   # Holds IElement instances

How have the other parts of the plugin been affected?

Core generation functionality has been drastically changed, including the behaviour of the "Generate Parser Code "action. However, existing generation tests remained unchanged, ensuring that the main generation functionality remains stable.

@KrylovBoris KrylovBoris marked this pull request as draft October 9, 2025 13:53
Boris Krylov and others added 29 commits October 10, 2025 14:31
(cherry picked from commit 70ab9d7)
…or api to use before importing ParserUtils
Boris Krylov and others added 26 commits October 10, 2025 14:32
@KrylovBoris KrylovBoris force-pushed the rebasing-kotlin-generator branch from c8afb6f to 145c4ed Compare October 10, 2025 11:38
@KrylovBoris KrylovBoris marked this pull request as ready for review October 10, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants