From 763bb498a6dc51115d41ae30f8a04cef08461c01 Mon Sep 17 00:00:00 2001 From: Dennis Rieks Date: Tue, 11 May 2021 22:05:22 +0200 Subject: [PATCH] fixed parsing of companion object refs #38 --- .../kotlin/kotlinx/ast/common/klass/Klass.kt | 1 + .../kotlin/common/summary/KotlinTreeMapBuilder.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/common/src/commonMain/kotlin/kotlinx/ast/common/klass/Klass.kt b/common/src/commonMain/kotlin/kotlinx/ast/common/klass/Klass.kt index 81c1f8b..eaf8fc3 100644 --- a/common/src/commonMain/kotlin/kotlinx/ast/common/klass/Klass.kt +++ b/common/src/commonMain/kotlin/kotlinx/ast/common/klass/Klass.kt @@ -274,6 +274,7 @@ private val klassDeclarationKeywords: Map = mapOf( "VAL" to "val", "CLASS" to "class", "INTERFACE" to "interface", + "COMPANION" to "companion object", "OBJECT" to "object", "primaryConstructor" to "constructor", "valueArgument" to "argument", diff --git a/grammar-kotlin-parser-common/src/commonMain/kotlin/kotlinx/ast/grammar/kotlin/common/summary/KotlinTreeMapBuilder.kt b/grammar-kotlin-parser-common/src/commonMain/kotlin/kotlinx/ast/grammar/kotlin/common/summary/KotlinTreeMapBuilder.kt index 41f5233..84a29c2 100644 --- a/grammar-kotlin-parser-common/src/commonMain/kotlin/kotlinx/ast/grammar/kotlin/common/summary/KotlinTreeMapBuilder.kt +++ b/grammar-kotlin-parser-common/src/commonMain/kotlin/kotlinx/ast/grammar/kotlin/common/summary/KotlinTreeMapBuilder.kt @@ -344,6 +344,19 @@ val kotlinTreeMapBuilder = TreeMapBuilder() // (NL* COLON NL* delegationSpecifiers)? // (NL* classBody)? // ; + .convert( + filter = byDescription("companionObject") + ) { node: AstNode -> + toKlassDeclaration(node) { ast -> + astContinue( + ast.filter( + setOf( + "classBody", + ) + ) + ) + }.toAstList() + } // functionValueParameters // : LPAREN NL* (functionValueParameter (NL* COMMA NL* functionValueParameter)* (NL* COMMA)?)? NL* RPAREN