swift-tools 3.1.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/objc_2_swift.rb +51 -20
- data/lib/swift_tools.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a996ed7884cc6e36f6488cdc8c872f6f8935add4
|
4
|
+
data.tar.gz: 812deb2223cf24ed41104d3a2df3b40f0b36c680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6821410d2ff24e058c504592c06fccef962796796f2021844cd32b61284a56bbc9909bb74527ec0faffd1bcf6403d3d876c0ae6e73f65140ff4e54e7b60babb6
|
7
|
+
data.tar.gz: f61e270b413a36be7bc9accae6c6347f00a83654328a114341ea904151626320ad516ac55ad3ea7543d8273792a6ab1a210efa3f1d00200fd652112eafd1f0ee
|
data/lib/objc_2_swift.rb
CHANGED
@@ -62,6 +62,7 @@ module SwiftTools
|
|
62
62
|
:scope => v1[:scope] || v2[:scope],
|
63
63
|
:return_type => v1[:return_type],
|
64
64
|
:visibility => v1[:visibility],
|
65
|
+
:args => v2[:args],
|
65
66
|
:body => v2[:body]
|
66
67
|
}
|
67
68
|
} if have_interface
|
@@ -112,13 +113,13 @@ module SwiftTools
|
|
112
113
|
}
|
113
114
|
interface_data[:properties].merge!(new_properties)
|
114
115
|
|
115
|
-
# line2 = INDENT + "public var #{prop_data[:getter]}: #{prop_data[:type]} { return #{prop_name} }\n"
|
116
|
-
# if prop_data[:getter]
|
117
|
-
# line1 = INDENT + "private "
|
118
|
-
|
119
116
|
# Write properties
|
120
117
|
interface_data[:properties].each {|prop_name, prop_data|
|
121
118
|
line = INDENT
|
119
|
+
if prop_data[:ib_outlet]
|
120
|
+
line += "@IBOutlet "
|
121
|
+
end
|
122
|
+
|
122
123
|
if prop_data[:readonly]
|
123
124
|
line += "private(set) "
|
124
125
|
elsif prop_data[:visibility] == :private
|
@@ -145,6 +146,10 @@ module SwiftTools
|
|
145
146
|
line += ": #{prop_data[:type]}"
|
146
147
|
end
|
147
148
|
|
149
|
+
unless prop_data[:notnull]
|
150
|
+
line += '!'
|
151
|
+
end
|
152
|
+
|
148
153
|
if prop_data[:initializer]
|
149
154
|
line += " = #{prop_data[:initializer]}"
|
150
155
|
end
|
@@ -188,7 +193,15 @@ module SwiftTools
|
|
188
193
|
line += 'private '
|
189
194
|
end
|
190
195
|
|
191
|
-
line += "func #{method_name}(
|
196
|
+
line += "func #{method_name}("
|
197
|
+
args = method_data[:args]
|
198
|
+
args.each_index {|i|
|
199
|
+
if i > 0
|
200
|
+
line += ", "
|
201
|
+
end
|
202
|
+
line += args[i][1] + ": " + args[i][0]
|
203
|
+
}
|
204
|
+
line += ")"
|
192
205
|
if method_data[:return_type] and method_data[:return_type] != 'Void'
|
193
206
|
line += " -> #{method_data[:return_type]}"
|
194
207
|
end
|
@@ -265,10 +278,10 @@ module SwiftTools
|
|
265
278
|
|
266
279
|
def capture_interfaces(content, in_hdr)
|
267
280
|
interfaces = {}
|
268
|
-
content.scan(/^\s*@interface
|
281
|
+
content.scan(/^\s*@interface *([a-zA-Z0-9_]+)(?: *: *([a-zA-Z0-9_]+) *)?(?: *\(([a-zA-Z0-9_, ]*)\))?(?: *<(.+)>)?((?:.|\n)*?)@end *\n$/m).each {|m|
|
269
282
|
body = m[4]
|
270
|
-
properties =
|
271
|
-
methods =
|
283
|
+
properties = capture_properties(body, in_hdr)
|
284
|
+
methods = capture_methods(body, in_hdr)
|
272
285
|
|
273
286
|
interfaces[m[0]] = {
|
274
287
|
:base => m[1],
|
@@ -282,12 +295,12 @@ module SwiftTools
|
|
282
295
|
interfaces
|
283
296
|
end
|
284
297
|
|
285
|
-
def
|
298
|
+
def capture_properties(content, in_hdr)
|
286
299
|
properties = {}
|
287
|
-
content.scan
|
288
|
-
name =
|
289
|
-
type = map_type(remove_ptr(
|
290
|
-
options = Hash[
|
300
|
+
content.to_enum(:scan, /^ *@property *\(([a-zA-Z0-9_=, ]*)\) *(IBOutlet)? *([a-zA-Z0-9_\*]+) *([a-zA-Z0-9_\*]+) */m).map { Regexp.last_match }.each {|m|
|
301
|
+
name = m[4]
|
302
|
+
type = map_type(remove_ptr(m[3]))
|
303
|
+
options = Hash[m[1].split(',').map(&:strip).collect {|s|
|
291
304
|
a = s.split('=')
|
292
305
|
if a.length > 1
|
293
306
|
[a[0].to_sym, a[1]]
|
@@ -295,6 +308,9 @@ module SwiftTools
|
|
295
308
|
[a[0].to_sym, true]
|
296
309
|
end
|
297
310
|
}]
|
311
|
+
if m[2]
|
312
|
+
options[:ib_outlet] = true
|
313
|
+
end
|
298
314
|
properties[remove_ptr(name)] = {
|
299
315
|
:type => type,
|
300
316
|
:visibility => in_hdr ? :public : :private,
|
@@ -304,9 +320,9 @@ module SwiftTools
|
|
304
320
|
properties
|
305
321
|
end
|
306
322
|
|
307
|
-
def
|
323
|
+
def capture_methods(content, in_hdr)
|
308
324
|
methods = {}
|
309
|
-
content.to_enum(:scan, /^ *(\+|-)? *\(([a-zA-Z0-9_]+)\) *([a-zA-Z0-9_]+)(?:[
|
325
|
+
content.to_enum(:scan, /^ *(\+|-)? *\(([a-zA-Z0-9_]+)\) *([a-zA-Z0-9_]+)(?: *: *)?([^}]*?){/m).map { Regexp.last_match }.each {|m|
|
310
326
|
if in_hdr
|
311
327
|
body = ''
|
312
328
|
else
|
@@ -314,9 +330,11 @@ module SwiftTools
|
|
314
330
|
body_end_offset = find_close_char_offset(content, body_start_offset, '{', '}') - 1
|
315
331
|
body = indent_lines(content[body_start_offset..body_end_offset])
|
316
332
|
end
|
333
|
+
|
317
334
|
methods[m[3]] = {
|
318
335
|
:scope => (m[1] == '+' ? :static : :instance),
|
319
336
|
:return_type => map_type(remove_ptr(m[2])),
|
337
|
+
:args => capture_method_args(m[4]),
|
320
338
|
:visibility => in_hdr ? :public : :private,
|
321
339
|
:body => body
|
322
340
|
}
|
@@ -328,7 +346,7 @@ module SwiftTools
|
|
328
346
|
implementations = {}
|
329
347
|
content.scan(/^\s*@implementation *([a-zA-Z0-9_]+)((?:.|\n)*?)@end *\n$/m).each {|m|
|
330
348
|
body = m[1]
|
331
|
-
methods =
|
349
|
+
methods = capture_methods(body, in_hdr = false)
|
332
350
|
|
333
351
|
implementations[m[0]] = {
|
334
352
|
:methods => methods,
|
@@ -338,6 +356,19 @@ module SwiftTools
|
|
338
356
|
implementations
|
339
357
|
end
|
340
358
|
|
359
|
+
def capture_method_args(content)
|
360
|
+
args = []
|
361
|
+
raw_args = content.gsub(/ *\*/, '*')
|
362
|
+
raw_args = raw_args.split(' ') # The only space left should be between the args
|
363
|
+
raw_args.each {|raw_arg|
|
364
|
+
m = raw_arg.match(/\((.*)\)(.*)/)
|
365
|
+
unless m.nil?
|
366
|
+
args.push([map_type(remove_ptr(m[1])), m[2]])
|
367
|
+
end
|
368
|
+
}
|
369
|
+
args
|
370
|
+
end
|
371
|
+
|
341
372
|
def convert_to_dot_syntax(content)
|
342
373
|
# Repeatedly find a [] syntax method call that does not have a nested [] call
|
343
374
|
# and convert it until done.
|
@@ -399,7 +430,7 @@ module SwiftTools
|
|
399
430
|
def convert_var_decls(content)
|
400
431
|
# Note, this must be done _before_ removing EOL semicolons
|
401
432
|
content.gsub!(/^( *)([a-zA-Z0-9_\*]+) +([a-zA-Z0-9_\*]+)(?: *= *(.*?))? *;/m) {|m|
|
402
|
-
decl = "#{$1}var #{$3}: #{map_type(remove_ptr($2))}"
|
433
|
+
decl = "#{$1}var #{remove_ptr($3)}: #{map_type(remove_ptr($2))}"
|
403
434
|
if $4
|
404
435
|
decl += " = #{$4}"
|
405
436
|
end
|
@@ -508,7 +539,7 @@ module SwiftTools
|
|
508
539
|
end
|
509
540
|
|
510
541
|
def remove_ptr(content)
|
511
|
-
content.gsub('*', '')
|
542
|
+
content.gsub('*', '').strip
|
512
543
|
end
|
513
544
|
|
514
545
|
def map_type(content)
|
@@ -525,8 +556,8 @@ module SwiftTools
|
|
525
556
|
'Void'
|
526
557
|
when 'NSString'
|
527
558
|
'String'
|
528
|
-
when
|
529
|
-
|
559
|
+
when 'CGRect'
|
560
|
+
'CGRect'
|
530
561
|
else
|
531
562
|
content
|
532
563
|
end
|
data/lib/swift_tools.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Lyon-smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: methadone
|