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
how would i design the and of a parser combinator so that i do not need to create an infinite number of classes for it
example (probably incorrect)
/*
val A = F1("1")
val B = F1("2")
val C = F1("3")
val C: F1AndF1 = A.and(B)
val D: F1AndF1 = B.and(D)
val E: F1AndF1AndF2AndF2 = C.and(D)
// ...
*/
class F1(left: Any) {
// F1 And F1
infix fun and(right: F1) = F1AndF1(this, right)
}
class F1AndF1(left: F1, right: F1) {
// F1AndF1 And F1AndF1
infix fun and(right: F1AndF1) = F1AndF1AndF2AndF2(this, right)
}
class F1AndF1AndF2AndF2(left: F1AndF1, right: F1AndF1) {
// F1AndF1AndF2AndF2 And F1AndF1AndF2AndF2
infix and(right: F1AndF1AndF2AndF2) = F1AndF1AndF2AndF2AndF3AndF3AndF4AndF4(this, right)
}
// and so on for ever
The text was updated successfully, but these errors were encountered:
I couldn't find a way to do that preserving type safety. My and combinators are based on generated tuples and functions for adding another component, for each number of components (up to 16).
how would i design the
and
of a parser combinator so that i do not need to create an infinite number of classes for itexample (probably incorrect)
The text was updated successfully, but these errors were encountered: