From f6e6cfc3b5c7c84dedddc95084c423608769d4b7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 26 Apr 2017 12:43:15 +0200 Subject: Fix bug in pair handling --- build2/lexer.cxx | 16 ++++++++++------ build2/parser | 17 ++--------------- build2/parser.cxx | 2 +- build2/token | 3 +-- build2/token.cxx | 2 +- old-tests/pairs/buildfile | 3 +++ old-tests/pairs/test.out | 1 + 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/build2/lexer.cxx b/build2/lexer.cxx index d3afdb0..e117f28 100644 --- a/build2/lexer.cxx +++ b/build2/lexer.cxx @@ -119,9 +119,11 @@ namespace build2 xchar c (get ()); uint64_t ln (c.line), cn (c.column); - auto make_token = [&sep, ln, cn] (type t) + auto make_token = [&sep, ln, cn] (type t, string v = string ()) { - return token (t, sep, ln, cn, token_printer); + return token (t, move (v), + sep, quote_type::unquoted, false, + ln, cn, token_printer); }; if (eos (c)) @@ -130,7 +132,7 @@ namespace build2 // Handle pair separator. // if (c == st.sep_pair) - return make_token (type::pair_separator); + return make_token (type::pair_separator, string (1, c)); switch (c) { @@ -232,9 +234,11 @@ namespace build2 uint64_t ln (c.line), cn (c.column); - auto make_token = [sep, ln, cn] (type t) + auto make_token = [sep, ln, cn] (type t, string v = string ()) { - return token (t, sep, ln, cn, token_printer); + return token (t, move (v), + sep, quote_type::unquoted, false, + ln, cn, token_printer); }; // This mode is quite a bit like the value mode when it comes to special @@ -244,7 +248,7 @@ namespace build2 // Handle pair separator. // if (c == st.sep_pair) - return make_token (type::pair_separator); + return make_token (type::pair_separator, string (1, c)); // Note: we don't treat [ and ] as special here. Maybe can use them for // something later. diff --git a/build2/parser b/build2/parser index 7ca9366..16b7782 100644 --- a/build2/parser +++ b/build2/parser @@ -395,7 +395,7 @@ namespace build2 // if (peeked_) { - assert (peek_.mode == m && peek_.pair_separator == ps); + assert (peek_.mode == m); return peek_.token.type; } @@ -436,18 +436,6 @@ namespace build2 } } - char - pair_separator () const - { - if (replay_ != replay::play) - return lexer_->pair_separator (); - else - { - assert (replay_i_ != replay_data_.size ()); - return replay_data_[replay_i_].pair_separator; - } - } - void expire_mode () { @@ -552,8 +540,7 @@ namespace build2 lexer_next () { lexer_mode m (lexer_->mode ()); // Get it first since it may expire. - char ps (lexer_->pair_separator ()); - return replay_token {lexer_->next (), path_, m, ps}; + return replay_token {lexer_->next (), path_, m}; } const replay_token& diff --git a/build2/parser.cxx b/build2/parser.cxx index b95aeae..cfd18c6 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -3585,7 +3585,7 @@ namespace build2 fail (t) << "multiple " << what << "s on the left hand side " << "of a pair"; - ns.back ().pair = pair_separator (); + ns.back ().pair = t.value[0]; // If the next token is separated, then we have an empty RHS. Note // that the case where it is not a name/group (e.g., a newline/eos) diff --git a/build2/token b/build2/token index e43e66d..d58aebd 100644 --- a/build2/token +++ b/build2/token @@ -27,7 +27,7 @@ namespace build2 eos, newline, word, - pair_separator, + pair_separator, // token::value[0] is the pair separator char. colon, // : dollar, // $ @@ -156,7 +156,6 @@ namespace build2 build2::token token; const path* file; lexer_mode_base mode; - char pair_separator; using location_type = build2::location; diff --git a/build2/token.cxx b/build2/token.cxx index a721239..6f2eae5 100644 --- a/build2/token.cxx +++ b/build2/token.cxx @@ -19,7 +19,7 @@ namespace build2 { case token_type::eos: os << ""; break; case token_type::newline: os << ""; break; - case token_type::pair_separator: os << ""; break; + case token_type::pair_separator: os << ""; break; case token_type::word: os << '\'' << t.value << '\''; break; case token_type::colon: os << q << ':' << q; break; diff --git a/old-tests/pairs/buildfile b/old-tests/pairs/buildfile index 3b55044..4068be3 100644 --- a/old-tests/pairs/buildfile +++ b/old-tests/pairs/buildfile @@ -37,4 +37,7 @@ print foo@{bar BAR} # foo@bar foo@BAR #print @@ # error: double pair separator +v=foo +print @"$v" + ./: diff --git a/old-tests/pairs/test.out b/old-tests/pairs/test.out index 6033c84..f7280ac 100644 --- a/old-tests/pairs/test.out +++ b/old-tests/pairs/test.out @@ -25,3 +25,4 @@ foo@{} {}@bar {}@BAR {}@bar {}@BAR foo@bar foo@BAR +{}@foo -- cgit v1.1