stark 0.9.3 → 0.10.0

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: ee88e66907614d95a281f6fd2652090d72819597
4
- data.tar.gz: 91e8a4938a10133026421032e509fa919a302662
3
+ metadata.gz: eb7324236d30ca7b3ac671be85de15c61711ca00
4
+ data.tar.gz: b66c8a55bbe142c278412b3a3275449cb52cba04
5
5
  SHA512:
6
- metadata.gz: 15d9b264ee7df0283b7158eb8395d41ec4ef870188d0343f31e96b612ad9550c6c6b857a0eaf29eb9fd547215d30562fb17aaef4320e5fc09f57aa6e6fb20cef
7
- data.tar.gz: 48be3431365f17b3684c6d0b0b82ffc857651d0ed2ca6c4dff10a750e2b067c74422a4400cdf0ad90867984d9b2abda25c9c07c0f41ba8c81b157e8bbb2d5381
6
+ metadata.gz: 1480bd6c16afaee07d84d803de9d816fe0a278e2287a79da0e9c12cc0e0b92a8679ac47baf5277ee83431b11cc4fded15f63646edcefec1441b301261cde1ba3
7
+ data.tar.gz: 4a0a15ae192c3f0cff13c49054ee4dde6414ae4c892059eca7ce8414dd811060098967139cf701b40f924d0a81038f6903ae98ff29afafd3fd3f00b8c4518edb
@@ -2,7 +2,7 @@ require 'thrift'
2
2
  require 'logger'
3
3
 
4
4
  module Stark
5
- VERSION = '0.9.3'
5
+ VERSION = '0.10.0'
6
6
 
7
7
  def self.logger
8
8
  @logger ||= ::Logger.new($stdout)
@@ -13,8 +13,7 @@ class Stark::Parser
13
13
  # Prepares for parsing +str+. If you define a custom initialize you must
14
14
  # call this method before #parse
15
15
  def setup_parser(str, debug=false)
16
- @string = str
17
- @pos = 0
16
+ set_string str, 0
18
17
  @memoizations = Hash.new { |h,k| h[k] = {} }
19
18
  @result = nil
20
19
  @failed_rule = nil
@@ -27,7 +26,6 @@ class Stark::Parser
27
26
  attr_reader :failing_rule_offset
28
27
  attr_accessor :result, :pos
29
28
 
30
-
31
29
  def current_column(target=pos)
32
30
  if c = string.rindex("\n", target-1)
33
31
  return target - c - 1
@@ -61,6 +59,13 @@ class Stark::Parser
61
59
  @string[start..@pos-1]
62
60
  end
63
61
 
62
+ # Sets the string and current parsing position for the parser.
63
+ def set_string string, pos
64
+ @string = string
65
+ @string_size = string ? string.size : 0
66
+ @pos = pos
67
+ end
68
+
64
69
  def show_pos
65
70
  width = 10
66
71
  if @pos < width
@@ -167,19 +172,19 @@ class Stark::Parser
167
172
  return nil
168
173
  end
169
174
 
170
- if "".respond_to? :getbyte
175
+ if "".respond_to? :ord
171
176
  def get_byte
172
- if @pos >= @string.size
177
+ if @pos >= @string_size
173
178
  return nil
174
179
  end
175
180
 
176
- s = @string.getbyte @pos
181
+ s = @string[@pos].ord
177
182
  @pos += 1
178
183
  s
179
184
  end
180
185
  else
181
186
  def get_byte
182
- if @pos >= @string.size
187
+ if @pos >= @string_size
183
188
  return nil
184
189
  end
185
190
 
@@ -228,8 +233,7 @@ class Stark::Parser
228
233
  old_pos = @pos
229
234
  old_string = @string
230
235
 
231
- @pos = other.pos
232
- @string = other.string
236
+ set_string other.string, other.pos
233
237
 
234
238
  begin
235
239
  if val = __send__(rule, *args)
@@ -240,8 +244,7 @@ class Stark::Parser
240
244
  end
241
245
  val
242
246
  ensure
243
- @pos = old_pos
244
- @string = old_string
247
+ set_string old_string, old_pos
245
248
  end
246
249
  end
247
250
 
@@ -494,60 +497,63 @@ class Stark::Parser
494
497
  attr_reader :fields
495
498
  end
496
499
  end
