Make the Python generator use non-hardcoded namespaces.
authorDavid Reiss <dreiss@apache.org>
Thu, 27 Mar 2008 21:41:54 +0000 (21:41 +0000)
committerDavid Reiss <dreiss@apache.org>
Thu, 27 Mar 2008 21:41:54 +0000 (21:41 +0000)
- 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
compiler/cpp/src/parse/t_program.h
compiler/cpp/src/thrifty.yy
test/py/explicit_module/test1.thrift
thrift.el
thrift.vim

index 4521515..9eac2f2 100644 (file)
@@ -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();
     }
index bcb3967..6dcba86 100644 (file)
@@ -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_;
 
index 81c7360..53c6d81 100644 (file)
@@ -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
index 316a173..864b95c 100644 (file)
@@ -1,4 +1,4 @@
-py_module foo.bar.baz
+namespace py foo.bar.baz
 
 struct astruct {
   1: i32 how_unoriginal;
index e0cf6eb..0d0def8 100644 (file)
--- 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
index 3551dbc..d4f509c 100644 (file)
@@ -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