Adding grammar tokens

I was looking at changing some understand rules into grammar rules, but I’m hitting a limitation; it doesn’t look like you can add your own grammar tokens, like [object] or [single].

I’d like a way to transform this:

(understand [brood | $Words] as [brood $Obj])
    *(understand $Words as single object $Obj preferably { (memory $_) })

into this:

(grammar [brood [memory]] for [brood $])

With some way of identifying that token [memory] is a single object, preferably with the memory trait.

Actually looks like grammar transformer and match grammar token might be the trick, even if not documented.

Yes, just pick an unused integer (for instance in the 90–99 range) for the internal representation. I should document this.

3 Likes