aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-09-30 12:53:29 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-09-30 15:30:45 +0200
commit6b9699f0f2e48961af25843eea9b694d043bd352 (patch)
tree6989edc16eb0690480d556aae6b83588d495a132 /libbuild2
parent12268f7741ba73c75a73fafb6063f1393e485aae (diff)
Reserve `:` in `case` pattern expression for future match extraction support
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/lexer.cxx11
-rw-r--r--libbuild2/lexer.hxx2
-rw-r--r--libbuild2/parser.cxx12
3 files changed, 18 insertions, 7 deletions
diff --git a/libbuild2/lexer.cxx b/libbuild2/lexer.cxx
index 17b0c7d..61d7fbf 100644
--- a/libbuild2/lexer.cxx
+++ b/libbuild2/lexer.cxx
@@ -63,8 +63,8 @@ namespace build2
}
case lexer_mode::case_patterns:
{
- s1 = " $(){}[],|#\t\n";
- s2 = " ";
+ s1 = " $(){}[],|:#\t\n";
+ s2 = " ";
break;
}
case lexer_mode::attribute:
@@ -201,9 +201,10 @@ namespace build2
// The following characters are special in the normal, variable, and
// switch_expressions modes.
//
- if (m == lexer_mode::normal ||
- m == lexer_mode::variable ||
- m == lexer_mode::switch_expressions)
+ if (m == lexer_mode::normal ||
+ m == lexer_mode::variable ||
+ m == lexer_mode::switch_expressions ||
+ m == lexer_mode::case_patterns)
{
switch (c)
{
diff --git a/libbuild2/lexer.hxx b/libbuild2/lexer.hxx
index 72ec050..90d546d 100644
--- a/libbuild2/lexer.hxx
+++ b/libbuild2/lexer.hxx
@@ -33,7 +33,7 @@ namespace build2
// a few extra characters:
//
// switch_expressions values plus `:`
- // case_patterns values plus '|'
+ // case_patterns values plus '|' and ':'
//
// Note that the normal, value/values and derived, as well as eval modes
// split words separated by the pair character (to disable pairs one can
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index d457c68..a8abbfb 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -2141,7 +2141,7 @@ namespace build2
// multiple `case`s per line/block) optionally followed by the `default`
// lines/blocks followed by the closing `}`.
//
- bool taken (false); // One of the cases/default has been taken.
+ bool taken (false); // One of the case/default has been taken.
bool seen_default (false);
auto special = [&seen_default, this] (const token& t, const type& tt)
@@ -2279,6 +2279,16 @@ namespace build2
break;
}
+ // We reserve the ':' separator for possible future match
+ // extraction support:
+ //
+ // case '...': x
+ // info "$x"
+ //
+ if (tt == type::colon)
+ fail (t) << "unexpected ':' (match extraction is not yet "
+ << "supported)";
+
if (tt != type::comma)
break;
}