From 08ae9246421cf2b7269dc09dab2dbd5dc5d0817a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 28 Oct 2016 13:01:04 +0200 Subject: Add tests and fixes for trailing description support --- build2/test/script/lexer.cxx | 22 ++++++++++++++------ build2/test/script/parser.cxx | 48 +++++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 24 deletions(-) (limited to 'build2/test') diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx index 8b647dc..a9b7d56 100644 --- a/build2/test/script/lexer.cxx +++ b/build2/test/script/lexer.cxx @@ -407,20 +407,30 @@ namespace build2 token lexer:: next_description () { - xchar c (get ()); + xchar c (peek ()); + + if (eos (c)) + fail (c) << "expected newline at the end of description line"; uint64_t ln (c.line), cn (c.column); + + if (c == '\n') + { + get (); + state_.pop (); // Expire the description mode. + return token (type::newline, false, ln, cn, token_printer); + } + string lexeme; // For now no line continutions though we could support them. // - for (; !eos (c) && c != '\n'; c = get ()) + for (; !eos (c) && c != '\n'; c = peek ()) + { + get (); lexeme += c; + } - if (eos (c)) - fail (c) << "expected newline at the end of description line"; - - state_.pop (); // Expire the description mode. return token (move (lexeme), false, false, ln, cn); } diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index a6b8e50..e714665 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -350,13 +350,20 @@ namespace build2 mode (lexer_mode::description_line); next (t, tt); - assert (tt == type::word); - const string& l (t.value); + // If it is empty, then we get newline right away. + // + const string& l (tt == type::word ? t.value : string ()); + + if (tt == type::word) + next (t, tt); // Get newline. + + assert (tt == type::newline); - // If this is the first line, then get the "strip prefix", i.e., the - // beginning of the line that contains only whitespaces. If the - // subsequent lines start with the same prefix, then we strip it. + // If this is the first line, then get the "strip prefix", i.e., + // the beginning of the line that contains only whitespaces. If + // the subsequent lines start with the same prefix, then we strip + // it. // if (ln == 1) { @@ -1099,6 +1106,7 @@ namespace build2 case type::equal: case type::not_equal: case type::semi: + case type::colon: case type::newline: { done = true; @@ -1424,23 +1432,27 @@ namespace build2 mode (lexer_mode::description_line); next (t, tt); - assert (tt == type::word); - - string l (move (t.value)); - trim (l); // Strip leading/trailing whitespaces. - // Decide whether this is id or summary. + // If it is empty, then we get newline right away. // - auto& d (*(r.second = description ())); - (l.find_first_of (" \t") == string::npos ? d.id : d.summary) = - move (l); + if (tt == type::word) + { + string l (move (t.value)); + trim (l); // Strip leading/trailing whitespaces. - if (d.empty ()) - fail (loc) << "empty description"; + // Decide whether this is id or summary. + // + auto& d (*(r.second = description ())); + (l.find_first_of (" \t") == string::npos ? d.id : d.summary) = + move (l); - //@@ No newline token! - // - tt = type::newline; + next (t, tt); // Get newline. + } + + assert (tt == type::newline); + + if (r.second->empty ()) + fail (loc) << "empty description"; } else { -- cgit v1.1