aboutsummaryrefslogtreecommitdiff
path: root/build2/test
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-11-01 12:18:59 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:37 +0200
commit5583ffaa2581858cb7f7f75e28660bc038bcc8ec (patch)
tree72707ac943e4f2a5a0457869d7672db558940461 /build2/test
parent40a34dc212a5749350723ac4f390335c0c5283e3 (diff)
Add support for cleanup types to testscript parser
Diffstat (limited to 'build2/test')
-rw-r--r--build2/test/script/lexer.cxx14
-rw-r--r--build2/test/script/parser.cxx36
-rw-r--r--build2/test/script/token4
-rw-r--r--build2/test/script/token.cxx5
4 files changed, 47 insertions, 12 deletions
diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx
index a9b7d56..b7a9f78 100644
--- a/build2/test/script/lexer.cxx
+++ b/build2/test/script/lexer.cxx
@@ -264,13 +264,21 @@ namespace build2
//
case '&':
{
- if (peek () == '&')
+ xchar p (peek ());
+
+ if (p == '?' || p == '!' || p == '&')
{
get ();
- return make_token (type::log_and);
+
+ switch (p)
+ {
+ case '?': return make_token (type::clean_maybe);
+ case '!': return make_token (type::clean_never);
+ case '&': return make_token (type::log_and);
+ }
}
else
- return make_token (type::clean);
+ return make_token (type::clean_always);
}
// <
//
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index fc40fd0..7fb0608 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -807,6 +807,7 @@ namespace build2
pending p (pending::program);
bool nn (false); // True if pending here-{str,doc} is "no-newline".
bool app (false); // True if to append to pending file.
+ cleanup_type ct; // Pending cleanup type.
// Ordered sequence of here-document redirects that we can expect to
// see after the command line.
@@ -823,7 +824,7 @@ namespace build2
// to program arguments by default.
//
auto add_word =
- [&c, &p, &nn, &app, &hd, this] (string&& w, const location& l)
+ [&c, &p, &nn, &app, &ct, &hd, this] (string&& w, const location& l)
{
auto add_merge = [&l, this] (redirect& r, const string& w, int fd)
{
@@ -913,7 +914,8 @@ namespace build2
case pending::clean:
{
c.cleanups.push_back (
- {cleanup_type::always, parse_path (move (w), "cleanup path")});
+ {ct, parse_path (move (w), "cleanup path")});
+
break;
}
}
@@ -1092,6 +1094,20 @@ namespace build2
}
};
+ // Set pending cleanup type.
+ //
+ auto parse_clean = [&p, &ct] (type tt)
+ {
+ switch (tt)
+ {
+ case type::clean_always: ct = cleanup_type::always; break;
+ case type::clean_maybe: ct = cleanup_type::maybe; break;
+ case type::clean_never: ct = cleanup_type::never; break;
+ }
+
+ p = pending::clean;
+ };
+
const location ll (get_location (t)); // Line location.
// Keep parsing chunks of the command line until we see one of the
@@ -1136,7 +1152,9 @@ namespace build2
case type::out_file:
case type::out_file_app:
- case type::clean:
+ case type::clean_always:
+ case type::clean_maybe:
+ case type::clean_never:
{
if (pre_parse_)
{
@@ -1206,9 +1224,11 @@ namespace build2
break;
}
- case type::clean:
+ case type::clean_always:
+ case type::clean_maybe:
+ case type::clean_never:
{
- p = pending::clean;
+ parse_clean (tt);
break;
}
@@ -1369,9 +1389,11 @@ namespace build2
break;
}
- case type::clean:
+ case type::clean_always:
+ case type::clean_maybe:
+ case type::clean_never:
{
- p = pending::clean;
+ parse_clean (tt);
break;
}
diff --git a/build2/test/script/token b/build2/test/script/token
index a1374fe..d4f6eec 100644
--- a/build2/test/script/token
+++ b/build2/test/script/token
@@ -30,7 +30,9 @@ namespace build2
minus, // -
pipe, // |
- clean, // &
+ clean_always, // &
+ clean_maybe, // &?
+ clean_never, // &!
log_and, // &&
log_or, // ||
diff --git a/build2/test/script/token.cxx b/build2/test/script/token.cxx
index 1cd0859..79e64de 100644
--- a/build2/test/script/token.cxx
+++ b/build2/test/script/token.cxx
@@ -26,8 +26,11 @@ namespace build2
case token_type::plus: os << q << '+' << q; break;
case token_type::minus: os << q << '-' << q; break;
+ case token_type::clean_always: os << q << '&' << q; break;
+ case token_type::clean_maybe: os << q << "&?" << q; break;
+ case token_type::clean_never: os << q << "&!" << q; break;
+
case token_type::pipe: os << q << '|' << q; break;
- case token_type::clean: os << q << '&' << q; break;
case token_type::log_and: os << q << "&&" << q; break;
case token_type::log_or: os << q << "||" << q; break;