497
- def comment(text)
498
- AST::Comment.new(text)
499
- end
500
- def const_dbl(value)
501
- AST::ConstDouble.new(value)
502
- end
503
- def const_id(value)
504
- AST::ConstIdentifier.new(value)
505
- end
506
- def const_int(value)
507
- AST::ConstInt.new(value)
508
- end
509
- def const_list(values)
510
- AST::ConstList.new(values)
511
- end
512
- def const_map(values)
513
- AST::ConstMap.new(values)
514
- end
515
- def const_str(value)
516
- AST::ConstString.new(value)
517
- end
518
- def enum(name, values)
519
- AST::Enum.new(name, values)
520
- end
521
- def exception(name, fields)
522
- AST::Exception.new(name, fields)
523
- end
524
- def field(index, type, name, value, options)
525
- AST::Field.new(index, type, name, value, options)
526
- end
527
- def function(name, return_type, arguments, throws, options)
528
- AST::Function.new(name, return_type, arguments, throws, options)
529
- end
530
- def include(path)
531
- AST::Include.new(path)
532
- end
533
- def list(value)
534
- AST::List.new(value)
535
- end
536
- def map(key, value)
537
- AST::Map.new(key, value)
538
- end
539
- def namespace(lang, namespace)
540
- AST::Namespace.new(lang, namespace)
541
- end
542
- def service(name, functions)
543
- AST::Service.new(name, functions)
544
- end
545
- def set(value)
546
- AST::Set.new(value)
547
- end
548
- def struct(type, name, fields)
549
- AST::Struct.new(type, name, fields)
500
+ module ASTConstruction
501
+ def comment(text)
502
+ AST::Comment.new(text)
503
+ end
504
+ def const_dbl(value)
505
+ AST::ConstDouble.new(value)
506
+ end
507
+ def const_id(value)
508
+ AST::ConstIdentifier.new(value)
509
+ end
510
+ def const_int(value)
511
+ AST::ConstInt.new(value)
512
+ end
513
+ def const_list(values)
514
+ AST::ConstList.new(values)
515
+ end
516
+ def const_map(values)
517
+ AST::ConstMap.new(values)
518
+ end
519
+ def const_str(value)
520
+ AST::ConstString.new(value)
521
+ end
522
+ def enum(name, values)
523
+ AST::Enum.new(name, values)
524
+ end
525
+ def exception(name, fields)
526
+ AST::Exception.new(name, fields)
527
+ end
528
+ def field(index, type, name, value, options)
529
+ AST::Field.new(index, type, name, value, options)
530
+ end
531
+ def function(name, return_type, arguments, throws, options)
532
+ AST::Function.new(name, return_type, arguments, throws, options)
533
+ end
534
+ def include(path)
535
+ AST::Include.new(path)
536
+ end
537
+ def list(value)
538
+ AST::List.new(value)
539
+ end
540
+ def map(key, value)
541
+ AST::Map.new(key, value)
542
+ end
543
+ def namespace(lang, namespace)
544
+ AST::Namespace.new(lang, namespace)
545
+ end
546
+ def service(name, functions)
547
+ AST::Service.new(name, functions)
548
+ end
549
+ def set(value)
550
+ AST::Set.new(value)
551
+ end
552
+ def struct(type, name, fields)
553
+ AST::Struct.new(type, name, fields)
554
+ end
550
555
  end
556
+ include ASTConstruction
551
557
  def setup_foreign_grammar; end
552
558
 
553
559
  # intconstant = /([+-]?[0-9]+)/
@@ -2127,7 +2133,7 @@ class Stark::Parser
2127
2133
  return _tmp
2128
2134
  end
2129
2135
 
2130
- # EnumDef = (CaptureDocText tok_identifier "=" tok_int_constant CommaOrSemicolonOptional | CaptureDocText tok_identifier CommaOrSemicolonOptional)
2136
+ # EnumDef = (CaptureDocText tok_identifier osp "=" osp tok_int_constant CommaOrSemicolonOptional | CaptureDocText tok_identifier CommaOrSemicolonOptional)
2131
2137
  def _EnumDef
2132
2138
 
2133
2139
  _save = self.pos
@@ -2145,11 +2151,21 @@ class Stark::Parser
2145
2151
  self.pos = _save1
2146
2152
  break
2147
2153
  end
