I noticed that Kotlin has a "LightTree" representi...
# compiler
a
I noticed that Kotlin has a "LightTree" representing the individual source code elements. Is there any way to use that in a library to help model source-code generation? KSP and KotlinPoet both give up on representing the bodies of functions, but I'd like to use and modify that information without constructing new wrapper classes for every single expression type. EDIT: tbh I'm not sure if that lighttree represents each kotlin expression, so I might be barking up the wrong tree altogether. I saw it in the code and hoped it was what I needed.
h
Yeah, I also want to have a kotlin modeling library. I wrote a (very hacky) implementation by myself but I need to improve it. https://kotlinlang.slack.com/archives/C0B8PUJGZ/p1769687481686459?thread_ts=1769686074.367619&channel=C0B8PUJGZ&message_ts=1769687481.686459
a
I also wrote a very hacky implementation, lol
d
LightTree is a very dump parse tree which consists of one node type (
LighterASTNode
) and a enum-like marker
IElementType
which indicates to which grammar element this node corresponds to (see KtNodeTypes for kotlin values). This tree is not very user-friendly and doesn't support transformations by itself. Its main advantage is how fast it could be built by parser, so that's why the CLI compiler uses it to parse and build the raw FIR tree. The PSI tree is actually just a typed wrappers over the light tree.