From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BDB7A138010 for ; Sun, 19 Aug 2012 15:24:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CDC01E0540; Sun, 19 Aug 2012 15:23:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id A160DE0540 for ; Sun, 19 Aug 2012 15:23:49 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 132FF1B4065 for ; Sun, 19 Aug 2012 15:23:49 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id BBB14E543D for ; Sun, 19 Aug 2012 15:23:47 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <1345389235.527b3e33399dc4075339463f2b1f0478bb61ca6b.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/bashast.g bashast/libbashWalker.g scripts/command_execution.bash X-VCS-Directories: scripts/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 527b3e33399dc4075339463f2b1f0478bb61ca6b X-VCS-Branch: master Date: Sun, 19 Aug 2012 15:23:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 3c98f0c4-79b8-41e8-accb-0f334fb719db X-Archives-Hash: d34717541f2ec50cd2beab93a7e964c1 commit: 527b3e33399dc4075339463f2b1f0478bb61ca6b Author: André Aparício gmail com> AuthorDate: Sat Aug 11 01:17:05 2012 +0000 Commit: Petteri Räty gentoo org> CommitDate: Sun Aug 19 15:13:55 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=527b3e33 Parser&Walker: Support nested command substitution --- bashast/bashast.g | 2 +- bashast/libbashWalker.g | 15 ++++++++++++--- scripts/command_execution.bash | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 799b1cf..2226839 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -1197,7 +1197,7 @@ COMMAND_SUBSTITUTION_PAREN | . )+ )); -COMMAND_SUBSTITUTION_TICK : TICK (~(TICK))+ TICK; +COMMAND_SUBSTITUTION_TICK : TICK .+ (~ESC) TICK; ESC_LT : ESC'<'; ESC_GT : ESC'>'; diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 768129f..f50b32c 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -1132,13 +1132,22 @@ command_substitution returns[std::string libbash_value] @declarations { std::string subscript; std::stringstream out; + current_streams streams(walker->get_output_stream(), walker->get_error_stream(), walker->get_input_stream()); } :^(COMMAND_SUB { walker->set_output_stream(&out); } (libbash_string=any_string { subscript += libbash_string; })+) { - if(subscript[0] == '`') - bash_ast(std::stringstream(subscript.substr(1, subscript.size() - 2))).interpret_with(*walker); + if(subscript[0] == '`') { + std::string sub = subscript.substr(1, subscript.size() - 2); + // Escape \ and ' for nested command substitution + size_t pos = 0; + while((pos = sub.find("\\\\", pos)) != std::string::npos) + sub.erase(pos++, 1); + pos = 0; + while((pos = sub.find("\\`", pos)) != std::string::npos) + sub.erase(pos++, 1); + bash_ast(std::stringstream(sub)).interpret_with(*walker); + } else bash_ast(std::stringstream(subscript.substr(2, subscript.size() - 3))).interpret_with(*walker); - walker->restore_output_stream(); $libbash_value = out.str(); walker->trim_trailing_eols($libbash_value); }; diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash index df6275b..248de63 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -79,6 +79,10 @@ echo "$(echo 'hi')" echo "`echo 'hi'`" array=(`echo 1` `echo 2` 3) echo ${array[@]} +echo `echo 1` +echo `echo 1 \`echo 2\` 3` +echo `echo 1 \`echo 2 \\\`echo 3\\\` 4\` 5` +echo $(echo 1 `echo 2 $(echo 3) 4` 5) ech\ o Hello\ world