From 320e45ce8b1d2721a7f814c1e1a8288dba36dd14 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 27 Mar 2008 21:41:54 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_py_generator.cc | 2 +- compiler/cpp/src/parse/t_program.h | 11 ----------- compiler/cpp/src/thrifty.yy | 4 +++- test/py/explicit_module/test1.thrift | 2 +- thrift.el | 2 +- thrift.vim | 2 +- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc index 4521515a..9eac2f28 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -151,7 +151,7 @@ class t_py_generator : public t_generator { 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 bcb39672..6dcba86d 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -192,14 +192,6 @@ class t_program : public t_doc { 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 @@ class t_program : public t_doc { // 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 81c73607..53c6d819 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -277,11 +277,13 @@ Header: 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 316a1732..864b95cf 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 e0cf6ebf..0d0def8b 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 3551dbce..d4f509c8 100644 --- a/thrift.vim +++ b/thrift.vim @@ -31,7 +31,7 @@ syn match thriftNumber "-\=\<\d\+\>" contained " 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 -- 2.17.1