diff options
-rw-r--r-- | libbuild2/lexer.cxx | 11 | ||||
-rw-r--r-- | libbuild2/lexer.hxx | 2 | ||||
-rw-r--r-- | libbuild2/parser.cxx | 12 | ||||
-rw-r--r-- | tests/switch/testscript | 12 |
4 files changed, 30 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; } diff --git a/tests/switch/testscript b/tests/switch/testscript index c8adaf0..f6c3753 100644 --- a/tests/switch/testscript +++ b/tests/switch/testscript @@ -312,3 +312,15 @@ switch 1: no_such_matcher EOI <stdin>:3:8: error: unmatched call to no_such_matcher(<untyped>, <untyped>) EOE + +: match-extraction +: +$* <<EOI 2>>EOE != 0 +switch 1 +{ + case 1: y + x = $y +} +EOI +<stdin>:3:9: error: unexpected ':' (match extraction is not yet supported) +EOE |