From 21ffa9b582ec483a6209b70971d982e923931a7a Mon Sep 17 00:00:00 2001 From: Xanonymous Date: Tue, 6 Aug 2024 07:16:15 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20primaryConstructor=20of?= =?UTF-8?q?=20a=20Parser=20is=20actually=20not=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/tw/xcc/gumtree/antlrBridge/GumTreeConverter.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/antlr-bridge/src/main/kotlin/tw/xcc/gumtree/antlrBridge/GumTreeConverter.kt b/antlr-bridge/src/main/kotlin/tw/xcc/gumtree/antlrBridge/GumTreeConverter.kt index b1c8867..a553115 100644 --- a/antlr-bridge/src/main/kotlin/tw/xcc/gumtree/antlrBridge/GumTreeConverter.kt +++ b/antlr-bridge/src/main/kotlin/tw/xcc/gumtree/antlrBridge/GumTreeConverter.kt @@ -12,6 +12,7 @@ import org.antlr.v4.runtime.Lexer import org.antlr.v4.runtime.Parser import org.antlr.v4.runtime.ParserRuleContext import org.antlr.v4.runtime.Token +import org.antlr.v4.runtime.TokenStream import org.antlr.v4.runtime.Vocabulary import org.antlr.v4.runtime.tree.Tree import tw.xcc.gumtree.model.GumTree @@ -20,7 +21,6 @@ import java.io.InputStream import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract -import kotlin.reflect.full.primaryConstructor class GumTreeConverter(private val vocabulary: Vocabulary, private val ruleNames: List) { private fun createSingleGumTreeNodeOfTokenFrom(token: Token): GumTree = @@ -94,8 +94,9 @@ class GumTreeConverter(private val vocabulary: Vocabulary, private val ruleNames val lexer = lexerFactory(charStream) val tokenStream = CommonTokenStream(lexer) val parser = - P::class.primaryConstructor?.call(tokenStream) - ?: error("Provided Parser should have primary constructor") + P::class.constructors.find { + it.parameters.size == 1 && it.parameters.first().type.classifier == TokenStream::class + }?.call(tokenStream) ?: error("Provided Parser should have primary constructor") val firstGrammarEntry = parser.firstGrammarParseFunction() val converter = GumTreeConverter(parser.vocabulary, parser.ruleNames.toList())