diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-07-16 12:21:27 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-07-16 12:21:27 +0300 |
commit | 529fed25f92e04d694c30b3fc6bc8645e2703f4e (patch) | |
tree | c575001b35a43ba8f325bf7af60d7b9fb8b8b32a /tests | |
parent | 6201e61fb932dbe6153f92ede836e07247d04b7c (diff) | |
download | grecs-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 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/gcffmt.c | 7 | ||||
-rw-r--r-- | tests/stradj.at | 39 | ||||
-rw-r--r-- | tests/strcat.at | 31 | ||||
-rw-r--r-- | tests/testsuite.at | 4 |
5 files changed, 82 insertions, 1 deletions
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]) |