From: Martin Mares Date: Sun, 1 Apr 2018 20:44:37 +0000 (+0200) Subject: More general syntax of pipelines X-Git-Tag: v0.1~40 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0527588aa3555c88b096f0ad2ab6147c3ec395d6;p=paperjam.git More general syntax of pipelines --- diff --git a/cmds.cc b/cmds.cc index fa4f615..8a5c0b4 100644 --- a/cmds.cc +++ b/cmds.cc @@ -177,20 +177,20 @@ vector select_cmd::process(vector &pages) { vector 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 selected; + { + vector 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; } diff --git a/parse.cc b/parse.cc index ea6d6cd..2e38d3a 100644 --- 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;