mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Allow strings to span multiple lines - newlines and any leading
whitespace are removed, as well as any following comments that couldn't be part of a format. This allows long formats or other strings to be annotated and indented.
This commit is contained in:
		
							
								
								
									
										41
									
								
								cmd-parse.y
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								cmd-parse.y
									
									
									
									
									
								
							@@ -1494,24 +1494,33 @@ yylex_token(int ch)
 | 
				
			|||||||
	buf = xmalloc(1);
 | 
						buf = xmalloc(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (;;) {
 | 
						for (;;) {
 | 
				
			||||||
		/*
 | 
							/* EOF or \n are always the end of the token. */
 | 
				
			||||||
		 * EOF or \n are always the end of the token. If inside quotes
 | 
							if (ch == EOF || (state == NONE && ch == '\n'))
 | 
				
			||||||
		 * they are an error.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		if (ch == EOF || ch == '\n') {
 | 
					 | 
				
			||||||
			if (state != NONE)
 | 
					 | 
				
			||||||
				goto error;
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Whitespace or ; ends a token unless inside quotes. */
 | 
							/* Whitespace or ; or } ends a token unless inside quotes. */
 | 
				
			||||||
		if ((ch == ' ' || ch == '\t' || ch == ';' || ch == '}') &&
 | 
							if ((ch == ' ' || ch == '\t' || ch == ';' || ch == '}') &&
 | 
				
			||||||
		    state == NONE)
 | 
							    state == NONE)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/* Spaces and comments inside quotes after \n are removed. */
 | 
				
			||||||
		 * \ ~ and $ are expanded except in single quotes.
 | 
							if (ch == '\n' && state != NONE) {
 | 
				
			||||||
		 */
 | 
								while ((ch = yylex_getc()) == ' ' || ch == '\t')
 | 
				
			||||||
 | 
									/* nothing */;
 | 
				
			||||||
 | 
								if (ch != '#')
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								ch = yylex_getc();
 | 
				
			||||||
 | 
								if (strchr(",#{}:", ch) != NULL) {
 | 
				
			||||||
 | 
									yylex_ungetc(ch);
 | 
				
			||||||
 | 
									ch = '#';
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									while ((ch = yylex_getc()) != '\n' && ch != EOF)
 | 
				
			||||||
 | 
										/* nothing */;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* \ ~ and $ are expanded except in single quotes. */
 | 
				
			||||||
		if (ch == '\\' && state != SINGLE_QUOTES) {
 | 
							if (ch == '\\' && state != SINGLE_QUOTES) {
 | 
				
			||||||
			if (!yylex_token_escape(&buf, &len))
 | 
								if (!yylex_token_escape(&buf, &len))
 | 
				
			||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
@@ -1530,9 +1539,7 @@ yylex_token(int ch)
 | 
				
			|||||||
		if (ch == '}' && state == NONE)
 | 
							if (ch == '}' && state == NONE)
 | 
				
			||||||
			goto error;  /* unmatched (matched ones were handled) */
 | 
								goto error;  /* unmatched (matched ones were handled) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/* ' and " starts or end quotes (and is consumed). */
 | 
				
			||||||
		 * ' and " starts or end quotes (and is consumed).
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		if (ch == '\'') {
 | 
							if (ch == '\'') {
 | 
				
			||||||
			if (state == NONE) {
 | 
								if (state == NONE) {
 | 
				
			||||||
				state = SINGLE_QUOTES;
 | 
									state = SINGLE_QUOTES;
 | 
				
			||||||
@@ -1554,9 +1561,7 @@ yylex_token(int ch)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/* Otherwise add the character to the buffer. */
 | 
				
			||||||
		 * Otherwise add the character to the buffer.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		yylex_append1(&buf, &len, ch);
 | 
							yylex_append1(&buf, &len, ch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	skip:
 | 
						skip:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user