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 toelementis broken link -
callSuffix’s trailing annotated lambda is not properly marked as optional -
callSuffixsays it takestypeArgumentson the LHS which doesn’t include the*projection even though it’s valid -
functionType’sparameterref makes it seem liketypeis required which it’s not -
callableReference’s LHS says it only supportsuserTypewhich is not true, should be some kind of expression -
callableReferencementions an optionaltypeArgumentsat the end. Is there anywhere I can see an example of this? -
classModifieris 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 = 1is 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
interfacedecl, but there is a parser corpus test atrecovery/InterfaceInExpressionPosition.ktthat 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.