Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/
Date: Wed, 06 Apr 2011 07:43:23
Message-Id: cc66a932c3756730ddf11198999c39a4f6f9a9e1.betelgeuse@gentoo
1 commit: cc66a932c3756730ddf11198999c39a4f6f9a9e1
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Tue Apr 5 12:02:24 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 5 13:49:13 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cc66a932
7
8 Implement ${param:=w} and ${param:+w} expansion
9
10 ---
11 bashast/libbashWalker.g | 6 ++++++
12 scripts/var_expansion.ebuild | 4 ++++
13 scripts/var_expansion.ebuild.result | 5 +++++
14 src/core/interpreter.h | 20 ++++++++++++++++++++
15 4 files changed, 35 insertions(+), 0 deletions(-)
16
17 diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
18 index a25c58c..ad8e444 100644
19 --- a/bashast/libbashWalker.g
20 +++ b/bashast/libbashWalker.g
21 @@ -89,6 +89,12 @@ var_name returns[std::string libbash_value]
22 var_expansion returns[std::string libbash_value]:
23 ^(USE_DEFAULT var_name libbash_word=word) {
24 libbash_value = walker->do_default_expansion($var_name.libbash_value, libbash_word);
25 + }
26 + |^(ASSIGN_DEFAULT var_name libbash_word=word) {
27 + libbash_value = walker->do_assign_expansion($var_name.libbash_value, libbash_word);
28 + }
29 + |^(USE_ALTERNATE var_name libbash_word=word) {
30 + libbash_value = walker->do_alternate_expansion($var_name.libbash_value, libbash_word);
31 };
32
33 word returns[std::string libbash_value]:
34
35 diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild
36 index 533e7a7..f0ad504 100644
37 --- a/scripts/var_expansion.ebuild
38 +++ b/scripts/var_expansion.ebuild
39 @@ -5,3 +5,7 @@ FOO2="${EAPI3:-hello}"
40 FOO3=123
41 FOO4=$EAPI
42 FOO5=$(( 1+1 ))
43 +FOO6=${EAPI:=hello}
44 +FOO7=${FOO8:=hello}
45 +FOO9=${EAPI:+hello}
46 +FOO10=${NOT_EXIST:+hello}
47
48 diff --git a/scripts/var_expansion.ebuild.result b/scripts/var_expansion.ebuild.result
49 index bad2cf3..7d2e5ca 100644
50 --- a/scripts/var_expansion.ebuild.result
51 +++ b/scripts/var_expansion.ebuild.result
52 @@ -1,7 +1,12 @@
53 EAPI=3
54 EAPI4=4
55 FOO=3
56 +FOO10=
57 FOO2=hello
58 FOO3=123
59 FOO4=3
60 FOO5=2
61 +FOO6=3
62 +FOO7=hello
63 +FOO8=hello
64 +FOO9=hello
65
66 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
67 index ab6b9e8..aad8f48 100644
68 --- a/src/core/interpreter.h
69 +++ b/src/core/interpreter.h
70 @@ -424,5 +424,25 @@ public:
71 {
72 return (is_unset_or_null(name)? value : resolve<std::string>(name));
73 }
74 +
75 + /// \brief perform ${parameter:=word} expansion
76 + /// \param the name of the parameter
77 + /// \param the value of the word
78 + /// \return the expansion result
79 + const std::string do_assign_expansion(const std::string& name,
80 + const std::string& value)
81 + {
82 + return (is_unset_or_null(name)? set_value(name, value) : resolve<std::string>(name));
83 + }
84 +
85 + /// \brief perform ${parameter:+word} expansion
86 + /// \param the name of the parameter
87 + /// \param the value of the word
88 + /// \return the expansion result
89 + const std::string do_alternate_expansion(const std::string& name,
90 + const std::string& value)
91 + {
92 + return (is_unset_or_null(name)? "" : value);
93 + }
94 };
95 #endif