talk 2.2.7 → 2.3.0

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: 6cccb79ea7fa1b5aff58e44804d7a6faf3e5f8e4
4
- data.tar.gz: 17a38cc100e492b6e8a5d5c2c027ac015936a313
3
+ metadata.gz: 17af9791fad56df5e635906a3eebd9b2a0ac668b
4
+ data.tar.gz: fce31b459bb50cda0529202c6243621a1ffe1008
5
5
  SHA512:
6
- metadata.gz: 222f47a4e9deed38fcd4379001361c95c1373d11bfd55c8d6dd8b2b447a15dab0c2385ca73dfa7e49a76dda395f8244a2b611aafc1677f8ddf2dcf7051a57fd4
7
- data.tar.gz: 35fe8c0ed55b714d9d4ba9ca482d147de4c78d872f215977d3f5dac689c801e1856a4afba211d8d83406311e14cc85530915231c61def64eb1660788da6fc074
6
+ metadata.gz: fd168905d6edaae2941893cc76434f06bc38f63e08c942927b841cc10a79e28b606aca5a6cf5e95a68fc4185bba80053fe6b621ca7c1c9d049811603d309f0cd
7
+ data.tar.gz: 521827ceadf656d198a33840b4d7da62b344bf684d8afd9c228648ffb3beac736799f5d8cf0a06f7795c898b51afd4b05c2034b4c0eeb846278b260d7e9bcee5
@@ -10,7 +10,7 @@ require 'trollop'
10
10
  require 'pp'
11
11
 
12
12
  $opts = Trollop::options do
13
- version "Talk #{Talk::VERSION} (c) 2013 Jonas Acres"
13
+ version "Talk 2.0 (c) 2013 Jonas Acres"
14
14
  banner <<-EOS
15
15
  Talk is a compile-to-source protocol specification language.
16
16
 
@@ -26,7 +26,6 @@ EOS
26
26
  opt :no, "Do not render specified tag type at any level", :type => :string, :multi => true
27
27
  opt :json, "Dump raw JSON to console"
28
28
  opt :upgrade, "Upgrade old-style protocols to new-style"
29
- opt :version, "Show Talk version"
30
29
  end
31
30
 
32
31
  Trollop::die :omit, "cannot be combined with include" if $opts[:omit].length > 0 and $opts[:include].length > 0
@@ -114,6 +113,7 @@ end
114
113
 
115
114
  def upgrade_protocols(results)
116
115
  methods = {}
116
+ return if results[:method].nil? || results[:method].empty?
117
117
  results[:method].each { |method| methods[method[:name].to_sym] = method }
118
118
  results[:protocol].each do |proto|
119
119
  proto[:method].map! { |method| methods[method.to_sym] }
@@ -274,7 +274,8 @@ module Talk
274
274
 
275
275
  return v.to_val if @class_methods[v.class].include? :to_val
276
276
  return v.to_h if @class_methods[v.class].include? :to_h
277
- return v.to_f if v.is_a? Fixnum or v.is_a? Float
277
+ return v.to_f if(v.is_a?(Fixnum) || v.is_a?(Float))
278
+ return v if (v == true || v == false)
278
279
 
279
280
  v.to_s
280
281
  end
@@ -1,5 +1,4 @@
1
1
  tag :class, :multi => true
2
- tag :method, :multi => true
3
2
  tag :enumeration, :multi => true
4
3
  tag :protocol, :multi => true
5
4
  tag :target, :multi => true
@@ -1,15 +1,12 @@
1
1
  # register :methods
2
2
  reference :response, :classes, :skip => ["none"]
3
3
  reference :request, :classes, :skip => ["none"]
4
- reference :followup, :classes, :skip => ["none"]
5
4
 
6
5
  property :name
7
6
 
8
7
  tag_description
9
- tag :response, :class => :string
10
8
  tag :request, :class => :string
11
- tag :followup, :class => :string
12
- tag :requirements, :class => :string
9
+ tag :response, :class => :string
13
10
  tag :origin, :class => :string, :allowed => [ "client", "server", "both" ]
14
-
11
+ tag :needs, :class => :string, :allowed => [ "nothing", "connection", "both" ]
15
12
  tag_end
