]> mj.ucw.cz Git - paperjam.git/commitdiff
More general syntax of pipelines
authorMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 20:44:37 +0000 (22:44 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 20:44:37 +0000 (22:44 +0200)
cmds.cc
parse.cc

diff --git a/cmds.cc b/cmds.cc
index fa4f615fadeedf28b62aa917422dca6927b4c8f8..8a5c0b4434e782a7c30de5d0c90480c30c7d8e3e 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -177,20 +177,20 @@ vector<page *> select_cmd::process(vector<page *> &pages)
 {
   vector<page *> out;
   for (auto pb: pipe->branches)
-    for (auto ps: pb->selectors)
-      {
-       int f = validate_page_index(pages, ps.from);
-       int t = validate_page_index(pages, ps.to);
-       int step = (f <= t) ? 1 : -1;
-       for (int i=f; f<=t; f += step)
-         {
-           vector<page *> selected;
+    {
+      vector<page *> selected;
+      for (auto ps: pb->selectors)
+       {
+         int f = validate_page_index(pages, ps.from);
+         int t = validate_page_index(pages, ps.to);
+         int step = (f <= t) ? 1 : -1;
+         for (int i=f; f<=t; f += step)
            selected.push_back(pages[i]);
-           selected = run_command_list(pb->commands, selected);
-           for (auto p: selected)
-             out.push_back(p);
-         }
-      }
+       }
+      auto processed = run_command_list(pb->commands, selected);
+      for (auto p: processed)
+       out.push_back(p);
+    }
   return out;
 }
 
index ea6d6cda812d1beb92458944b5899075f40646f2..2e38d3ad403204451ea2ace07e6a8d3079c78b57 100644 (file)
--- a/parse.cc
+++ b/parse.cc
@@ -231,23 +231,15 @@ static void parse_pipeline(cmd *c)
       pipeline_branch *pb = new pipeline_branch;
       pp->branches.push_back(pb);
 
+      token_type t;
       for (;;)
        {
-         token_type t = next_token();
-         if (t == TOK_CLOSE_BRACE || t == TOK_END)
-           parse_error("Premature end of pipeline");
-         if (t == TOK_COLON)
+         t = next_token();
+         if (t == TOK_END)
+           parse_error("Missing close brace");
+         if (t == TOK_CLOSE_BRACE || t == TOK_COLON || t == TOK_COMMA)
            break;
 
-         if (pb->selectors.size())
-           {
-             if (t != TOK_COMMA)
-               parse_error("Invalid pipeline selector");
-             t = next_token();
-             if (t == TOK_CLOSE_BRACE || t == TOK_END)
-               parse_error("Premature end of pipeline");
-           }
-
          pipeline_selector ps;
          if (t != TOK_NUMBER)
            parse_error("Pipeline selectors must start with a number");
@@ -270,7 +262,10 @@ static void parse_pipeline(cmd *c)
          pb->selectors.push_back(ps);
        }
 
-      parse_commands(pb->commands);
+      if (t == TOK_COLON)
+       parse_commands(pb->commands);
+      else
+       return_token();
     }
 
   c->pipe = pp;