Remove duplicate machines for predicates
authorMichael Spang <mspang@csclub.uwaterloo.ca>
Mon, 21 Dec 2009 05:23:26 +0000 (00:23 -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>
parser.rl

index 6e763a2..8882472 100644 (file)
--- a/parser.rl
+++ b/parser.rl
@@ -30,28 +30,28 @@ using namespace std;
         tmp_package->action = tmp_action->action;
         tmp_package->linenum = curline - (*p == '\n');
         tmp_package->filename = curfile;
-        tmp_package->predicates.swap(pkg_predicates);
+        tmp_package->predicates.swap(predicates);
         tmp_action->packages.push_back(tmp_package);
     }
 
     action start_install {
         tmp_action = new inapt_action;
         tmp_action->action = inapt_action::INSTALL;
-        tmp_action->predicates.swap(cmd_predicates);
+        tmp_action->predicates.swap(predicates);
         block_stack.back()->actions.push_back(tmp_action);
     }
 
     action start_remove {
         tmp_action = new inapt_action;
         tmp_action->action = inapt_action::REMOVE;
-        tmp_action->predicates.swap(cmd_predicates);
+        tmp_action->predicates.swap(predicates);
         block_stack.back()->actions.push_back(tmp_action);
     }
 
     action add_profiles {
         inapt_profiles *tmp_profiles = new inapt_profiles;
         tmp_profiles->profiles.swap(profiles);
-        tmp_profiles->predicates.swap(cmd_predicates);
+        tmp_profiles->predicates.swap(predicates);
         block_stack.back()->profiles.push_back(tmp_profiles);
     }
 
@@ -97,14 +97,9 @@ using namespace std;
         block_stack.back()->children.push_back(cond);
     }
 
-    action pkg_predicate {
+    action predicate {
         std::string tmp (ts, p - ts); ts = 0;
-        pkg_predicates.push_back(tmp);
-    }
-
-    action cmd_predicate {
-        std::string tmp (ts, p - ts); ts = 0;
-        cmd_predicates.push_back(tmp);
+        predicates.push_back(tmp);
     }
 
     action profile {
@@ -117,10 +112,9 @@ using namespace std;
     whitespace = [\t\v\f\r ] | comment | newline;
     profile = alpha (alpha | digit | '-' | '+' | '.')*;
     package_name = ((lower | digit) (lower | digit | '+' | '-' | '.')+) >strstart;
-    pkg_predicate = '@' ('!'? profile) >strstart %pkg_predicate whitespace+;
-    cmd_predicate = '@' ('!'? profile) >strstart %cmd_predicate whitespace+;
+    predicate = '@' ('!'? profile) >strstart %predicate whitespace+;
     package_alternates = package_name >strstart %add_alternate ('/' package_name >strstart %add_alternate)*;
-    package_list = ((whitespace+ pkg_predicate* package_alternates)+ %add_package whitespace*);
+    package_list = ((whitespace+ predicate* package_alternates)+ %add_package whitespace*);
     profile_list = (whitespace+ profile >strstart %profile)* whitespace*;
     cmd_install = ('install' @start_install package_list ';');
     cmd_remove = ('remove' @start_remove package_list ';');
@@ -129,7 +123,7 @@ using namespace std;
     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 = whitespace* (cmd_predicate* (cmd_install | cmd_remove | cmd_profiles) | cmd_if);
+    cmd = whitespace* (predicate* (cmd_install | cmd_remove | cmd_profiles) | cmd_if);
     cmd_list = cmd* whitespace* end_block?;
     main := cmd_list;
 }%%
@@ -164,8 +158,7 @@ void parser(const char *filename, inapt_block *top_block)
     std::vector<inapt_block *> block_stack;
     std::vector<inapt_conditional *> conditional_stack;
     std::vector<std::string> alternates;
-    std::vector<std::string> cmd_predicates;
-    std::vector<std::string> pkg_predicates;
+    std::vector<std::string> predicates;
     std::vector<std::string> profiles;
     block_stack.push_back(top_block);
     inapt_action *tmp_action = NULL;