diff options
author | 2020-06-04 08:30:44 +0000 | |
---|---|---|
committer | 2020-06-04 08:30:44 +0000 | |
commit | af9d9f3be9a069f6c3527239976cad6a3f109087 (patch) | |
tree | 001317fd67fac8f1efa3f8361c60bbe22958985b | |
parent | Instead of using a custom parse function to process {}, treat it as a (diff) | |
download | wireguard-openbsd-af9d9f3be9a069f6c3527239976cad6a3f109087.tar.xz wireguard-openbsd-af9d9f3be9a069f6c3527239976cad6a3f109087.zip |
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.
-rw-r--r-- | usr.bin/tmux/cmd-parse.y | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/usr.bin/tmux/cmd-parse.y b/usr.bin/tmux/cmd-parse.y index 639d7709020..0c5e0f8731d 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.28 2020/06/04 07:12:05 nicm Exp $ */ +/* $OpenBSD: cmd-parse.y,v 1.29 2020/06/04 08:30:44 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1494,24 +1494,33 @@ yylex_token(int ch) buf = xmalloc(1); for (;;) { - /* - * EOF or \n are always the end of the token. If inside quotes - * they are an error. - */ - if (ch == EOF || ch == '\n') { - if (state != NONE) - goto error; + /* EOF or \n are always the end of the token. */ + if (ch == EOF || (state == NONE && ch == '\n')) break; - } - /* Whitespace or ; ends a token unless inside quotes. */ + /* Whitespace or ; or } ends a token unless inside quotes. */ if ((ch == ' ' || ch == '\t' || ch == ';' || ch == '}') && state == NONE) break; - /* - * \ ~ and $ are expanded except in single quotes. - */ + /* Spaces and comments inside quotes after \n are removed. */ + 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 (!yylex_token_escape(&buf, &len)) goto error; @@ -1530,9 +1539,7 @@ yylex_token(int ch) if (ch == '}' && state == NONE) 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 (state == NONE) { 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); skip: |