<@U0FLRRSQK> I was sent here to you by David Dento...
# forkhandles
a
@Dmitry Kandalov I was sent here to you by David Denton. Given this parser4k parser, do you know why it can parse
REMOVE foo
, but not
REMOVE foo bar
? I thought the
oneOrMore
in
Remove
would catch multiple space-separated tokens, but I get this error:
Copy code
parser4k.InputIsNotConsumed: 
REMOVE foo bar
          ^
Copy code
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 }
        }
    }
}