From 88cf98d9c45b00be04a4e92738b02c11ccf2d0ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 15:52:03 +0200 Subject: [PATCH] states work: Documents the various states. --- highlighters/main/main-highlighter.zsh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2803eb3..2cc35f8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -103,6 +103,20 @@ _zsh_highlight_main_highlighter() $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS ) + # State machine + # + # The states are: + # - :start: Command word + # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i") + # - :sudo_arg: The argument to a sudo leading-dash option that takes one, + # when given as a separate word; i.e., "foo" in "-u foo" (two + # words) but not in "-ufoo" (one word). + # - :regular: "Not a command word". + # Mainly used to detect premature termination of commands. + # + # The tokens are always added with both leading and trailing colons to serve as + # word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/} + # will DTRT regardless of how many elements or repetitions $x has.. local this_word=':start:' next_word for arg in ${(z)buf}; do next_word=':regular:'