Context: I'm porting an existing handwritten parser to use parsus.
Right now, parsus only supports fully parsing a string. If the string doesn't completely parse, it returns an error noting an index noting how far it was able to parse.
It would be very helpful if it also returned what it had succesfully parsed up until that point.
Because it doesn't have that feature, I've resorted to this hack:
class Grammar<Expression>() {
// ... the grammar I've ported over
abstract val bind: Parser<T>
private val any by token { input, fromIndex -> input.length - fromIndex }
val remain by parser {
val v = bind() to currentOffset
while (true) {
when (val t = currentToken?.token) {
EofToken, null -> break
else -> skip(t)
}
}
v
}
}
Context: I'm porting an existing handwritten parser to use parsus.
Right now, parsus only supports fully parsing a string. If the string doesn't completely parse, it returns an error noting an index noting how far it was able to parse.
It would be very helpful if it also returned what it had succesfully parsed up until that point.
Because it doesn't have that feature, I've resorted to this hack: