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 1Q6mLg-0006bx-Bj for garchives@archives.gentoo.org; Mon, 04 Apr 2011 16:09:52 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3A98E1C091; Mon, 4 Apr 2011 16:09:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id F15E81C091 for ; Mon, 4 Apr 2011 16:09:44 +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 5E90D1B4090 for ; Mon, 4 Apr 2011 16:09:44 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id C2DEF8006D for ; Mon, 4 Apr 2011 16:09:43 +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: e399dff749def2cd11ab44cf53896c849f1429a8 Date: Mon, 4 Apr 2011 16:09:43 +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: a6ddfe5a8d0e1a3200a08388d02341c9 commit: e399dff749def2cd11ab44cf53896c849f1429a8 Author: Mu Qiao gentoo org> AuthorDate: Mon Apr 4 08:57:46 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Mon Apr 4 15:57:05 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3De399dff7 Implement parameter expansion: ${parameter:-word} --- bashast/libbashWalker.g | 26 ++++++++++++++++++++++++-- scripts/var_expansion.ebuild | 2 ++ scripts/var_expansion.ebuild.result | 2 ++ src/core/interpreter.h | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index ddfef7a..d0f89bf 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -62,7 +62,8 @@ var_def: =20 string_expr returns[std::string libbash_value]: ^(STRING libbash_string=3Dstring_expr) { $libbash_value =3D libbash_str= ing; } - |^(DOUBLE_QUOTED_STRING (libbash_string=3Ddqstr { $libbash_value +=3D l= ibbash_string; })*); + |^(DOUBLE_QUOTED_STRING (libbash_string=3Ddqstr { $libbash_value +=3D l= ibbash_string; })*) + |^(STRING libbash_string=3Ddqstr) { $libbash_value =3D libbash_string; = }; =20 //A rule for filenames/strings res_word_str returns[std::string libbash_value] @@ -109,9 +110,30 @@ dqstr returns[std::string libbash_value]: | libbash_string=3Dvar_ref { $libbash_value =3D libbash_string; } | ^(ARITHMETIC_EXPRESSION value=3Darithmetics) { $libbash_value =3D boo= st::lexical_cast(value); }; =20 +//Allowable variable names in the variable expansion +var_name returns[std::string libbash_value] +@after { + $libbash_value =3D walker->get_string($var_name.start); +}: + num|name|TIMES|AT; + +var_exp 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); + }; + +word returns[std::string libbash_value]: + // Avoid conflict with arithmetics (both have VAR_DEF) + (var_ref) =3D> libbash_string=3Dvar_ref { $libbash_value =3D libbash_st= ring; } + // Avoid conflict with arithmetics (both have num) + |(num) =3D> libbash_string=3Dnum { $libbash_value =3D libbash_string; } + |libbash_string=3Dstring_expr { $libbash_value =3D libbash_string; } + |value=3Darithmetics { $libbash_value =3D boost::lexical_cast(value); }; + //variable reference var_ref returns[std::string libbash_value]: - ^(VAR_REF libbash_name=3Dname) { $libbash_value=3Dwalker->resolve(libbash_name); }; + ^(VAR_REF libbash_name=3Dname) { $libbash_value =3D walker->resolve(libbash_name); } + |^(VAR_REF libbash_string=3Dvar_exp) { $libbash_value =3D libbash_strin= g; }; =20 // shell arithmetic arithmetics returns[int value] diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild index a5cadb6..62e95c3 100644 --- a/scripts/var_expansion.ebuild +++ b/scripts/var_expansion.ebuild @@ -1,2 +1,4 @@ EAPI=3D"3" EAPI4=3D"$(($EAPI+1))" +FOO=3D"${EAPI:-hello}" +FOO2=3D"${EAPI3:-hello}" diff --git a/scripts/var_expansion.ebuild.result b/scripts/var_expansion.= ebuild.result index cec88e4..f92abe4 100644 --- a/scripts/var_expansion.ebuild.result +++ b/scripts/var_expansion.ebuild.result @@ -1,2 +1,4 @@ EAPI=3D3 EAPI4=3D4 +FOO=3D3 +FOO2=3Dhello diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 1ce1076..2fc8703 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -410,5 +410,11 @@ public: new variable(name, value, readonly, is_null)); members.define(target); } + + const std::string do_default_expansion(const std::string& name, + const std::string& value) + { + return (is_null(name)? value : resolve(name)); + } }; #endif