2154
+ _tmp = apply(:_osp)
2155
+ unless _tmp
2156
+ self.pos = _save1
2157
+ break
2158
+ end
2148
2159
  _tmp = match_string("=")
2149
2160
  unless _tmp
2150
2161
  self.pos = _save1
2151
2162
  break
2152
2163
  end
2164
+ _tmp = apply(:_osp)
2165
+ unless _tmp
2166
+ self.pos = _save1
2167
+ break
2168
+ end
2153
2169
  _tmp = apply(:_tok_int_constant)
2154
2170
  unless _tmp
2155
2171
  self.pos = _save1
@@ -2287,7 +2303,7 @@ class Stark::Parser
2287
2303
  return _tmp
2288
2304
  end
2289
2305
 
2290
- # Const = "const" - FieldType tok_identifier "=" ConstValue CommaOrSemicolonOptional
2306
+ # Const = "const" - FieldType tok_identifier osp "=" osp ConstValue CommaOrSemicolonOptional
2291
2307
  def _Const
2292
2308
 
2293
2309
  _save = self.pos
@@ -2312,11 +2328,21 @@ class Stark::Parser
2312
2328
  self.pos = _save
2313
2329
  break
2314
2330
  end
2331
+ _tmp = apply(:_osp)
2332
+ unless _tmp
2333
+ self.pos = _save
2334
+ break
2335
+ end
2315
2336
  _tmp = match_string("=")
2316
2337
  unless _tmp
2317
2338
  self.pos = _save
2318
2339
  break
2319
2340
  end
2341
+ _tmp = apply(:_osp)
2342
+ unless _tmp
2343
+ self.pos = _save
2344
+ break
2345
+ end
2320
2346
  _tmp = apply(:_ConstValue)
2321
2347
  unless _tmp
2322
2348
  self.pos = _save
@@ -3097,7 +3123,7 @@ class Stark::Parser
3097
3123
  return _tmp
3098
3124
  end
3099
3125
 
3100
- # Function = CaptureDocText OneWay?:o FunctionType:rt - tok_identifier:name osp "(" FieldList?:args ")" Throws?:t CommaOrSemicolonOptional {function(name, rt, args, t, o)}
3126
+ # Function = CaptureDocText OneWay?:o FunctionType:rt - tok_identifier:name osp "(" obsp FieldList?:args ")" Throws?:t CommaOrSemicolonOptional {function(name, rt, args, t, o)}
3101
3127
  def _Function
3102
3128
 
3103
3129
  _save = self.pos
@@ -3146,6 +3172,11 @@ class Stark::Parser
3146
3172
  self.pos = _save
3147
3173
  break
3148
3174
  end
3175
+ _tmp = apply(:_obsp)
3176
+ unless _tmp
3177
+ self.pos = _save
3178
+ break
3179
+ end
3149
3180
  _save2 = self.pos
3150
3181
  _tmp = apply(:_FieldList)
3151
3182
  @result = nil unless _tmp
@@ -3230,7 +3261,7 @@ class Stark::Parser
3230
3261
  return _tmp
3231
3262
  end
3232
3263
 
3233
- # Throws = osp "throws" osp "(" FieldList ")"
3264
+ # Throws = osp "throws" osp "(" obsp FieldList ")"
3234
3265
  def _Throws
3235
3266
 
3236
3267
  _save = self.pos
@@ -3255,6 +3286,11 @@ class Stark::Parser
3255
3286
  self.pos = _save
3256
3287
  break
3257
3288
  end
3289
+ _tmp = apply(:_obsp)
3290
+ unless _tmp
3291
+ self.pos = _save
3292
+ break
3293
+ end
3258
3294
  _tmp = apply(:_FieldList)
3259
3295
  unless _tmp
3260
3296
  self.pos = _save
@@ -4060,11 +4096,11 @@ class Stark::Parser
4060
4096
  Rules[:_CommaOrSemicolonOptional] = rule_info("CommaOrSemicolonOptional", "(\",\" | \";\")? obsp")
4061
4097
  Rules[:_Enum] = rule_info("Enum", "\"enum\" - tok_identifier:name osp \"{\" obsp EnumDefList:vals obsp \"}\" {enum(name, vals)}")
