Dmitry Kandalov
08/27/2023, 10:07 AM.joinedWith(" ") , where ” ” is the separator between REMOVE arguments.
I wasn’t able to run your example directly, so I simplified it a bit 🙈 Not sure why you needed ExprFactory 🤔
Given “REMOVE foo bar”, token("REMOVE") matches “REMOVE ” (including whitespace), oneOrMore(identifier).joinedWith(" ") matches “foo” and “bar”.
import parser4k.OutputCache
import parser4k.Parser
import parser4k.commonparsers.Tokens.identifier
import parser4k.commonparsers.joinedWith
import parser4k.commonparsers.token
import parser4k.inOrder
import parser4k.map
import parser4k.oneOf
import parser4k.oneOrMore
import parser4k.parseWith
import parser4k.reset
import parser4k.skipFirst
import parser4k.with
object DynamoDbUpdateGrammar {
private val cache = OutputCache<Expr>()
fun parse(expression: String): Expr = expression.parseWith(expr)
private val expr: Parser<Expr> = oneOf(
Remove.with(cache),
).reset(cache)
}
data class Expr(val id: String)
private val Remove =
inOrder(
token("REMOVE"),
oneOrMore(identifier).joinedWith(" ")
).skipFirst().map { names ->
Expr(names.joinToString())
}
fun main() {
println(DynamoDbUpdateGrammar.parse("REMOVE foo bar"))
}