Make the Python generator use non-hardcoded namespaces.
- Make the Python generator use program->get_namespace("py")
instead of program->get_py_module()
- Eliminate the explicit "py_module" in t_program.
- Deprecate the py_module token.
- Update example .thrift files and syntax files.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665615 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 4521515..9eac2f2 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -151,7 +151,7 @@
std::string type_to_spec_args(t_type* ttype);
static std::string get_real_py_module(const t_program* program) {
- std::string real_module = program->get_py_module();
+ std::string real_module = program->get_namespace("py");
if (real_module.empty()) {
return program->get_name();
}
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index bcb3967..6dcba86 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -192,14 +192,6 @@
return ruby_namespace_;
}
- void set_py_module(std::string py_module) {
- py_module_ = py_module;
- }
-
- const std::string& get_py_module() const {
- return py_module_;
- }
-
void set_perl_package(std::string perl_package) {
perl_package_ = perl_package;
}
@@ -255,9 +247,6 @@
// Ruby namespace
std::string ruby_namespace_;
- // Python namespace
- std::string py_module_;
-
// Perl namespace
std::string perl_package_;
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index 81c7360..53c6d81 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -277,11 +277,13 @@
g_program->set_php_namespace($2);
}
}
+/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_py_module tok_identifier
{
+ pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
pdebug("Header -> tok_py_module tok_identifier");
if (g_parse_mode == PROGRAM) {
- g_program->set_py_module($2);
+ g_program->set_namespace("py", $2);
}
}
| tok_perl_package tok_identifier
diff --git a/test/py/explicit_module/test1.thrift b/test/py/explicit_module/test1.thrift
index 316a173..864b95c 100644
--- a/test/py/explicit_module/test1.thrift
+++ b/test/py/explicit_module/test1.thrift
@@ -1,4 +1,4 @@
-py_module foo.bar.baz
+namespace py foo.bar.baz
struct astruct {
1: i32 how_unoriginal;
diff --git a/thrift.el b/thrift.el
index e0cf6eb..0d0def8 100644
--- a/thrift.el
+++ b/thrift.el
@@ -10,7 +10,7 @@
(defconst thrift-font-lock-keywords
(list
'("#.*$" . font-lock-comment-face) ;; perl style comments
- '("\\<\\(include\\|struct\\|exception\\|typedef\\|php_namespace\\|ruby_namespace\\|py_module\\|perl_package\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords
+ '("\\<\\(include\\|struct\\|exception\\|typedef\\|php_namespace\\|ruby_namespace\\|perl_package\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords
'("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face) ;; built-in types
'("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face) ;; ordinals
'("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions
diff --git a/thrift.vim b/thrift.vim
index 3551dbc..d4f509c 100644
--- a/thrift.vim
+++ b/thrift.vim
@@ -31,7 +31,7 @@
" Keywords
syn keyword thriftKeyword namespace
-syn keyword thriftKeyword php_namespace ruby_namespace py_module perl_package
+syn keyword thriftKeyword php_namespace ruby_namespace perl_package
syn keyword thriftKeyword xsd_all xsd_optional xsd_nillable xsd_namespace xsd_attrs
syn keyword thriftKeyword include cpp_include cpp_type const optional required
syn keyword thriftBasicTypes void bool byte i16 i32 i64 double string binary