4062
4098
  Rules[:_EnumDefList] = rule_info("EnumDefList", "(EnumDefList:l EnumDef:e { l + [e] } | EnumDef:e { [e] })")
4063
- Rules[:_EnumDef] = rule_info("EnumDef", "(CaptureDocText tok_identifier \"=\" tok_int_constant CommaOrSemicolonOptional | CaptureDocText tok_identifier CommaOrSemicolonOptional)")
4099
+ Rules[:_EnumDef] = rule_info("EnumDef", "(CaptureDocText tok_identifier osp \"=\" osp tok_int_constant CommaOrSemicolonOptional | CaptureDocText tok_identifier CommaOrSemicolonOptional)")
4064
4100
  Rules[:_Senum] = rule_info("Senum", "\"senum\" - tok_identifier \"{\" SenumDefList \"}\"")
4065
4101
  Rules[:_SenumDefList] = rule_info("SenumDefList", "(SenumDefList SenumDef | nothing)")
4066
4102
  Rules[:_SenumDef] = rule_info("SenumDef", "tok_literal CommaOrSemicolonOptional")
4067
- Rules[:_Const] = rule_info("Const", "\"const\" - FieldType tok_identifier \"=\" ConstValue CommaOrSemicolonOptional")
4103
+ Rules[:_Const] = rule_info("Const", "\"const\" - FieldType tok_identifier osp \"=\" osp ConstValue CommaOrSemicolonOptional")
4068
4104
  Rules[:_ConstValue] = rule_info("ConstValue", "(tok_int_constant:i {const_int(i)} | tok_literal:s {const_str(s)} | tok_identifier:i {const_id(i)} | ConstList | ConstMap | tok_dub_constant:d {const_dbl(d)})")
4069
4105
  Rules[:_ConstList] = rule_info("ConstList", "\"[\" osp ConstListContents*:l osp \"]\" {const_list(l)}")
4070
4106
  Rules[:_ConstListContents] = rule_info("ConstListContents", "ConstValue:i CommaOrSemicolonOptional osp {i}")
@@ -4080,9 +4116,9 @@ class Stark::Parser
4080
4116
  Rules[:_Service] = rule_info("Service", "\"service\" - tok_identifier:name - Extends? osp \"{\" obsp FunctionList?:funcs obsp \"}\" {service(name, funcs)}")
4081
4117
  Rules[:_Extends] = rule_info("Extends", "\"extends\" - tok_identifier")
4082
4118
  Rules[:_FunctionList] = rule_info("FunctionList", "(FunctionList:l Function:f { l + [f] } | Function:f { [f] })")
4083
- Rules[:_Function] = rule_info("Function", "CaptureDocText OneWay?:o FunctionType:rt - tok_identifier:name osp \"(\" FieldList?:args \")\" Throws?:t CommaOrSemicolonOptional {function(name, rt, args, t, o)}")
4119
+ Rules[:_Function] = rule_info("Function", "CaptureDocText OneWay?:o FunctionType:rt - tok_identifier:name osp \"(\" obsp FieldList?:args \")\" Throws?:t CommaOrSemicolonOptional {function(name, rt, args, t, o)}")
4084
4120
  Rules[:_OneWay] = rule_info("OneWay", "(\"oneway\" | \"async\") - { :oneway }")
4085
- Rules[:_Throws] = rule_info("Throws", "osp \"throws\" osp \"(\" FieldList \")\"")
4121
+ Rules[:_Throws] = rule_info("Throws", "osp \"throws\" osp \"(\" obsp FieldList \")\"")
4086
4122
  Rules[:_FieldList] = rule_info("FieldList", "(FieldList:l Field:f { l + [f] } | Field:f { [f] })")
4087
4123
  Rules[:_Field] = rule_info("Field", "CaptureDocText FieldIdentifier?:i osp FieldRequiredness?:req osp FieldType:t osp tok_identifier:n osp FieldValue?:val CommaOrSemicolonOptional {field(i,t,n,val,req)}")
4088
4124
  Rules[:_FieldIdentifier] = rule_info("FieldIdentifier", "tok_int_constant:n \":\" {n}")
@@ -62,6 +62,29 @@ module Stark
62
62
  end
63
63
  end
64
64
 
