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 1Q7NOd-0003cZ-1U for garchives@archives.gentoo.org; Wed, 06 Apr 2011 07:43:23 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 199591C05F; Wed, 6 Apr 2011 07:43:11 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id CD3091C05F for ; Wed, 6 Apr 2011 07:43:10 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 470051B40E9 for ; Wed, 6 Apr 2011 07:43:10 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id EEE2780072 for ; Wed, 6 Apr 2011 07:43:08 +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: 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.ebuild scripts/var_expansion.ebuild.result 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: cc66a932c3756730ddf11198999c39a4f6f9a9e1 Date: Wed, 6 Apr 2011 07:43:08 +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: aa930c03c7564ba0ebd6b7b12cedb2f0 commit: cc66a932c3756730ddf11198999c39a4f6f9a9e1 Author: Mu Qiao gentoo org> AuthorDate: Tue Apr 5 12:02:24 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Tue Apr 5 13:49:13 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3Dcc66a932 Implement ${param:=3Dw} and ${param:+w} expansion --- bashast/libbashWalker.g | 6 ++++++ scripts/var_expansion.ebuild | 4 ++++ scripts/var_expansion.ebuild.result | 5 +++++ src/core/interpreter.h | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 0 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index a25c58c..ad8e444 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -89,6 +89,12 @@ var_name returns[std::string libbash_value] var_expansion returns[std::string libbash_value]: ^(USE_DEFAULT var_name libbash_word=3Dword) { libbash_value =3D walker->do_default_expansion($var_name.libbash_value= , libbash_word); + } + |^(ASSIGN_DEFAULT var_name libbash_word=3Dword) { + libbash_value =3D walker->do_assign_expansion($var_name.libbash_value,= libbash_word); + } + |^(USE_ALTERNATE var_name libbash_word=3Dword) { + libbash_value =3D walker->do_alternate_expansion($var_name.libbash_val= ue, libbash_word); }; =20 word returns[std::string libbash_value]: diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild index 533e7a7..f0ad504 100644 --- a/scripts/var_expansion.ebuild +++ b/scripts/var_expansion.ebuild @@ -5,3 +5,7 @@ FOO2=3D"${EAPI3:-hello}" FOO3=3D123 FOO4=3D$EAPI FOO5=3D$(( 1+1 )) +FOO6=3D${EAPI:=3Dhello} +FOO7=3D${FOO8:=3Dhello} +FOO9=3D${EAPI:+hello} +FOO10=3D${NOT_EXIST:+hello} diff --git a/scripts/var_expansion.ebuild.result b/scripts/var_expansion.= ebuild.result index bad2cf3..7d2e5ca 100644 --- a/scripts/var_expansion.ebuild.result +++ b/scripts/var_expansion.ebuild.result @@ -1,7 +1,12 @@ EAPI=3D3 EAPI4=3D4 FOO=3D3 +FOO10=3D FOO2=3Dhello FOO3=3D123 FOO4=3D3 FOO5=3D2 +FOO6=3D3 +FOO7=3Dhello +FOO8=3Dhello +FOO9=3Dhello diff --git a/src/core/interpreter.h b/src/core/interpreter.h index ab6b9e8..aad8f48 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -424,5 +424,25 @@ public: { return (is_unset_or_null(name)? value : resolve(name)); } + + /// \brief perform ${parameter:=3Dword} expansion + /// \param the name of the parameter + /// \param the value of the word + /// \return the expansion result + const std::string do_assign_expansion(const std::string& name, + const std::string& value) + { + return (is_unset_or_null(name)? set_value(name, value) : resolve(name)); + } + + /// \brief perform ${parameter:+word} expansion + /// \param the name of the parameter + /// \param the value of the word + /// \return the expansion result + const std::string do_alternate_expansion(const std::string& name, + const std::string& value) + { + return (is_unset_or_null(name)? "" : value); + } }; #endif