@@ -3,6 +3,7 @@ register :protocols
3
3
  property :name
4
4
 
5
5
  tag_description
6
- tag :method, :class => :string, :required => true, :multi => true
6
+ tag :scheme, :multi => true, :required => true
7
+ tag :method, :required => true, :multi => true
7
8
  tag :source, :class => :string
8
9
  tag_end
@@ -0,0 +1,2 @@
1
+ property :secure, :transform => lambda { |ctx,v| v=='secure' }
2
+ property :name
@@ -42,12 +42,10 @@ def class_line(cls)
42
42
  out << "// " + cls[:name]
43
43
 
44
44
  fields = {}
45
- unless cls[:field].nil? then
46
- cls[:field].each do |field|
47
- mapped = mapped_name(cls[:name], field[:name], :field)
48
- fields[mapped] = {typeStack:field[:type]}
49
- fields[mapped][:canonicalName] = field[:name] unless mapped == field[:name]
50
- end
45
+ cls[:field].each do |field|
46
+ mapped = mapped_name(cls[:name], field[:name], :field)
47
+ fields[mapped] = {typeStack:field[:type]}
48
+ fields[mapped][:canonicalName] = field[:name] unless mapped == field[:name]
51
49
  end
52
50
 
53
51
  out << "TalkObject.addClass('#{cls[:name]}', #{fields.to_json}, '#{truncated_name(superclass(cls))}');"
@@ -142,11 +142,6 @@ TalkObject.prototype.__validateInteger = function(key, param, unsigned, size)
142
142
  var def = this.__definition[key];
143
143
 
144
144
  // Validate number
145
- if(typeof(param) == 'string')
146
- {
147
- if(param.match(new RegExp("^(0x)?[0-9]+$"))) param = parseInt(param);
148
- }
149
-
150
145
  if(typeof(param) != 'number')
