* [gentoo-commits] proj/libbash:master commit in: src/, scripts/, bashast/, test/
@ 2011-04-12 18:29 Petteri Räty
0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-04-12 18:29 UTC (permalink / raw
To: gentoo-commits
commit: d175a4aeae470067af1d7680e0ce386ad9441c58
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 12 02:08:57 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 07:30:22 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d175a4ae
Implement array definition
Storing the value of an array variable in std::string is not good.
So we change the container for variable value to std::vector.
---
bashast/libbashWalker.g | 13 ++++++++++++-
scripts/var_def.ebuild | 2 ++
scripts/var_def.ebuild.result | 2 ++
src/libbash.cpp | 4 ++--
src/libbash.h | 3 ++-
test/api_test.cpp | 2 +-
test/variable_printer.cpp | 6 +++---
7 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 06ff2f8..e0add2a 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -55,9 +55,20 @@ options{ k=1; }:
DIGIT { $libbash_value = walker->get_string($DIGIT); }
|NUMBER { $libbash_value = walker->get_string($NUMBER); };
-var_def:
+var_def
+@declarations {
+ std::map<int, std::string> values;
+ int index = 0;
+}:
^(EQUALS libbash_name=name libbash_value=word){
walker->define(libbash_name, libbash_value);
+ }
+ |^(EQUALS libbash_name=name ^(ARRAY (
+ (libbash_string=string_expr
+ |^(EQUALS value=arithmetics { index = value; } libbash_string=string_expr))
+ { values[index++] = libbash_string; })*
+ )){
+ walker->define(libbash_name, values);
};
string_expr returns[std::string libbash_value]:
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index acb132b..3dfeb80 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -11,3 +11,5 @@ RDEPEND="dev-db/sqlite:3"
DEPEND="${RDEPEND}
dev-util/pkgconfig"
MY_PATCH=ldflags.patch
+PATCH=("1.patch" 2.patch)
+ARRAY=(1 2 3 [5]=4)
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 71872a4..3e19cdb 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,3 +1,4 @@
+ARRAY=1 2 3 4
DEPEND=dev-db/sqlite:3
dev-util/pkgconfig
DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
@@ -7,6 +8,7 @@ IUSE=
KEYWORDS=~amd64 ~x86
LICENSE=LGPL-2.1 CDDL
MY_PATCH=ldflags.patch
+PATCH=1.patch 2.patch
RDEPEND=dev-db/sqlite:3
SLOT=0
SRC_URI=http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
diff --git a/src/libbash.cpp b/src/libbash.cpp
index be34b44..3dd03c6 100644
--- a/src/libbash.cpp
+++ b/src/libbash.cpp
@@ -33,7 +33,7 @@
namespace libbash
{
void interpret(const std::string& path,
- std::unordered_map<std::string, std::string>& variables)
+ std::unordered_map<std::string, std::vector<std::string>>& variables)
{
std::ifstream input(path.c_str());
if(!input)
@@ -42,6 +42,6 @@ namespace libbash
walker_builder wbuilder = pbuilder.create_walker_builder();
for(auto iter = wbuilder.walker->begin(); iter != wbuilder.walker->end(); ++iter)
- variables[iter->first]=iter->second->get_value<std::string>();
+ iter->second->get_all_values<std::string>(variables[iter->first]);
}
}
diff --git a/src/libbash.h b/src/libbash.h
index c403ec4..01ea5e4 100644
--- a/src/libbash.h
+++ b/src/libbash.h
@@ -28,6 +28,7 @@
#include <memory>
#include <string>
#include <unordered_map>
+#include <vector>
#include "common.h"
#include "core/interpreter_exception.h"
@@ -40,7 +41,7 @@ namespace libbash
/// \param the path of target script
/// \param the map to store variables
void LIBBASH_API interpret(const std::string& path,
- std::unordered_map<std::string, std::string>& variables);
+ std::unordered_map<std::string, std::vector<std::string>>& variables);
}
#endif
diff --git a/test/api_test.cpp b/test/api_test.cpp
index 5972f14..14ab059 100644
--- a/test/api_test.cpp
+++ b/test/api_test.cpp
@@ -30,7 +30,7 @@ using namespace std;
TEST(libbashapi, bad_path)
{
- std::unordered_map<std::string, std::string> variables;
+ std::unordered_map<std::string, std::vector<std::string>> variables;
EXPECT_THROW(libbash::interpret("not exist", variables),
interpreter_exception);
}
diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
index cb839f2..cb17b9d 100644
--- a/test/variable_printer.cpp
+++ b/test/variable_printer.cpp
@@ -40,13 +40,13 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
- std::unordered_map<std::string, std::string> variables;
+ std::unordered_map<std::string, std::vector<std::string>> variables;
libbash::interpret(argv[1], variables);
- std::map<std::string, std::string> sorted(variables.begin(), variables.end());
+ 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;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-04-12 18:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-12 18:29 [gentoo-commits] proj/libbash:master commit in: src/, scripts/, bashast/, test/ Petteri Räty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox