Allow conditionals to have multiple predicates
authorMichael Spang <mspang@csclub.uwaterloo.ca>
Mon, 21 Dec 2009 05:34:09 +0000 (00:34 -0500)
committerMichael Spang <mspang@csclub.uwaterloo.ca>
Tue, 22 Dec 2009 03:28:24 +0000 (22:28 -0500)
Signed-off-by: Michael Spang <mspang@csclub.uwaterloo.ca>
inapt.cc
inapt.h
parser.rl

index f263b18..98f1dda 100644 (file)
--- a/inapt.cc
+++ b/inapt.cc
@@ -189,7 +189,7 @@ static void eval_block(inapt_block *block, std::set<std::string> *defines, std::
             eval_action(*i, defines, final_actions);
 
     for (vector<inapt_conditional *>::iterator i = block->children.begin(); i < block->children.end(); i++) {
-        if (test_macro((*i)->condition, defines))
+        if (test_macros(&(*i)->predicates, defines))
             eval_block((*i)->then_block, defines, final_actions);
         else
             eval_block((*i)->else_block, defines, final_actions);
@@ -206,7 +206,7 @@ static void eval_profiles(inapt_block *block, std::set<std::string> *defines) {
                 defines->insert(*j);
 
     for (vector<inapt_conditional *>::iterator i = block->children.begin(); i < block->children.end(); i++) {
-        if (test_macro((*i)->condition, defines))
+        if (test_macros(&(*i)->predicates, defines))
             eval_profiles((*i)->then_block, defines);
         else
             eval_profiles((*i)->else_block, defines);
diff --git a/inapt.h b/inapt.h
index 4659b76..50bbd05 100644 (file)
--- a/inapt.h
+++ b/inapt.h
@@ -31,7 +31,7 @@ struct inapt_block {
 };
 
 struct inapt_conditional {
-    const char *condition;
+    std::vector<std::string> predicates;
     struct inapt_block *then_block;
     struct inapt_block *else_block;
 };
index 8882472..1347b40 100644 (file)
--- a/parser.rl
+++ b/parser.rl
@@ -79,7 +79,7 @@ using namespace std;
 
     action start_conditional {
         inapt_conditional *cond = new inapt_conditional;
-        cond->condition = xstrndup(ts, p - ts); ts = 0;
+        cond->predicates.swap(predicates);
         conditional_stack.push_back(cond);
     }
 
@@ -119,10 +119,9 @@ using namespace std;
     cmd_install = ('install' @start_install package_list ';');
     cmd_remove = ('remove' @start_remove package_list ';');
     cmd_profiles = ('profiles' profile_list ';' @add_profiles);
-    start_block = '{' @start_block;
     end_block = '}' @end_block;
-    cmd_if = 'if' whitespace+ profile >strstart %start_conditional whitespace* start_block whitespace*
-             ('else' whitespace* start_block whitespace* ';' @full_conditional | ';' @half_conditional);
+    cmd_if = 'if' whitespace+ predicate+ '{' @start_conditional @start_block whitespace*
+             ('else' whitespace* '{' @start_block whitespace* ';' @full_conditional | ';' @half_conditional);
     cmd = whitespace* (predicate* (cmd_install | cmd_remove | cmd_profiles) | cmd_if);
     cmd_list = cmd* whitespace* end_block?;
     main := cmd_list;