151
146
  {
152
147
  var errMsg = "Expected " + key + " to be a number";
@@ -231,10 +226,6 @@ TalkObject.prototype.__validateInteger = function(key, param, unsigned, size)
231
226
  TalkObject.prototype.__validateReal = function(key, param)
232
227
  {
233
228
  var def = this.__definition[key];
234
- if(typeof(param) == 'string')
235
- {
236
- if(param.match(new RegExp("^[0-9]+(\.[0-9]+)?$"))) param = parseFloat(param);
237
- }
238
229
  if(typeof(param) != 'number') return "Expected numeric value for " + key;
239
230
  if(def.minValue !== undefined && def.minValue !== null && param < def.minValue)
240
231
  {
@@ -1,6 +1,6 @@
1
1
  def make_source
2
2
  @prefix = common_class_prefix if meta(:namespace) == "true"
3
- master_files = [ "TalkClasses.h", "TalkClassesForward.h", "TalkConstants.h", "TalkObjectList.h"]
3
+ master_files = [ "TalkClasses.h", "TalkClassesForward.h", "TalkConstants.h", "TalkObjectList.h", "TalkDefinition+Autogenerated.m" ]
4
4
  master_files.each { |template| generate_template(template) }
5
5
 
6
6
  @base[:class].each do |cls|
@@ -81,10 +81,14 @@ def assist_line(field)
81
81
  "@[#{stringified.join(",")}]"
82
82
  end
83
83
 
84
+ def protocol_constant_name(name)
85
+ name = (name.split("/").map { |x| x[0].upcase + x[1..-1] }).join("")
86
+ "kProto#{name}"
87
+ end
88
+
84
89
  def protocol_method_name(p_name, m_name)
85
- p_name = p_name[0].upcase + p_name[1..-1]
86
90
  m_name = m_name[0].upcase + m_name[1..-1]
87
- "kProto#{p_name}Method#{m_name}"
91
+ "#{protocol_constant_name(p_name)}Method#{m_name}"
88
92
  end
89
93
 
90
94
  def class_field_maps(cls)
@@ -138,3 +142,11 @@ def field_definition(cls, field)
138
142
  end
139
143
  "#{objc_type} #{mapped_name(cls, field, :field)}"
140
144
  end
145
+
146
+ def safe_escape(str)
147
+ str.gsub("\\", "\\\\\\").gsub("\"", "\\\"")
148
+ end
149
+
150
+ def talk_definition
151
+ @base
152
+ end
@@ -25,6 +25,7 @@ enum <%= truncated_name(enumeration[:name]) %>
25
25
 
26
26
  // @protocol <%= protocol[:name] %>
27
27
  <%= comment_block(protocol) %>
28
+ #define <%= protocol_constant_name(protocol[:name]) %> @"<%= protocol[:name] %>"
28
29
 
29
30
  <% protocol[:method].each do |method| %>
30
31
  <%= comment_block(method) %>
@@ -0,0 +1,10 @@
1
+ #import "TalkDefinition.h"
2
+
3
+ @implementation TalkDefinition (Automap)
4
+
5
+ +(NSString *) talkJson
6
+ {
7
+ return @"<%= safe_escape(talk_definition.to_json) %>";
8
+ }
9
+
10
+ @end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'version.rb'
4
3
  require 'parser'
5
4
  require 'languages/language.rb'
5
+
@@ -1,14 +1,10 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'version'
4
-
5
1
  Gem::Specification.new do |s|
6
2
  s.name = 'talk'
7
3
  s.executables << 'maketalk'
8
- s.version = Talk::VERSION
4
+ s.version = '2.3.0'
9
5
  s.date = '2014-06-12'
10
6
  s.summary = "Compile-to-source protocol contract specification language"
11
- s.description = "A lightweight language for specifying protocol contracts. Compiles to source in Java, CSharp, Javascript, ObjC and Ruby."
7
+ s.description = "A lightweight language for specifying protocol contracts. Compiles to source in Java, Javascript, ObjC and Ruby."
12
8
  s.authors = ["Jonas Acres"]
13
9
  s.email = 'jonas@becuddle.com'
14
10
  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.7
4
+ version: 2.3.0
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, CSharp, Javascript, ObjC and Ruby.
56
+ source in Java, Javascript, ObjC and Ruby.
57
57
  email: jonas@becuddle.com
58
58
  executables:
59
59
  - maketalk
@@ -96,14 +96,10 @@ files:
96
96
  - lib/contexts/numeric.rb
97
97
  - lib/contexts/protocol.rb
98
98
  - lib/contexts/reference.rb
99
+ - lib/contexts/scheme.rb
99
100
  - lib/contexts/string.rb
100
101
  - lib/contexts/target.rb
101
102
  - 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
107
103
  - lib/languages/java/java.rb
108
104
  - lib/languages/java/templates/TalkProtocol.java.erb
109
105
  - lib/languages/java/templates/class.java.erb
@@ -116,6 +112,7 @@ files:
116
112
  - lib/languages/objc/templates/TalkClasses.h.erb
117
113
  - lib/languages/objc/templates/TalkClassesForward.h.erb
118
114
  - lib/languages/objc/templates/TalkConstants.h.erb
115
+ - lib/languages/objc/templates/TalkDefinition+Autogenerated.m.erb
119
116
  - lib/languages/objc/templates/TalkObjectList.h.erb
120
117
  - lib/languages/objc/templates/class.h.erb
121
118
  - lib/languages/objc/templates/class.m.erb
@@ -123,7 +120,6 @@ files:
123
120
  - lib/parser.rb
124
121
  - lib/registry.rb
125
122
  - lib/talk.rb
126
- - lib/version.rb
127
123
  - talk.gemspec
128
124
  homepage: http://github.com/jonasacres/talk
129
125
  licenses:
@@ -1,183 +0,0 @@
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
@@ -1,14 +0,0 @@
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 const string <%= method[:name].sub(/^(\w)/) {|s| s.capitalize} %> = "<%= method[:name] %>";
11
-
12
- <% end %>
13
- }
14
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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 const int <%= field[:name] %> = <%= field[:value].to_i %>;
9
- <% end %>
10
- }
11
- }
@@ -1,10 +0,0 @@
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 const string <%= field[:name] %> = "<%= field[:value] %>";<% end %>
9
- }
10
- }
@@ -1,3 +0,0 @@
1
- module Talk
2
- VERSION = "2.2.7"
3
- end