talk 2.2.4 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 963aee9e434631bd8d20cd86f11645b6478425e9
4
- data.tar.gz: 364d02b88f3a18aa97c40001314140453b34f00d
3
+ metadata.gz: 0a80291fbc647d3d33efc33910bd6f03f59133fa
4
+ data.tar.gz: 413f5cb78048b0a4f786962f63d6db7f1c9949d6
5
5
  SHA512:
6
- metadata.gz: 9bd86f190ae3dc6863b78620bd484ef63b78f7481569c04ea8ecac4c895eb5dbf6728c460affb2a55d506d747be72181b235662ac5367a1bc4ee2593f10f24c9
7
- data.tar.gz: e526a3c98a908f0c3dc9c638ebf9bc51084a933fc9edb0ad91ecf08d7ccb4e1dc86fc0540cd4167f94005b3182b88600e546b638131234e0e0ca68ca18038fa2
6
+ metadata.gz: c23f63f43dbe835647da59d19e628c4533051b889c6657bc2f924f2dfbda90e9c0dc7ad50c5a00eaeb86224c251c1d9628e8e605a87180e351055c96c0d05dee
7
+ data.tar.gz: 892e8693ecf5a7b8f7606e035849c102872330d8bf337c99975760477a29ddcc0ef15fcc0fb4d4d3753c750b30afd19f42e8a3ad395d3fd82ccc547dcd1f1974
@@ -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.2.4"
2
+ VERSION = "2.2.5"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = Talk::VERSION
9
9
  s.date = '2014-06-12'
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 2.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Acres
@@ -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
@@ -99,6 +99,11 @@ files:
99
99
  - lib/contexts/string.rb
100
100
  - lib/contexts/target.rb
101
101
  - lib/contexts/term.rb
102
+ - lib/languages/cs/cs.rb
103
+ - lib/languages/cs/templates/TalkProtocol.cs.erb
104
+ - lib/languages/cs/templates/class.cs.erb
105
+ - lib/languages/cs/templates/enumeration.cs.erb
106
+ - lib/languages/cs/templates/glossary.cs.erb
102
107
  - lib/languages/java/java.rb
103
108
  - lib/languages/java/templates/TalkProtocol.java.erb
104
109
  - lib/languages/java/templates/class.java.erb