Skip to content

Commit

Permalink
fix: πŸ› remove reflection usage and receive lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed Aug 6, 2024
1 parent 21ffa9b commit 95558cf
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GumTreeConverter(private val vocabulary: Vocabulary, private val ruleNames
suspend inline fun <reified L : Lexer, reified P : Parser> convertFrom(
inputStream: InputStream,
crossinline lexerFactory: (CharStream) -> L,
crossinline parserFactory: (TokenStream) -> P,
crossinline firstGrammarParseFunction: P.() -> ParserRuleContext
): GumTree {
contract {
Expand All @@ -93,10 +94,7 @@ class GumTreeConverter(private val vocabulary: Vocabulary, private val ruleNames

val lexer = lexerFactory(charStream)
val tokenStream = CommonTokenStream(lexer)
val parser =
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 parser = parserFactory(tokenStream)

val firstGrammarEntry = parser.firstGrammarParseFunction()
val converter = GumTreeConverter(parser.vocabulary, parser.ruleNames.toList())
Expand Down

0 comments on commit 95558cf

Please sign in to comment.