From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/, test/
Date: Thu, 14 Apr 2011 04:50:14 +0000 (UTC) [thread overview]
Message-ID: <793965cb2dac5bb015538620796bc628b7618f44.betelgeuse@gentoo> (raw)
commit: 793965cb2dac5bb015538620796bc628b7618f44
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 02:29:35 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 13 08:26:40 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=793965cb
Support assigning empty value to variable
Syntax like 'a=' and 'a[1]=' is supported now.
---
bashast/bashast.g | 4 ++--
bashast/libbashWalker.g | 5 +++--
scripts/var_def.ebuild | 7 +++++++
scripts/var_def.ebuild.result | 4 ++++
src/core/interpreter.h | 7 ++++---
test/variable_printer.cpp | 2 +-
6 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 74fd5df..5fc5e7b 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -214,8 +214,8 @@ cond_comparison
//Defining a variable
//It's not legal to do FOO[1]=(a b c)
var_def
- : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS fname -> ^(EQUALS ^(name explicit_arithmetic) fname)
- | name EQUALS^ value;
+ : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS fname? -> ^(EQUALS ^(name explicit_arithmetic) fname?)
+ | name EQUALS^ value?;
//Possible values of a variable
value : fname
| LPAREN! wspace!? arr_val RPAREN!;
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f4fff5d..43304f1 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -71,9 +71,10 @@ var_def
@declarations {
std::map<int, std::string> values;
int index = 0;
+ bool is_null = true;
}:
- ^(EQUALS name libbash_string=string_expr){
- walker->set_value($name.libbash_value, libbash_string, $name.index);
+ ^(EQUALS name (libbash_string=string_expr { is_null = false; })?){
+ walker->set_value($name.libbash_value, libbash_string, $name.index, is_null);
}
|^(EQUALS libbash_name=name_base ^(ARRAY (
(libbash_string=string_expr
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index 5d336ee..06ebb3b 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -16,5 +16,12 @@ ARRAY=(1 2 3 [5]=4 5)
ARRAY2=(1 2 3)
ARRAY2[2]=4
ARRAY2[3]=5
+EMPTY=
ARRAY_LAST=${ARRAY[6]}
PARTIAL[5]=5
+EMPTY_ARRAY=()
+ARRAY3=(1 2 3)
+ARRAY3[0]=
+ARRAY4=(1 2 3)
+# The following one is equivalent to ARRAY4[0]=
+ARRAY4=
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index f288519..6433df7 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,10 +1,14 @@
ARRAY=1 2 3 4 5
ARRAY2=1 2 4 5
+ARRAY3=2 3
+ARRAY4=2 3
ARRAY_LAST=5
DEPEND=dev-db/sqlite:3
dev-util/pkgconfig
DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
EAPI=1
+EMPTY=
+EMPTY_ARRAY=
HOMEPAGE=http://sunpinyin.googlecode.com
IUSE=
KEYWORDS=~amd64 ~x86
diff --git a/src/core/interpreter.h b/src/core/interpreter.h
index 9166379..1e2babe 100644
--- a/src/core/interpreter.h
+++ b/src/core/interpreter.h
@@ -418,13 +418,14 @@ public:
template <typename T>
const T& set_value(const std::string& name,
const T& new_value,
- const unsigned index=0)
+ const unsigned index=0,
+ bool is_null=false)
{
std::shared_ptr<variable> value = members.resolve(name);
if(!value)
- define(name, new_value, false);
+ define(name, new_value, false, is_null);
else
- value->set_value(new_value, index);
+ value->set_value(new_value, index, is_null);
return new_value;
}
diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
index cb17b9d..32fc161 100644
--- a/test/variable_printer.cpp
+++ b/test/variable_printer.cpp
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
std::map<std::string, std::vector<std::string>> sorted(variables.begin(), variables.end());
using namespace boost::spirit::karma;
- std::cout << format((string << '=' << (string % ' ')) % eol, sorted) << std::endl;
+ std::cout << format((string << '=' << -(string % ' ')) % eol, sorted) << std::endl;
return 0;
}
next reply other threads:[~2011-04-14 4:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-14 4:50 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-04-14 4:50 [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/, test/ Petteri Räty
2011-04-27 15:11 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=793965cb2dac5bb015538620796bc628b7618f44.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox