CLI: new optimize() method in CommandToken

optimize() will transform a parse tree into a more efficient equivalient
variant. This will be useful to prevent redundant expensive API calls
in autocomplete.

Signed-off-by: Guillermo Ontanon <guillermo@midokura.jp>
CLI: optimize autocomplete

Use the new optimize() tree transformations in autocomplete by merging
all command patterns into one grammar and invoking optimize() on it. Also
during complete() calls, trim the parse tree in Or nodes, and use the
resulting trimmed tree until clear() is called on the CompletionCache.

Signed-off-by: Guillermo Ontanon <guillermo@midokura.jp>