From 86c5561ba890795d34bd5e4dddfe8123282736e1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 28 Feb 2018 16:28:30 -0800 Subject: [PATCH] Allow file redirects on while statements --- corpus/control_flow.txt | 18 ++++++++++++++++++ grammar.js | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/corpus/control_flow.txt b/corpus/control_flow.txt index a77f47e..5891288 100644 --- a/corpus/control_flow.txt +++ b/corpus/control_flow.txt @@ -16,6 +16,24 @@ done (command (command_name (word)) (word)) (command (command_name (word)) (word))))) +==================================== +While statements with IO redirects +==================================== + +while read line; do + echo $line +done < <(cat file) + +--- + +(program + (while_statement + (command (command_name (word)) (word)) + (do_group + (command (command_name (word)) (simple_expansion (variable_name)))) + (file_redirect (process_substitution + (command (command_name (word)) (word)))))) + ==================================== For statements ==================================== diff --git a/grammar.js b/grammar.js index 2db3d08..dea9244 100644 --- a/grammar.js +++ b/grammar.js @@ -78,7 +78,12 @@ module.exports = grammar({ while_statement: $ => seq( 'while', $._terminated_statement, - $.do_group + $.do_group, + repeat(choice( + $.file_redirect, + $.heredoc_redirect, + $.herestring_redirect + )) ), do_group: $ => seq(