talk 2.3.6 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1a5abbb15a585fc235b8447ce7811f92ca3b14b
4
- data.tar.gz: aa468079200186fdef8d92913c903f4b9539a7b3
3
+ metadata.gz: ba013c3a9959cffe8437109544ac80fe0ba56656
4
+ data.tar.gz: 9ecc6df80df26fbc85110f9fa8a73ce31b42003d
5
5
  SHA512:
6
- metadata.gz: 7ef638efe6c9b72b9b5a32d42b65af49a846a6122a1aeb42ece3e50872a9590397761933870c6aa14b3edd15118be7eb7f955e5c9de01c1f56d14f79b11d90cc
7
- data.tar.gz: d940a4a534110ec594fe6f5072265364c0afdae689598f10d18dd2aa679e542bcfa3a9d6cb5c4ccb08cffd0a38ff8bf6063727e1b6114a60c8d26b1526a09508
6
+ metadata.gz: 97162e8d65b4b6946150b51958ebca5a50073b01e9f2aa89b2323818882dd273660b45073ba48ae8983b8f3520085505294754a13b4a838a69923fe28b7d2796
7
+ data.tar.gz: 495194289d8326087d0bf98c3b504ac597647320abb54a4cb265f1f71e5236dd3b2767ce0f1e00f109902801881746ecc96a9e6ade0f9df6be041e0b969ae353
data/CHANGELOG CHANGED
@@ -1 +1,2 @@
1
+ 2.3.7 - Add C# generator
1
2
  2.3.6 - Fix crashes in JS generator
@@ -0,0 +1,183 @@
1
+ require 'set'
2
+
3
+ def make_source
4
+ types = [ :class, :enumeration, :glossary]
5
+ types.each do |type|
6
+ @base[type].each do |current|
7
+ @current = current
8
+ @current[:field] ||= [] if type == :class
9
+ generate_template(filename_for_entity(@current), type.to_s+".cs.erb")
10
+ end
11
+ end
12
+ @base[:protocol].each do |current|
13
+ @current = current
14
+ generate_template("com/acres4/common/protocol/#{current[:name]}.cs", "TalkProtocol.cs.erb")
15
+ end
16
+ end
17
+
18
+ def filename_for_entity(name)
19
+ name = name[:name] if name.is_a? Hash
20
+ name.gsub(".", "/") + ".cs"
21
+ end
22
+
23
+ def autogenerated_warning
24
+ <<-AUTOGEN_DONE
25
+ /* Autogenerated from Talk
26
+ ** Please do not edit this file directly. Instead, modify the underlying .talk files. */
27
+ AUTOGEN_DONE
28
+ end
29
+
30
+ def definition_reference(tag)
31
+ "@talkFile #{tag[:__meta][:file]}:#{tag[:__meta][:line]}"
32
+ end
33
+
34
+ def rootclass
35
+ @target[:rootclass] || "io.usetalk.TalkObject"
36
+ end
37
+
38
+ def superclass(cls)
39
+ cls[:inherits] || rootclass
40
+ end
41
+
42
+ def class_package(cls)
43
+ cls[:name].split(".")[0..-2].join(".")
44
+ end
45
+
46
+ def list_references_for_class(cls)
47
+ references = Set.new
48
+ cls[:field].each do |field|
49
+ unless is_primitive?(field[:type].first) then
50
+ references.add( class_package( class_named(field[:type][0], @base[:class]) ))
51
+ end
52
+ end
53
+
54
+ references.add("System.Collections.Generic") if class_has_map(cls)
55
+ references.to_a
56
+ end
57
+
58
+ def class_has_map(cls)
59
+ cls[:field].each do |f|
60
+ return true if f[:type].include? "{}"
61
+ end
62
+
63
+ false
64
+ end
65
+
66
+ def import_classes
67
+ (list_references_for_class(@current).map { |name| "using #{name};"}).join("\n")
68
+ end
69
+
70
+ def comment_block(tag, indent_level=0)
71
+ lines = []
72
+ indent = "\t" * indent_level
73
+ lines.push(indent)
74
+ lines.push(indent + "/**")
75
+ lines.push(wrap_text_to_width(tag[:description], 80, indent + " * ")) unless tag[:description].nil?
76
+ lines.push(indent + " * ")
77
+ lines.push(indent + " * " + definition_reference(tag))
78
+ lines.push(indent + " */")
79
+
80
+ lines.join("\n")
81
+ end
82
+
83
+ def field_datatype_rec(field, stack)
84
+ return field_datatype_basic(field, stack.last) if stack.length == 1
85
+ t = stack.last
86
+
87
+ r = field_datatype_rec(field, stack[0 .. -2])
88
+ if is_array? t then
89
+ "#{r}[]"
90
+ elsif is_dict? t then
91
+ "Dictionary<string, #{convert_field_for_map(r)}>"
92
+ else
93
+ nil
94
+ end
95
+ end
96
+
97
+ def convert_field_for_map(field)
98
+ case field
99
+ when "byte"
100
+ "byte"
101
+ when "short"
102
+ "short"
103
+ when "int"
104
+ "int"
105
+ when "long"
106
+ "long"
107
+ when "double"
108
+ "double"
109
+ else
110
+ field
111
+ end
112
+ end
113
+
114
+ def field_datatype_basic(field, type)
115
+ if is_primitive? type then
116
+ case type
117
+ when "string"
118
+ "string"
119
+ when "real"
120
+ "double"
121
+ when "bool"
122
+ "bool"
123
+ when "object"
124
+ "object"
125
+ when "talkobject"
126
+ rootclass
127
+ when "int8"
128
+ "sbyte"
129
+ when "uint8"
130
+ "byte"
131
+ when "int16"
132
+ "short"
133
+ when "uint16"
134
+ "ushort"
135
+ when "int32"
136
+ "int"
137
+ when "uint32"
138
+ "uint"
139
+ when "int64"
140
+ "long"
141
+ when "uint64"
142
+ "ulong"
143
+ end
144
+ else
145
+ truncated_name type
146
+ end
147
+ end
148
+
149
+ def field_datatype(field)
150
+ field_datatype_rec(field, field[:type])
151
+ end
152
+
153
+ def field_variable(cls,field)
154
+ lines = []
155
+ lines.push comment_block(field, 2)
156
+ lines.push "\t\tpublic #{field_datatype(field)} #{mapped_name(cls, field, :field)} { get; set; }"
157
+ lines.join("\n")
158
+ end
159
+
160
+ def setter_name(field)
161
+ "set#{field[:name].sub(/^(\w)/) {|s| s.capitalize}}"
162
+ end
163
+
164
+ def getter_name(field)
165
+ "get#{field[:name].sub(/^(\w)/) {|s| s.capitalize}}"
166
+ end
167
+
168
+ def field_accessors(cls, field)
169
+ lines = []
170
+ lines.push "\t\t/**"
171
+ lines.push "\t\t#{wrap_text_to_width(field[:description])}"
172
+ lines.push "\t\t#{field[:deprecated] if field.has_key? :deprecated}"
173
+ lines.push "\t\t#{definition_reference(field)}"
174
+ lines.push "\t\t@param #{field[:name]} #{field[:description]}"
175
+ lines.push "\t\t*/"
176
+ lines.push "\t\tpublic void #{setter_name(field)}(#{field_datatype(field)} #{mapped_name(cls, field,:field)}) {"
177
+ lines.push "\t\t\tthis.#{mapped_name(cls, field, :field)} = #{mapped_name(cls, field, :field)};"
178
+ lines.push "\t\t}"
179
+ lines.push "\t\tpublic #{field_datatype(field)} #{getter_name(field)}() {"
180
+ lines.push "\t\t\treturn this.#{mapped_name(cls, field, :field)};"
181
+ lines.push "\t\t}"
182
+ lines.join "\n"
183
+ end
@@ -0,0 +1,14 @@
1
+ <%= autogenerated_warning %>
2
+ namespace com.acres4.common.protocol
3
+ {
4
+ public class <%= truncated_name(@current[:name]) %>
5
+ {
6
+ <% @current[:method].each do |method| %>
7
+ /**
8
+ <%= method[:description] %>
9
+ */
10
+ public static readonly string <%= method[:name].sub(/^(\w)/) {|s| s.capitalize} %> = "<%= method[:name] %>";
11
+
12
+ <% end %>
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ <%= autogenerated_warning %>
2
+ <%= import_classes %>
3
+ namespace <%= class_package(@current) %>
4
+ {
5
+ <%= comment_block(@current,1) %>
6
+ public class <%= truncated_name(@current) %> : <%= superclass(@current) %>
7
+ {
8
+ <%= (@current[:field].map do |f| field_variable(truncated_name(@current),f) end).join("\n") %>
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ <%= autogenerated_warning %>
2
+ namespace <%= class_package(@current) %>
3
+ {
4
+ <%= comment_block(@current) %>
5
+ public class <%= truncated_name(@current) %> : <%= rootclass %>
6
+ {<% @current[:constant].each do |field| %>
7
+ /** <%= field[:description] %> */
8
+ public readonly static int <%= field[:name] %> = <%= field[:value].to_i %>;
9
+ <% end %>
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ <%= autogenerated_warning %>
2
+ namespace <%= class_package(@current) %>
3
+ {
4
+ <%= comment_block(@current) %>
5
+ public class <%= truncated_name(@current) %>
6
+ {
7
+ <% @current[:term].each do |field| %>
8
+ public readonly static string <%= field[:name] %> = "<%= field[:value] %>";<% end %>
9
+ }
10
+ }
@@ -1,3 +1,3 @@
1
1
  module Talk
2
- VERSION = "2.3.6"
2
+ VERSION = "2.3.7"
3
3
  end
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = 'talk'
7
7
  s.executables << 'maketalk'
8
8
  s.version = Talk::VERSION
9
- s.date = '2014-07-31'
9
+ s.date = '2014-08-25'
10
10
  s.summary = "Compile-to-source protocol contract specification language"
11
- s.description = "A lightweight language for specifying protocol contracts. Compiles to source in Java, Javascript, ObjC and Ruby."
11
+ s.description = "A lightweight language for specifying protocol contracts. Compiles to source in Java, CSharp, Javascript, ObjC and Ruby."
12
12
  s.authors = ["Jonas Acres"]
13
13
  s.email = 'jonas@becuddle.com'
14
14
  s.homepage = 'http://github.com/jonasacres/talk'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Acres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-31 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.12.1
55
55
  description: A lightweight language for specifying protocol contracts. Compiles to
56
- source in Java, Javascript, ObjC and Ruby.
56
+ source in Java, CSharp, Javascript, ObjC and Ruby.
57
57
  email: jonas@becuddle.com
58
58
  executables:
59
59
  - maketalk
@@ -101,6 +101,11 @@ files:
101
101
  - lib/contexts/string.rb
102
102
  - lib/contexts/target.rb
103
103
  - lib/contexts/term.rb
104
+ - lib/languages/cs/cs.rb
105
+ - lib/languages/cs/templates/TalkProtocol.cs.erb
106
+ - lib/languages/cs/templates/class.cs.erb
107
+ - lib/languages/cs/templates/enumeration.cs.erb
108
+ - lib/languages/cs/templates/glossary.cs.erb
104
109
  - lib/languages/java/java.rb
105
110
  - lib/languages/java/templates/TalkProtocol.java.erb
106
111
  - lib/languages/java/templates/class.java.erb