Andrew O'Hara
08/26/2023, 10:26 PMREMOVE foo, but not REMOVE foo bar? I thought the oneOrMore in Remove would catch multiple space-separated tokens, but I get this error:
parser4k.InputIsNotConsumed:
REMOVE foo bar
^
object DynamoDbUpdateGrammar {
private val cache = OutputCache<Expr>()
fun parse(expression: String): Expr = expression.parseWith(expr)
private val expr: Parser<Expr> = oneOf(
//set
Remove(::expr).with(cache),
// add
// delete
).reset(cache)
}
private val UpdateAttributeName : ExprFactory = {
Tokens.identifier.map { name -> Expr { AttributeName.of(name) } }
}
private val Remove: ExprFactory = { parser ->
inOrder(
token("REMOVE"),
oneOrMore(
UpdateAttributeName(parser),
)
).skipFirst().map { names ->
Expr { item ->
val attributeNames = names.map { it.eval(item) }
item.item.filterKeys { it !in attributeNames }
}
}
}