From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QoyNx-0005uw-VI for garchives@archives.gentoo.org; Thu, 04 Aug 2011 13:54:54 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0D85321C1FB; Thu, 4 Aug 2011 13:53:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C62CD21C1FB for ; Thu, 4 Aug 2011 13:53:46 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5EE6D2AC01E for ; Thu, 4 Aug 2011 13:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id BBD9780042 for ; Thu, 4 Aug 2011 13:53:45 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <9bfb2dbd4180e1171db2026fb58646045c1e7144.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/var_expansion.bash src/core/interpreter.h X-VCS-Directories: scripts/ src/core/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 9bfb2dbd4180e1171db2026fb58646045c1e7144 Date: Thu, 4 Aug 2011 13:53:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 4d9a5e82ad3c5770d3672c837b710a71 commit: 9bfb2dbd4180e1171db2026fb58646045c1e7144 Author: Mu Qiao gentoo org> AuthorDate: Thu Jul 28 11:50:44 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Tue Aug 2 07:52:19 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D9bfb2dbd Walker: support expansions without colon --- bashast/libbashWalker.g | 29 ++++++++++++++++++++++++++--- scripts/var_expansion.bash | 18 ++++++++++++++++++ src/core/interpreter.h | 19 +++++++++---------- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index fc05b91..bfcb73b 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -475,13 +475,36 @@ var_expansion returns[std::string libbash_value] bool greedy; } :^(USE_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=3Draw_string) { - libbash_value =3D walker->do_default_expansion($var_name.libbash_value= , libbash_word, $var_name.index); + libbash_value =3D walker->do_default_expansion(walker->is_unset_or_nul= l($var_name.libbash_value, $var_name.index), + $var_name.libbash_value, + libbash_word, + $var_name.index); + } + |^(USE_DEFAULT_WHEN_UNSET var_name libbash_word=3Draw_string) { + libbash_value =3D walker->do_default_expansion(walker->is_unset($var_n= ame.libbash_value), + $var_name.libbash_value, + libbash_word, + $var_name.index); } |^(ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=3Draw_string= ) { - libbash_value =3D walker->do_assign_expansion($var_name.libbash_value,= libbash_word, $var_name.index); + libbash_value =3D walker->do_assign_expansion(walker->is_unset_or_null= ($var_name.libbash_value, $var_name.index), + $var_name.libbash_value, + libbash_word, + $var_name.index); + } + |^(ASSIGN_DEFAULT_WHEN_UNSET var_name libbash_word=3Draw_string) { + libbash_value =3D walker->do_assign_expansion(walker->is_unset($var_na= me.libbash_value), + $var_name.libbash_value, + libbash_word, + $var_name.index); } |^(USE_ALTERNATE_WHEN_UNSET_OR_NULL var_name libbash_word=3Draw_string)= { - libbash_value =3D walker->do_alternate_expansion($var_name.libbash_val= ue, libbash_word, $var_name.index); + libbash_value =3D walker->do_alternate_expansion(walker->is_unset_or_n= ull($var_name.libbash_value, $var_name.index), + libbash_word); + } + |^(USE_ALTERNATE_WHEN_UNSET var_name libbash_word=3Draw_string) { + libbash_value =3D walker->do_alternate_expansion(walker->is_unset($var= _name.libbash_value), + libbash_word); } |(^(OFFSET array_name arithmetics arithmetics)) =3D> ^(OFFSET libbash_n= ame=3Darray_name offset=3Darithmetics length=3Darithmetics) { libbash_value =3D walker->do_subarray_expansion(libbash_name, offset, = length); diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash index f1f5e52..2d9a28e 100644 --- a/scripts/var_expansion.bash +++ b/scripts/var_expansion.bash @@ -109,3 +109,21 @@ echo $# echo a{b,c}d echo a{a,bc}d{e,}f echo a{ab,cd}d{ef,gh} +foo=3D +unset bar +echo ${foo-abc} +foo=3D +unset bar +echo ${foo+abc} +foo=3D +unset bar +echo ${foo=3Dabc} +foo=3D +unset bar +echo ${bar-abc} +foo=3D +unset bar +echo ${bar+abc} +foo=3D +unset bar +echo ${bar=3Dabc} diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 1ee02dd..091d4b7 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -372,12 +372,12 @@ public: /// \param value the value of the word /// \param index the index of the paramter /// \return the expansion result - const std::string do_default_expansion(const std::string& name, + const std::string do_default_expansion(bool cond, + const std::string& name, const std::string& value, const unsigned index) const { - return (is_unset_or_null(name, index)? - value : resolve(name, index)); + return (cond ? value : resolve(name, index)); } =20 /// \brief perform ${parameter:=3Dword} expansion @@ -385,12 +385,12 @@ public: /// \param value the value of the word /// \param index the index of the paramter /// \return the expansion result - const std::string do_assign_expansion(const std::string& name, + const std::string do_assign_expansion(bool cond, + const std::string& name, const std::string& value, const unsigned index) { - return (is_unset_or_null(name, index)? - set_value(name, value, index) : resolve(name, index= )); + return (cond ? set_value(name, value, index) : resolve(= name, index)); } =20 /// \brief perform ${parameter:+word} expansion @@ -398,11 +398,10 @@ public: /// \param value the value of the word /// \param index the index of the paramter /// \return the expansion result - const std::string do_alternate_expansion(const std::string& name, - const std::string& value, - const unsigned index) const + const std::string do_alternate_expansion(bool cond, + const std::string& value) con= st { - return (is_unset_or_null(name, index)? "" : value); + return (cond ? "" : value); } =20 /// \brief perform substring expansion