65
+ def const_to_ruby(val)
66
+ case val
67
+ when Stark::Parser::AST::ConstString
68
+ return %Q!"#{val.value}"!
69
+ when Stark::Parser::AST::ConstInt
70
+ return val.value
71
+ when Stark::Parser::AST::ConstDouble
72
+ return val.value
73
+ when Stark::Parser::AST::ConstIdentifier
74
+ return val.value.to_sym
75
+ when Stark::Parser::AST::ConstList
76
+ parts = val.values.map { |x| const_to_ruby(x) }
77
+ return "[#{parts.join(', ')}]"
78
+ when Stark::Parser::AST::ConstMap
79
+ parts = val.values.map { |(k,v)|
80
+ const_to_ruby(k) + " => " + const_to_ruby(v)
81
+ }
82
+ return "{#{parts.join(', ')}}"
83
+ else
84
+ raise "Unsupported default type: #{val.class}"
85
+ end
86
+ end
87
+
65
88
  def write_field_declarations(fields)
66
89
  max_field_len = fields.inject(0) {|max,f| f.name.length > max ? f.name.length : max }
67
90
  max_index_len = fields.inject(0) {|max,f| f.index.to_s.length > max ? f.index.to_s.length : max }
@@ -73,7 +96,14 @@ module Stark
73
96
  current_index = f.index
74
97
  end
75
98
  current_index += 1
76
- o("attr_accessor :%-*s # %*s: %s" % [max_field_len, f.name, max_index_len, f.index, object_type(f.type)])
99
+
100
+ if f.value
101
+ o("attr_writer :%-*s # %*s: %s" % [max_field_len, f.name, max_index_len, f.index, object_type(f.type)])
102
+
103
+ o("def %s; @%s || %s; end" % [f.name, f.name, const_to_ruby(f.value)])
104
+ else
105
+ o("attr_accessor :%-*s # %*s: %s" % [max_field_len, f.name, max_index_len, f.index, object_type(f.type)])
106
+ end
77
107
  end
78
108
  end
79
109
 
@@ -217,7 +217,7 @@ Enum = "enum" - tok_identifier:name osp "{" obsp EnumDefList:vals obsp "}" ~enum
217
217
  EnumDefList = EnumDefList:l EnumDef:e { l + [e] }
218
218
  | EnumDef:e { [e] }
219
219
 
220
- EnumDef = CaptureDocText tok_identifier "=" tok_int_constant CommaOrSemicolonOptional
220
+ EnumDef = CaptureDocText tok_identifier osp "=" osp tok_int_constant CommaOrSemicolonOptional
221
221
  | CaptureDocText tok_identifier CommaOrSemicolonOptional
222
222
 
223
223
  Senum = "senum" - tok_identifier "{" SenumDefList "}"
@@ -227,7 +227,7 @@ SenumDefList = SenumDefList SenumDef
227
227
 
228
228
  SenumDef = tok_literal CommaOrSemicolonOptional
229
229
 
230
- Const = "const" - FieldType tok_identifier "=" ConstValue CommaOrSemicolonOptional
230
+ Const = "const" - FieldType tok_identifier osp "=" osp ConstValue CommaOrSemicolonOptional
231
231
 
232
232
  ConstValue = tok_int_constant:i ~const_int(i)
233
233
  | tok_literal:s ~const_str(s)
@@ -274,12 +274,12 @@ FunctionList = FunctionList:l Function:f { l + [f] }
274
274
  | Function:f { [f] }
275
275
 
276
276
  Function = CaptureDocText OneWay?:o FunctionType:rt - tok_identifier:name
277
- osp "(" FieldList?:args ")" Throws?:t CommaOrSemicolonOptional
277
+ osp "(" obsp FieldList?:args ")" Throws?:t CommaOrSemicolonOptional
278
278
  ~function(name, rt, args, t, o)
279
279
 
280
280
  OneWay = ("oneway" | "async") - { :oneway }
281
281
 
282
- Throws = osp "throws" osp "(" FieldList ")"
282
+ Throws = osp "throws" osp "(" obsp FieldList ")"
283
283
 
284
284
  FieldList = FieldList:l Field:f { l + [f] }
285
285
  | Field:f { [f] }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '3.13'
53
+ version: '3.15'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '3.13'
60
+ version: '3.15'
61
61
  description: Optimized thrift bindings for ruby.
62
62
  email:
63
63
  - evan@phx.io
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.5.1
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Optimized thrift bindings for ruby.