Skip to content

Commit

Permalink
Make the Smalltalk generator use non-hardcoded namespaces.
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
David Reiss committed Mar 27, 2008
1 parent b3ac8a6 commit 3b45501
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
11 changes: 9 additions & 2 deletions compiler/cpp/src/generate/t_st_generator.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
21 changes: 0 additions & 21 deletions compiler/cpp/src/parse/t_program.h
Expand Up @@ -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
Expand Down Expand Up @@ -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_;
Expand Down
8 changes: 6 additions & 2 deletions compiler/cpp/src/thrifty.yy
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion thrift.el
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion thrift.vim
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tutorial.thrift
Expand Up @@ -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
Expand Down

0 comments on commit 3b45501

Please sign in to comment.