aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/name.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-05-25 11:19:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-05-28 10:10:44 +0200
commit6b3e75edf034ebcbd048a24c283c7bcf7b1da019 (patch)
tree4dff34692fd09c6f201a486c0d92549adc864947 /libbuild2/name.hxx
parentbb02e152dc036879ab0b2d1d8aa2cb19084b8e16 (diff)
Add support for regex-based target type/pattern specific variables
This is in addition to the already supported path-based target type/pattern specific variables. For example: hxx{*}: x = y # path-based hxx{~/.*/}: x = y # regex-based
Diffstat (limited to 'libbuild2/name.hxx')
-rw-r--r--libbuild2/name.hxx38
1 files changed, 27 insertions, 11 deletions
diff --git a/libbuild2/name.hxx b/libbuild2/name.hxx
index 5c76d07..216f207 100644
--- a/libbuild2/name.hxx
+++ b/libbuild2/name.hxx
@@ -33,16 +33,21 @@ namespace build2
// If pair is not '\0', then this name and the next in the list form a
// pair. Can be used as a bool flag.
//
- // If pattern is true then this is a name pattern (e.g., file{*.txt}).
+ // If pattern is present then this is a name pattern (e.g., file{*.txt},
+ // file{~'/(.+)\.txt/i'}, file{^'/\1/'}). A directory name cannot be a regex
+ // pattern (since we would need to store it in dir_path and a regex is not
+ // necessarily a valid path).
//
struct name
{
+ enum class pattern_type: uint8_t {path, regex_pattern, regex_substitution};
+
optional<project_name> proj;
dir_path dir;
string type;
string value;
char pair = '\0';
- bool pattern = false;
+ optional<pattern_type> pattern;
name () {} // = default; Clang needs this to initialize const object.
name (string v): value (move (v)) {}
@@ -57,13 +62,16 @@ namespace build2
: proj (project_name (move (p))), dir (move (d)), type (move (t)),
value (move (v)) {}
- name (optional<project_name> p,
- dir_path d,
- string t,
- string v,
- bool pat = false)
+ name (optional<project_name> p, dir_path d, string t, string v)
+ : proj (move (p)), dir (move (d)), type (move (t)), value (move (v)) {}
+
+ name (optional<project_name> p,
+ dir_path d,
+ string t,
+ string v,
+ optional<pattern_type> pt)
: proj (move (p)), dir (move (d)), type (move (t)), value (move (v)),
- pattern (pat) {}
+ pattern (pt) {}
bool
qualified () const {return proj.has_value ();}
@@ -162,7 +170,8 @@ namespace build2
cs.append (n.type);
cs.append (n.value);
cs.append (n.pair);
- cs.append (n.pattern);
+ if (n.pattern)
+ cs.append (static_cast<uint8_t> (*n.pattern));
}
// Store a string in a name in a reversible way. If the string ends with a
@@ -173,14 +182,21 @@ namespace build2
to_name (string);
// Serialize the name to the stream. If requested, the name components
- // containing special characters are quoted. The special characters are:
+ // containing special characters are quoted and/or escaped. The special
+ // characters are:
//
// {}[]$() \t\n#\"'%
//
- // And additionally, if name is not a pattern:
+ // And additionally, unless name is a pattern:
//
// *?
//
+ // As well as leading and if followed by a non-alphanumeric delimiter:
+ //
+ // ~^
+ //
+ // As well as leading `+` if in the curly braces.
+ //
// If the pair argument is not '\0', then it is added to the above special
// characters set. If the quote character is present in the component then
// it is double quoted rather than single quoted. In this case the following