As an experiment I tried ChatGPT4 :melting_face: I...
# forkhandles
d
As an experiment I tried ChatGPT4 đŸ«  It doesn’t know about parser4k or forkhandles (I guess they need more likes on the Internet). But after copy-pasting readme.md into it one section at a time, it was able to give a correct answer đŸ˜± I don’t mean it as “here is how to use Google”, just curious/impressed that it was able to do it. Here is what ChatGPT says: --------------- The problem you’re facing is that the
oneOrMore
parser does capture multiple space-separated tokens, but it expects them to be directly adjacent to one another. In other words, it’s expecting input like
REMOVE foofoofoo
instead of
REMOVE foo bar
because there’s no parser defined to handle the space between the tokens. To solve this, you can explicitly specify that you’re expecting space-separated tokens. Here’s how you can modify the
Remove
parser to handle multiple space-separated tokens:
Copy code
private val Remove: ExprFactory = { parser ->
    inOrder(
        token("REMOVE"),
        oneOrMore(
            inOrder(
                Tokens.space.optional(),
                UpdateAttributeName(parser)
            ).skipFirst()
        )
    ).skipFirst().map { names ->
        Expr { item ->
            val attributeNames = names.map { it.eval(item) }
            item.item.filterKeys { it !in attributeNames }
        }
    }
}
Here’s a breakdown of the changes: 1. Inside the
oneOrMore
parser, I wrapped the
UpdateAttributeName(parser)
with another
inOrder
parser. 2. This new
inOrder
parser starts with
Tokens.space.optional()
, which tries to parse a space but doesn’t fail if there isn’t one. 3. I used
.skipFirst()
to make sure the optional space doesn’t get included in the parsed result. Now,
Remove
should be able to parse inputs like
REMOVE foo bar
.