Skip to content

Commit

Permalink
fix: πŸ› primaryConstructor of a Parser is actually not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed Aug 6, 2024
1 parent b44d0a3 commit 21ffa9b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>) {
private fun createSingleGumTreeNodeOfTokenFrom(token: Token): GumTree =
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 21ffa9b

Please sign in to comment.