diff options
author | nicm <nicm> | 2019-06-14 12:04:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2019-06-14 16:04:52 +0100 |
commit | 0a94dbe051042cba644240ab0361319744ee4875 (patch) | |
tree | 863c82e61d3596dfdf1dd1e0a1f0ead9e00eb314 /cmd-parse.y | |
parent | ebc9dcb3bb71c2c8640466d84897971648a43845 (diff) | |
download | rtmux-0a94dbe051042cba644240ab0361319744ee4875.tar.gz rtmux-0a94dbe051042cba644240ab0361319744ee4875.tar.bz2 rtmux-0a94dbe051042cba644240ab0361319744ee4875.zip |
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 'cmd-parse.y')
-rw-r--r-- | cmd-parse.y | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/cmd-parse.y b/cmd-parse.y index 6feeb35a..9a2c2cfd 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -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; @@ -102,7 +103,7 @@ static void cmd_parse_free_commands(struct cmd_parse_commands *); %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 @@ -158,7 +159,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; @@ -950,12 +960,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(); @@ -995,11 +1008,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); @@ -1026,6 +1039,7 @@ yylex(void) } if (*cp == '\0') return (TOKEN); + ps->condition = 1; if (strcmp(yylval.token, "%if") == 0) { free(yylval.token); return (IF); |