From 3b45501b5220ac2e8ab159c6cd8163467300f406 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 27 Mar 2008 21:40:46 +0000 Subject: [PATCH] Make the Smalltalk generator use non-hardcoded namespaces. - Make the Smalltalk generator use program->get_namespace("smalltalk.*") instead of program->get_smalltalk_{category|prefix}() - Eliminate the explicit "smalltalk_{category|prefix}" in t_program. - Deprecate the smalltalk_{category|prefix} tokens. - Update example .thrift files and syntax files. This was a little more complex than the others. We now convert "." to "-" in Smalltalk categories, because we no longer lex them as tok_st_identifier. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665601 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_st_generator.cc | 11 +++++++++-- compiler/cpp/src/parse/t_program.h | 21 --------------------- compiler/cpp/src/thrifty.yy | 8 ++++++-- thrift.el | 2 +- thrift.vim | 2 +- tutorial/tutorial.thrift | 2 +- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/compiler/cpp/src/generate/t_st_generator.cc b/compiler/cpp/src/generate/t_st_generator.cc index 312e2ba4103..cf93bdc068c 100644 --- a/compiler/cpp/src/generate/t_st_generator.cc +++ b/compiler/cpp/src/generate/t_st_generator.cc @@ -169,7 +169,7 @@ string t_st_generator::class_name() { } string t_st_generator::prefix(string class_name) { - string prefix = program_->get_smalltalk_prefix(); + string prefix = program_->get_namespace("smalltalk.prefix"); string name = capitalize(class_name); name = prefix.empty() ? name : (prefix + name); return name; @@ -206,7 +206,14 @@ void t_st_generator::close_generator() { } string t_st_generator::generated_category() { - string cat = program_->get_smalltalk_category(); + string cat = program_->get_namespace("smalltalk.category"); + // For compatibility with the Thrift grammar, the category must + // be punctuated by dots. Replaces them with dashes here. + for (string::iterator iter = cat.begin(); iter != cat.end(); ++iter) { + if (*iter == '.') { + *iter = '-'; + } + } return cat.size() ? cat : "Generated-" + class_name(); } diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index 72c3cddbf18..5d331a5331f 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -224,22 +224,6 @@ class t_program : public t_doc { return cocoa_prefix_; } - void set_smalltalk_category(std::string smalltalk_category) { - smalltalk_category_ = smalltalk_category; - } - - const std::string& get_smalltalk_category() const { - return smalltalk_category_; - } - - void set_smalltalk_prefix(std::string smalltalk_prefix) { - smalltalk_prefix_ = smalltalk_prefix; - } - - const std::string& get_smalltalk_prefix() const { - return smalltalk_prefix_; - } - private: // File path @@ -292,14 +276,9 @@ class t_program : public t_doc { // Perl namespace std::string perl_package_; - // Cocoa/Objective-C naming prefix std::string cocoa_prefix_; - // Smalltalk category - std::string smalltalk_category_; - // Smalltalk prefix - std::string smalltalk_prefix_; // C# namespace std::string csharp_namespace_; diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index db4a4a8eafe..36b9316995f 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -298,18 +298,22 @@ Header: g_program->set_ruby_namespace($2); } } +/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ | tok_smalltalk_category tok_st_identifier { + pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead"); pdebug("Header -> tok_smalltalk_category tok_st_identifier"); if (g_parse_mode == PROGRAM) { - g_program->set_smalltalk_category($2); + g_program->set_namespace("smalltalk.category", $2); } } +/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ | tok_smalltalk_prefix tok_identifier { + pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead"); pdebug("Header -> tok_smalltalk_prefix tok_identifier"); if (g_parse_mode == PROGRAM) { - g_program->set_smalltalk_prefix($2); + g_program->set_namespace("smalltalk.prefix", $2); } } /* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ diff --git a/thrift.el b/thrift.el index 3383aeec3e0..a8c6adb86b5 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\\|cocoa_prefix\\|csharp_namespace\\|php_namespace\\|ruby_namespace\\|py_module\\|perl_package\\|smalltalk_category\\|smalltalk_prefix\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords + '("\\<\\(include\\|struct\\|exception\\|typedef\\|cocoa_prefix\\|csharp_namespace\\|php_namespace\\|ruby_namespace\\|py_module\\|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 4cadaf76e98..115e9369685 100644 --- a/thrift.vim +++ b/thrift.vim @@ -31,7 +31,7 @@ syn match thriftNumber "-\=\<\d\+\>" contained " Keywords syn keyword thriftKeyword namespace cocoa_prefix -syn keyword thriftKeyword csharp_namespace smalltalk_category smalltalk_prefix +syn keyword thriftKeyword csharp_namespace syn keyword thriftKeyword php_namespace ruby_namespace py_module 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 diff --git a/tutorial/tutorial.thrift b/tutorial/tutorial.thrift index 3a1b7d2476e..8a72f60bff0 100755 --- a/tutorial/tutorial.thrift +++ b/tutorial/tutorial.thrift @@ -48,7 +48,7 @@ namespace cpp tutorial namespace java tutorial php_namespace tutorial perl_package tutorial -smalltalk_category Thrift-Tutorial +namespace smalltalk.category Thrift.Tutorial /** * Thrift lets you do typedefs to get pretty names for your types. Standard