I built a converter that converts the PSI-parsed AST to a more straightforward one. Here are some notes I took while converting parser results, numbered/categorized for easy response:
- Where the reference grammar is wrong:
-
collectionLiteral
’s reference toelement
is broken link -
callSuffix
’s trailing annotated lambda is not properly marked as optional -
callSuffix
says it takestypeArguments
on the LHS which doesn’t include the*
projection even though it’s valid -
functionType
’sparameter
ref makes it seem liketype
is required which it’s not -
callableReference
’s LHS says it only supportsuserType
which is not true, should be some kind of expression -
callableReference
mentions an optionaltypeArguments
at the end. Is there anywhere I can see an example of this? -
classModifier
is missinginner
-
- Where the PSI parser corpus (taken from here) has something unexpected:
- What are function expressions? Specifically, what do the following mean:
val a = fun b()
val a = fun @[a] T.(a : foo) : bar
- Grammar doesn’t allow nameless function, but parser does and there is a corpus test enforcing it. Why make this a valid parse?
- Docs say “Any expression in Kotlin may be marked with a label”, but
label1@ val x = 1
is a labeled statement (var decl) instead of an expression. Would that actually be considered two statements, a label def and a var/property decl, or should a var decl be considered an expression? Doesn’t appear properly in the grammar either way. - Grammar doesn’t allow functions without names, but parser does and there is a corpus test enforcing it. Why make this a valid parse?
- Grammar doesn’t allow something like an
interface
decl, but there is a parser corpus test atrecovery/InterfaceInExpressionPosition.kt
that says it should parse validly. Why make this a valid parse?
- What are function expressions? Specifically, what do the following mean:
That’s only the things I jotted down while developing, there are a bunch of other idiosyncracies I probably just worked around. Feel free to respond, ignore, make issues, etc.