mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							
								
								
									
										26
									
								
								cmd-parse.y
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								cmd-parse.y
									
									
									
									
									
								
							@@ -59,6 +59,7 @@ struct cmd_parse_state {
 | 
				
			|||||||
	size_t				 len;
 | 
						size_t				 len;
 | 
				
			||||||
	size_t				 off;
 | 
						size_t				 off;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int				 condition;
 | 
				
			||||||
	int				 eol;
 | 
						int				 eol;
 | 
				
			||||||
	int				 eof;
 | 
						int				 eof;
 | 
				
			||||||
	struct cmd_parse_input		*input;
 | 
						struct cmd_parse_input		*input;
 | 
				
			||||||
@@ -102,7 +103,7 @@ static void	 cmd_parse_free_commands(struct cmd_parse_commands *);
 | 
				
			|||||||
%token ENDIF
 | 
					%token ENDIF
 | 
				
			||||||
%token <token> FORMAT TOKEN EQUALS
 | 
					%token <token> FORMAT TOKEN EQUALS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%type <token> argument expanded
 | 
					%type <token> argument expanded format
 | 
				
			||||||
%type <arguments> arguments
 | 
					%type <arguments> arguments
 | 
				
			||||||
%type <flag> if_open if_elif
 | 
					%type <flag> if_open if_elif
 | 
				
			||||||
%type <elif> elif elif1
 | 
					%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_state	*ps = &parse_state;
 | 
				
			||||||
			struct cmd_parse_input	*pi = ps->input;
 | 
								struct cmd_parse_input	*pi = ps->input;
 | 
				
			||||||
@@ -950,12 +960,15 @@ yylex(void)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	struct cmd_parse_state	*ps = &parse_state;
 | 
						struct cmd_parse_state	*ps = &parse_state;
 | 
				
			||||||
	char			*token, *cp;
 | 
						char			*token, *cp;
 | 
				
			||||||
	int			 ch, next;
 | 
						int			 ch, next, condition;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ps->eol)
 | 
						if (ps->eol)
 | 
				
			||||||
		ps->input->line++;
 | 
							ps->input->line++;
 | 
				
			||||||
	ps->eol = 0;
 | 
						ps->eol = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						condition = ps->condition;
 | 
				
			||||||
 | 
						ps->condition = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (;;) {
 | 
						for (;;) {
 | 
				
			||||||
		ch = yylex_getc();
 | 
							ch = yylex_getc();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -995,11 +1008,11 @@ yylex(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if (ch == '#') {
 | 
							if (ch == '#') {
 | 
				
			||||||
			/*
 | 
								/*
 | 
				
			||||||
			 * #{ opens a format; anything else is a comment,
 | 
								 * #{ after a condition opens a format; anything else
 | 
				
			||||||
			 * ignore up to the end of the line.
 | 
								 * is a comment, ignore up to the end of the line.
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			next = yylex_getc();
 | 
								next = yylex_getc();
 | 
				
			||||||
			if (next == '{') {
 | 
								if (condition && next == '{') {
 | 
				
			||||||
				yylval.token = yylex_format();
 | 
									yylval.token = yylex_format();
 | 
				
			||||||
				if (yylval.token == NULL)
 | 
									if (yylval.token == NULL)
 | 
				
			||||||
					return (ERROR);
 | 
										return (ERROR);
 | 
				
			||||||
@@ -1026,6 +1039,7 @@ yylex(void)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			if (*cp == '\0')
 | 
								if (*cp == '\0')
 | 
				
			||||||
				return (TOKEN);
 | 
									return (TOKEN);
 | 
				
			||||||
 | 
								ps->condition = 1;
 | 
				
			||||||
			if (strcmp(yylval.token, "%if") == 0) {
 | 
								if (strcmp(yylval.token, "%if") == 0) {
 | 
				
			||||||
				free(yylval.token);
 | 
									free(yylval.token);
 | 
				
			||||||
				return (IF);
 | 
									return (IF);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.1
									
									
									
									
									
								
							@@ -583,9 +583,9 @@ or
 | 
				
			|||||||
.Ql %endif .
 | 
					.Ql %endif .
 | 
				
			||||||
For example:
 | 
					For example:
 | 
				
			||||||
.Bd -literal -offset indent
 | 
					.Bd -literal -offset indent
 | 
				
			||||||
%if #{==:#{host},myhost}
 | 
					%if "#{==:#{host},myhost}"
 | 
				
			||||||
set -g status-style bg=red
 | 
					set -g status-style bg=red
 | 
				
			||||||
%elif #{==:#{host},myotherhost}
 | 
					%elif "#{==:#{host},myotherhost}"
 | 
				
			||||||
set -g status-style bg=green
 | 
					set -g status-style bg=green
 | 
				
			||||||
%else
 | 
					%else
 | 
				
			||||||
set -g status-style bg=blue
 | 
					set -g status-style bg=blue
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user