You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val typePrefix by (type *-znws * parser(this::referenceParser) *-znws *-assign)
// ...val traitFunction by parser(this::functionSignature) use { CyanTraitDeclaration.Element.Function(CyanFunctionDeclaration(this, null), span) }
val traitProperty by structProperty use { CyanTraitDeclaration.Element.Property(ident, type, span) }
val traitElement by (traitFunction or traitProperty)
val traitDeclaration by (typePrefix *-znws *-trait *-znws *-lcur *-znws * (separatedTerms(traitElement, newLine)
.use { toTypedArray() }) *-znws *-rcur) use { CyanTraitDeclaration(t2, t3, span(t1, t3.last())) }
Yields the following exception :
com.github.h0tk3y.betterParse.utils.Tuple2 cannot be cast to com.github.h0tk3y.betterParse.lexer.TokenMatch
java.lang.ClassCastException: com.github.h0tk3y.betterParse.utils.Tuple2 cannot be cast to com.github.h0tk3y.betterParse.lexer.TokenMatch
at cyan.compiler.parser.CyanModuleParser$$special$$inlined$and2Operator$2.invoke(andFunctions.kt:9)
at cyan.compiler.parser.CyanModuleParser$$special$$inlined$and2Operator$2.invoke(andFunctions.kt)
at com.github.h0tk3y.betterParse.combinators.AndCombinator.tryParse(AndCombinator.kt:60)
at com.github.h0tk3y.betterParse.combinators.MapCombinator.tryParse(MapCombinator.kt:14)
at com.github.h0tk3y.betterParse.combinators.OrCombinator.tryParse(OrCombinator.kt:13)
at com.github.h0tk3y.betterParse.combinators.AndCombinator.tryParse(AndCombinator.kt:40)
at com.github.h0tk3y.betterParse.combinators.AndCombinator.tryParse(AndCombinator.kt:40)
at com.github.h0tk3y.betterParse.combinators.SeparatedCombinator.tryParse(Separated.kt:16)
at com.github.h0tk3y.betterParse.combinators.MapCombinator.tryParse(MapCombinator.kt:14)
at com.github.h0tk3y.betterParse.combinators.MapCombinator.tryParse(MapCombinator.kt:14)
at com.github.h0tk3y.betterParse.combinators.AndCombinator.tryParse(AndCombinator.kt:40)
at com.github.h0tk3y.betterParse.combinators.MapCombinator.tryParse(MapCombinator.kt:14)
at com.github.h0tk3y.betterParse.parser.ParserKt.tryParseToEnd(Parser.kt:18)
at com.github.h0tk3y.betterParse.parser.ParserKt.parseToEnd(Parser.kt:29)
at com.github.h0tk3y.betterParse.grammar.GrammarKt.parseToEnd(Grammar.kt:65)
at cyan.compiler.parser.StatementsTest.doTest(StatementsTest.kt:29)
at cyan.compiler.parser.StatementsTest.access$doTest(StatementsTest.kt:24)
at cyan.compiler.parser.StatementsTest$TypeDeclarations.trait with one function(StatementsTest.kt:34)
<...>
From a quick look into the code, it seems like in andFunctions.kt this is function is called for the first * operator in typePrefix * -znws * -trait :
But looking at the debugger, I see values packed into a tuple and not "flat mapped" (don't know if that makess sense, couldn't think of a better way to put it) :
Here, t1 of element 0 (which is the result of typePrefix) is the match for token type, and t2 is from parser(this::referenceParser). Yet, the code thinks t1 is element 0, and t2 is element 1, while they are in fact both inside element 0. This obviously causes a ClassCastException when it tries to cast element 0 into what I assume reified type parameter T1 is (TokenMatch).
I couldn't figure out which part of the library laid out those elements like that, which is where I'm stuck.
I hope this all made sense, and thanks in advance.
The text was updated successfully, but these errors were encountered:
Benjozork
changed the title
ClassCastException when combinding a Tuple2 parser
ClassCastException when combining a Tuple2 parser
Aug 22, 2020
I think the issue is that the SkipParser throws away type information, so the reified types don't propagate, and for some reason Kotlin doesn't complain.
Hey, it's been a long time since I worked on cyan and I think I just reshuffled the parser a bit to where it wasn't causing an issue and forgot about it. Sorry I don't have a more useful solution 😬
Hello,
The following code :
Yields the following exception :
From a quick look into the code, it seems like in
andFunctions.kt
this is function is called for the first * operator intypePrefix * -znws * -trait
:But looking at the debugger, I see values packed into a tuple and not "flat mapped" (don't know if that makess sense, couldn't think of a better way to put it) :
Here,
t1
of element 0 (which is the result oftypePrefix
) is the match for tokentype
, andt2
is fromparser(this::referenceParser)
. Yet, the code thinkst1
is element 0, andt2
is element 1, while they are in fact both inside element 0. This obviously causes aClassCastException
when it tries to cast element0
into what I assume reified type parameterT1
is (TokenMatch
).I couldn't figure out which part of the library laid out those elements like that, which is where I'm stuck.
I hope this all made sense, and thanks in advance.
The text was updated successfully, but these errors were encountered: