Skip to content

ANTLR parser fails when a newline exists inside an expression interpolated in a string #40

@ondrej

Description

@ondrej

Hi team,

I noticed a problem when parsing files using the official Kotlin ANTLR grammar from https://kotlinlang.org/docs/reference/grammar.html.

This parses OK:

val numbers = mapOf("1" to 1, "2" to 2, "3" to 3)
println("output: ${numbers.entries.joinToString { "${it.key}: ${it.value}" }}")

This fails (but compiles without issue in e.g. Android Studio):

val numbers = mapOf("1" to 1, "2" to 2, "3" to 3)
println("output: ${
    numbers.entries.joinToString { "${it.key}: ${it.value}" }}")

This issue is possibly related to https://youtrack.jetbrains.com/issue/KT-26077. When adding parentheses around the expression, ANTRL does parse the statement just fine. Assuming this is the same issue, and since KT-26077 hasn't been touched in over a year, is there anything I might be able to do in the short term to work around this?

Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions