TalAter/annyang

is there a documented syntax diagram for the command template?

sdetweil opened this issue · 3 comments

I want to extend an app I wrote, which copied an example from another app.
it has optional words

it has

 (ask) appname (to) *

I want to have both tell and ask as optional first words.

but I have never seen a full syntax diagram of what is allowed
is it
(ask|tell)
or
(ask) (tell)
or something else?

sorry for submitting an issue.. I cannot find any doc that describes this

The basic way to define commands does not support multiple options for an optional parameter. You can see the full explanation of what is supported in the documentation.

To achieve what you want you can either define two separate commands that point at the same function, like this:

var commands = {
  '(ask) appname (to) *do': myFunction,
  '(tell) appname (to) *do': myFunction,
};

Or better yet, use a regular expression to define your command syntax.

thanks but the 'doc' doesn't even describe what 'optional' looks like
(surround by ellipsis)

this works correctly

(ask) (tell) appname (to) *

Just note that your solution of (ask) (tell) appname (to) * isn't just ask or tell. It would accept ask and/or tell, but only in that specific order (i.e., it will accept the sentence ask tell appname to do but not tell ask appname to do). It gets the job done, but it also seems to me like a solution that could lead to hard to debug issues down the line.