-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
object MinimalCalculator {
val cache = OutputCache<BigDecimal>()
fun binaryExpr(s: String) = inOrder(ref { expr }, token(s), ref { expr })
val number = oneOrMore(oneOf('0'..'9')).map { it.joinToString("").toBigDecimal() }.with(cache)
}why not add getValue(k, p, self) for OutputCache:
class OutputCacheBy<out T>(private val p: Parser<T>) {
fun getValue(k: KClass<*>, p: KProperty<*>, self: OutputCache) = p.with(self)
}and then:
object MinimalCalculator {
val cache = OutputCache<BigDecimal>()
fun binaryExpr(s: String) = inOrder(ref { expr }, token(s), ref { expr })
val number = by cache { oneOrMore(oneOf('0'..'9')).map { it.joinToString("").toBigDecimal() } }
}Eh... looks ugly, but in real projects, I think p.with(cache) should have a shorter expression (maybe with a CachedParsers baseclass ext-fun?).
Metadata
Metadata
Assignees
Labels
No labels