summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2016-07-16 09:21:27 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-07-16 09:21:27 (GMT)
commit529fed25f92e04d694c30b3fc6bc8645e2703f4e (patch) (side-by-side diff)
treec575001b35a43ba8f325bf7af60d7b9fb8b8b32a /src
parent6201e61fb932dbe6153f92ede836e07247d04b7c (diff)
downloadgrecs-529fed25f92e04d694c30b3fc6bc8645e2703f4e.tar.gz
grecs-529fed25f92e04d694c30b3fc6bc8645e2703f4e.tar.bz2
Disable adjacent string concatenation.
The adjacent string concatenation feature doesn't work well with multiple-argument statements. The common example (found in GNU pies) is the "env" statement: env "PATH=/sbin:$PATH" "PRELOAD=true" The intent was to pass it two arguments, but in fact they get concatenated into one. To control this, the grecs_parser_options variable is introduced. If it has the GRECS_OPTION_QUOTED_STRING_CONCAT bit set, adjacent string concatenation is enabled. By default it is disabled. The GRECS_OPTION_ADJUST_STRING_LOCATIONS bit controls the way the quoted sring locations are computed. If it is set, the beginning of the string is counted at the first character after the opening double quote, and its end at the character immediately preceding the closing double quote. Otherwise, both double-quote characters are included in the location (the default). The change is backward incompatible. * doc/grecs-syntax.texi: Update. * include/grecs/parser.h (grecs_adjust_string_locations): Remove. (grecs_parser_options): New extern. * src/grecs-lex.l: QSTRING is returned only if GRECS_OPTION_QUOTED_STRING_CONCAT option is set. The GRECS_OPTION_ADJUST_STRING_LOCATIONS option controls string locus adjustment. * src/parser.c (grecs_adjust_string_locations): Remove. (grecs_parser_options): New variable. * tests/Makefile.am: Add strcat.at, stradj.at * tests/testsuite.at: Likewise. * tests/gcffmt.c: New options -strcat and -stradj * tests/stradj.at: New test case. * tests/strcat.at: New test case.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/grecs-lex.l10
-rw-r--r--src/parser.c2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index 113ee88..f7be62f 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -56,6 +56,10 @@ static int ident(void);
static int isemptystr(int off);
static void qstring_locus_fixup(void);
+#define qstring() \
+ ((grecs_parser_options & GRECS_OPTION_QUOTED_STRING_CONCAT) \
+ ? QSTRING : STRING)
+
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
do { \
@@ -116,7 +120,7 @@ P [1-9][0-9]*
grecs_line_add(yytext + 1, yyleng - 2);
yylval.string = grecs_line_finish();
qstring_locus_fixup();
- return QSTRING; }
+ return qstring(); }
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
@@ -138,7 +142,7 @@ P [1-9][0-9]*
grecs_line_add(yytext, yyleng - 1);
yylval.string = grecs_line_finish();
qstring_locus_fixup();
- return QSTRING; }
+ return qstring(); }
/* Multiline strings */
"<<"(-" "?)?\\?{ID}[ \t]*#.*\n |
"<<"(-" "?)?\\?{ID}[ \t]*"//".*\n |
@@ -348,7 +352,7 @@ ident()
static void
qstring_locus_fixup()
{
- if (grecs_adjust_string_locations) {
+ if (grecs_parser_options & GRECS_OPTION_ADJUST_STRING_LOCATIONS) {
yylloc.beg.col++;
yylloc.end.col--;
}
diff --git a/src/parser.c b/src/parser.c
index 1ad43c1..ed99a7a 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -26,7 +26,7 @@ int grecs_error_count = 0;
int grecs_default_port = 0;
int grecs_trace_flags = 0;
-int grecs_adjust_string_locations = 0;
+int grecs_parser_options = 0;
#ifndef GRECS_DEFAULT_PARSER
# define GRECS_DEFAULT_PARSER grecs_grecs_parser

Return to:

Send suggestions and report system problems to the System administrator.