aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-07-16 12:21:27 +0300
committerSergey Poznyakoff <gray@gnu.org>2016-07-16 12:21:27 +0300
commit529fed25f92e04d694c30b3fc6bc8645e2703f4e (patch)
treec575001b35a43ba8f325bf7af60d7b9fb8b8b32a
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.
-rw-r--r--doc/grecs-syntax.texi15
-rw-r--r--include/grecs/parser.h5
-rw-r--r--src/grecs-lex.l10
-rw-r--r--src/parser.c2
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/gcffmt.c7
-rw-r--r--tests/stradj.at39
-rw-r--r--tests/strcat.at31
-rw-r--r--tests/testsuite.at4
9 files changed, 106 insertions, 9 deletions
diff --git a/doc/grecs-syntax.texi b/doc/grecs-syntax.texi
index a7738d6..2ddedea 100644
--- a/doc/grecs-syntax.texi
+++ b/doc/grecs-syntax.texi
@@ -111,9 +111,12 @@ The default include search path is:
where @var{prefix} is the installation prefix.
@c FIXME: Uncomment this, if necessary:
-@c FIXME: New directories can be appended in front of it using @option{-I}
-@c FIXME: (@option{--include-directory}) command line option
-@c FIXME: (@pxref{Preprocessor, include-directory}).
+@ignore
+New directories can be appended in front of it using @option{-I}
+(@option{--include-directory}) command line option
+(@pxref{Preprocessor, include-directory}).
+}
+@end ignore
@kwindex #include_once
@item #include_once <@var{file}>
@@ -216,6 +219,11 @@ physical lines, e.g.:
If the character following a backslash is not one of those specified
above, the backslash is ignored and a warning is issued.
+@c FIXME: If grecs_parser_options variable has
+@c FIXME: GRECS_OPTION_QUOTED_STRING_CONCAT bit set, then the
+@c FIXME: following holds:
+
+@ignore
Two or more adjacent quoted strings are concatenated, which gives
another way to split long strings over several lines to improve
readability. The following fragment produces the same result as the
@@ -227,6 +235,7 @@ example above:
" split over several lines"
@end group
@end smallexample
+@end ignore
@anchor{here-document}
@item Here-document
diff --git a/include/grecs/parser.h b/include/grecs/parser.h
index 00878f4..41b3ae4 100644
--- a/include/grecs/parser.h
+++ b/include/grecs/parser.h
@@ -28,9 +28,12 @@ extern int grecs_default_port;
extern struct grecs_locus_point grecs_current_locus_point;
extern grecs_locus_t grecs_locus;
-extern int grecs_adjust_string_locations;
extern int grecs_error_count;
+#define GRECS_OPTION_ADJUST_STRING_LOCATIONS 0x01
+#define GRECS_OPTION_QUOTED_STRING_CONCAT 0x02
+extern int grecs_parser_options;
+
/* Main entry point */
struct grecs_node *grecs_parse(const char *name);
void grecs_gram_trace(int n);
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
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9bf28da..65f590a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -121,6 +121,8 @@ TESTSUITE_AT = \
set.at\
sort00.at\
sort01.at\
+ stradj.at\
+ strcat.at\
testsuite.at\
vercmp.at\
wordsplit.at\
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index 8e378f9..170f788 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -94,7 +94,8 @@ main(int argc, char **argv)
int flags = GRECS_NODE_FLAG_DEFAULT;
int reduce = 0;
int sort = 0;
-
+
+ grecs_parser_options = 0;
while (--argc) {
char *arg = *++argv;
if (strcmp(arg, "-locus") == 0)
@@ -128,6 +129,10 @@ main(int argc, char **argv)
grecs_gram_trace(1);
else if (strcmp(arg, "-X") == 0)
grecs_lex_trace(1);
+ else if (strcmp(arg, "-strcat") == 0)
+ grecs_parser_options |= GRECS_OPTION_QUOTED_STRING_CONCAT;
+ else if (strcmp(arg, "-stradj") == 0)
+ grecs_parser_options |= GRECS_OPTION_ADJUST_STRING_LOCATIONS;
else if (arg[0] == '-')
usage(progname, stderr, 1);
else {
diff --git a/tests/stradj.at b/tests/stradj.at
new file mode 100644
index 0000000..186078a
--- /dev/null
+++ b/tests/stradj.at
@@ -0,0 +1,39 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([String location adjustment])
+AT_KEYWORDS([format option stradj])
+
+AT_DATA([input.conf],
+[ident name;
+option "string";
+])
+
+AT_CHECK([echo "Default"
+gcffmt -nopath -locus input.conf
+echo "Adjustment"
+gcffmt -nopath -locus -stradj input.conf
+],
+[0],
+[Default
+input.conf:1.7-10: "name"
+input.conf:2.8-15: "string"
+Adjustment
+input.conf:1.7-10: "name"
+input.conf:2.9-14: "string"
+])
+
+AT_CLEANUP
diff --git a/tests/strcat.at b/tests/strcat.at
new file mode 100644
index 0000000..b5f703a
--- /dev/null
+++ b/tests/strcat.at
@@ -0,0 +1,31 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([String concatenation])
+AT_KEYWORDS([format option strcat concat])
+
+AT_DATA([input.conf],
+[option id "a" " string";
+])
+
+AT_CHECK([gcffmt input.conf
+gcffmt -strcat input.conf],
+[0],
+[.option: "id" "a" " string"
+.option: "id" "a string"
+])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index ec94ff0..cb7f1a5 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -54,6 +54,10 @@ m4_include([format00.at])
m4_include([format01.at])
m4_include([format02.at])
+AT_BANNER([Options])
+m4_include([stradj.at])
+m4_include([strcat.at])
+
AT_BANNER([Enumeration])
m4_include([enum.at])

Return to:

Send suggestions and report system problems to the System administrator.