Optional slots?
See original GitHub issueIs your feature request related to a problem? Please describe. I’m super impressed by your product. Really amazing offering, and great experience.
My question: is it possible to make slot optional for matching? I.e. allow the expression to be matched even if slot was not matched? My example
[open, extend, slide out] (the, a) $zone:zone (hydraulic, hydraulics, slide out, slide outs, room, section, slide, slides, cylinder, cylinders, areas, areas) (completely, entirely, fully, to the max, hundred percent, to the limit, as much as possible)
So I have only one meaningful $zone slot here, but also I have a set of words that I don’t care that much for, but they can be in the command. Because i have a bunch of intents and commands reusing those sets, i’d love to turn them into slots for reuse, while basically ignoring them later. The problem is that I’d like the command to work even if they are not matched.,
Describe the solution you’d like
($zone:zone)
type syntax for optional slots
Describe alternatives you’ve considered I can use multiple separate commands with or without slots, but there’s combinatorial complexity to support them all. I can also keep listing them as is which makes commands hard to parse visually
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
Yes that is correct,
Macros
andSlots
can be used in the same way throughout theexpressions
, and follow the same rules withinChoices
andOptionals
. The only functional difference is if the matched value is present in the output. In your case with themin
andmax
, since you want the output,Slots
inside anOptional
orChoice
is definitely the way to go.Macros
are good to use as an alias for aChoice
(eg.@brew
instead of[make, brew, pour]
), to reduce writing the same entries in multipleexpressions
. But obviously because they can be embedded in otherChoice
andOptional
constructs, they are quite flexible.I’m happy to say that we’ve implemented two additional features that should help with some of your concerns. Firstly, the addition of “Macros”, and secondly the ability to use both Macros and Slots in Optional and choice constructs. Full documentation is coming but in the meantime, some examples should be enough to get you started.
For the example you provided in the issue:
[open, extend, slide out] (the, a) $zone:zone (hydraulic, hydraulics, slide out, slide outs, room, section, slide, slides, cylinder, cylinders, areas, areas) (completely, entirely, fully, to the max, hundred percent, to the limit, as much as possible)
You can now reduce it to something like:
@openOptions (the, a) $zone:zone (@terms) (@stateMax)
with your YAML as so:Macros and Slots can be mixed and matched within the Optional and Choice constructs:
These changes are live and hopefully this should help with more complex grammers like you have mentioned here. As usual, if you you run into any additional problems please feel free to open another issue.