-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(spoon-kotlin): use the Spoon metamodel to analyze and transform Kotlin code #2554
Comments
Hi @monperrus @petitpre |
Kotlin is the fastest growing language on Github: https://octoverse.github.com/projects#repositories |
found by @martinezmatias Simple Kotlin Source AST and Syntax Parsing, Editing, and Writing |
In addition to detekt and kastree mentioned in earlier comments, here are two more potential options. In contrast to detekt and kastree, these are not using the PSI module of the official compiler for parsing kotlinx.ast: Generic AST parsing library for kotlin multiplatform Kotlin grammar tools: Tokenization and parsing Kotlin code using the ANTLR Kotlin grammar |
Hi @jlundhol Better-parse: A nice parser combinator library for Kotlin: https://github.com/h0tk3y/better-parse |
FYI: KtSpoon : Modelling Kotlin by extending Spoon’s Java Metamodel (2021): http://urn.kb.se/resolve?urn=urn:nbn:se:kth:diva-304429 |
@jlundhol Can you comment on your parser's support for error recovery? Does it need to perform symbol resolution or it possible to define a source code transformation on an incomplete code snippet? Thank you! |
Hi @breandan , |
Thank you! From what I have seen, Spoon is able to handle whole-classes, but methods must be enclosed. While some parsers have better support for error recovery, it is unclear what should occur when transforming a partial code snippet, so it makes sense to only consider fully-formed classes. Otherwise I quite like your fluent API design and look forward to using it. Out of the ones I have tried, it seems to be the most reasonable. |
The code now lives on https://github.com/SpoonLabs/KtSpoon/. Thanks @jlundhol! |
@monperrus Is that a private repository or is the link incorrect? I am unable to access it. |
made public, thanks @algomaster99 |
FYI: kotlin-spec contains an official ANTLR grammar. |
Hi all,
We would like to propose a new item in the Spoon roadmap: use the Spoon metamodel to analyze and transform Kotlin code.
This would be useful because there is no major Kotlin analysis and transformation tool, with an API as powerful as Spoon's one (@martinezmatias would need this for his research). The Spoon community would reach a new target, in a super active and growing community.
This would be doable, because the concepts of Kotlin are heavily based on Java, and there is likely little information to add in the metamodel to support Kotlin. We would need to:
KotlinTreeBuilder
, based on a Kotlin parser / compiler. We could likely reuse the official one from @JetBrains.KotlinPrettyPrinter
.And last but not least, this would be a lot of fun!
What do you think?
--Martin (@monperrus) and Nicolas (@petitpre)
The text was updated successfully, but these errors were encountered: