aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-11-14 16:07:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-11-14 16:07:42 +0200
commit3449948b4e56bcb37df4f980c71d907118d7a483 (patch)
tree27f68a17e300f9fdbf94567e6c8b3b85948c53e1
parent07b75e1979829c7df557719ff8076a1ec08faeb0 (diff)
Require attributes to be separated from words and similar on RHS
-rw-r--r--libbuild2/parser.cxx21
-rw-r--r--tests/function/regex/testscript2
2 files changed, 20 insertions, 3 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index be1ba0b..6f4b7c0 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -3582,8 +3582,25 @@ namespace build2
next (t, tt);
- if (!standalone && (tt == type::newline || tt == type::eos))
- fail (t) << "standalone attributes";
+ if (tt == type::newline || tt == type::eos)
+ {
+ if (!standalone)
+ fail (t) << "standalone attributes";
+ }
+ //
+ // We require attributes to be separated from the following word or
+ // "word-producing" tokens (`$` for variable expansions/function calls,
+ // `(` for eval contexts, and `{` for name generation) to reduce the
+ // possibility of confusing them with wildcard patterns. Consider:
+ //
+ // ./: [abc]-foo.txt
+ //
+ else if (!t.separated && (tt == type::word ||
+ tt == type::dollar ||
+ tt == type::lparen ||
+ tt == type::lcbrace))
+ fail (t) << "whitespace required after attributes" <<
+ info << "add an empty attribute list if this is a wildcard pattern";
return make_pair (has, l);
}
diff --git a/tests/function/regex/testscript b/tests/function/regex/testscript
index 091c28a..9006690 100644
--- a/tests/function/regex/testscript
+++ b/tests/function/regex/testscript
@@ -203,7 +203,7 @@
v = [string] "foo.cxx
bar.txt"
- print $regex.replace_lines($v, [string] '(.*)\.cxx', [string]'\1.hxx', return_lines)
+ print $regex.replace_lines($v, [string] '(.*)\.cxx', [string] '\1.hxx', return_lines)
EOI
foo.hxx
bar.txt