diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-06-14 12:04:12 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-06-14 12:04:12 +0000 |
commit | 26336d0eeab080b64e6a80dcb54bd45d7331b456 (patch) | |
tree | fd7168ecd2733fb18562c8f6afda0fbcd755ef5a /usr.bin | |
parent | c7715d886024f8ba1190c621dae71c116531fb83 (diff) |
A couple of minor parser changes around conditions: 1) only treat #{
specially after a condition, otherwise as a comment (which is more as
most people expect) 2) allow formats to be quoted after a condition.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-parse.y | 28 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 8 |
2 files changed, 25 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-parse.y b/usr.bin/tmux/cmd-parse.y index ca3592c7ff3..77504460744 100644 --- a/usr.bin/tmux/cmd-parse.y +++ b/usr.bin/tmux/cmd-parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-parse.y,v 1.14 2019/06/05 20:00:53 nicm Exp $ */ +/* $OpenBSD: cmd-parse.y,v 1.15 2019/06/14 12:04:11 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -59,6 +59,7 @@ struct cmd_parse_state { size_t len; size_t off; + int condition; int eol; int eof; struct cmd_parse_input *input; @@ -104,7 +105,7 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int, %token ENDIF %token <token> FORMAT TOKEN EQUALS -%type <token> argument expanded +%type <token> argument expanded format %type <arguments> arguments %type <flag> if_open if_elif %type <elif> elif elif1 @@ -160,7 +161,16 @@ statement : condition } } -expanded : FORMAT +format : FORMAT + { + $$ = $1; + } + | TOKEN + { + $$ = $1; + } + +expanded : format { struct cmd_parse_state *ps = &parse_state; struct cmd_parse_input *pi = ps->input; @@ -967,12 +977,15 @@ yylex(void) { struct cmd_parse_state *ps = &parse_state; char *token, *cp; - int ch, next; + int ch, next, condition; if (ps->eol) ps->input->line++; ps->eol = 0; + condition = ps->condition; + ps->condition = 0; + for (;;) { ch = yylex_getc(); @@ -1012,11 +1025,11 @@ yylex(void) if (ch == '#') { /* - * #{ opens a format; anything else is a comment, - * ignore up to the end of the line. + * #{ after a condition opens a format; anything else + * is a comment, ignore up to the end of the line. */ next = yylex_getc(); - if (next == '{') { + if (condition && next == '{') { yylval.token = yylex_format(); if (yylval.token == NULL) return (ERROR); @@ -1043,6 +1056,7 @@ yylex(void) } if (*cp == '\0') return (TOKEN); + ps->condition = 1; if (strcmp(yylval.token, "%if") == 0) { free(yylval.token); return (IF); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 29a2e438c0c..4b13d346989 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.665 2019/06/13 21:04:21 jmc Exp $ +.\" $OpenBSD: tmux.1,v 1.666 2019/06/14 12:04:11 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 13 2019 $ +.Dd $Mdocdate: June 14 2019 $ .Dt TMUX 1 .Os .Sh NAME @@ -582,9 +582,9 @@ or .Ql %endif . For example: .Bd -literal -offset indent -%if #{==:#{host},myhost} +%if "#{==:#{host},myhost}" set -g status-style bg=red -%elif #{==:#{host},myotherhost} +%elif "#{==:#{host},myotherhost}" set -g status-style bg=green %else set -g status-style bg=blue |