code_breaker 0.2.0 → 0.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: 4468ff2521266bb40fef341f1bccccae616ec424
4
- data.tar.gz: 42237cf2a40ab1a6070deb8518d251cf843c16e7
3
+ metadata.gz: bc0d158891183a1deb5f3c0ef4de80a435c85707
4
+ data.tar.gz: 32999f6fe0c83087e10e0c37211731ff3e3ca224
5
5
  SHA512:
6
- metadata.gz: 8eb015b2710c9ec7ac78aa24a6220231131486a9010c4526731e4ce4077249cdda0b347369f27dca219439f5eb0ff7184fd4894df3b07b817017c41bc22868b4
7
- data.tar.gz: c7bb344918f3b9c04c46ca7b0a86d4a04526b98e251c4087161dc1d71af3e932445f89931bcdf514f287f4851d16ec094db41e330d293a33ebd778040e5ab6c5
6
+ metadata.gz: 1bdc1571ee0755364674d48d03c23e52871072235c395c0d3a3663e2653d908ddf4f8919e4c47e7896161e4b70d829b0d638e2a8a931f8b349c68b77c1d44327
7
+ data.tar.gz: fafd6164a43dda14ad13128c09a57b5a85befddf718cef8bc08e9259ddee4de5ca63bf099a93de4fdd7a0dc498996cc74ec71666da5551824ee11aa98e91cb05
data/code_breaker.gemspec CHANGED
@@ -27,8 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'parser', '~> 2.2'
31
- spec.add_dependency 'activesupport', '~> 4'
30
+ spec.add_dependency 'parser', '~> 2.3'
32
31
 
33
32
  spec.add_development_dependency 'bundler', '~> 1.10'
34
33
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,63 +1,58 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Assignments
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- # local variable assignment
11
- alias_method :parse_lvasgn_node, :parse_as_hash
6
+ # local variable assignment
7
+ alias_method :parse_lvasgn_node, :parse_as_hash
12
8
 
13
- # instance variable assignment
14
- alias_method :parse_ivasgn_node, :parse_as_hash
9
+ # instance variable assignment
10
+ alias_method :parse_ivasgn_node, :parse_as_hash
15
11
 
16
- # class variable assignment
17
- alias_method :parse_cvasgn_node, :parse_as_hash
12
+ # class variable assignment
13
+ alias_method :parse_cvasgn_node, :parse_as_hash
18
14
 
19
- # global variable assignment
20
- alias_method :parse_gvasgn_node, :parse_as_hash
15
+ # global variable assignment
16
+ alias_method :parse_gvasgn_node, :parse_as_hash
21
17
 
22
- # operation assignment
23
- alias_method :parse_op_asgn_node, :parse_as_hash
18
+ # operation assignment
19
+ alias_method :parse_op_asgn_node, :parse_as_hash
24
20
 
25
- # or assignment
26
- alias_method :parse_or_asgn_node, :parse_as_hash
21
+ # or assignment
22
+ alias_method :parse_or_asgn_node, :parse_as_hash
27
23
 
28
- # and assignment
29
- alias_method :parse_and_asgn_node, :parse_as_hash
24
+ # and assignment
25
+ alias_method :parse_and_asgn_node, :parse_as_hash
30
26
 
31
- # multiple assignment
32
- def parse_masgn_node(node)
33
- lhs, rhs = parse_children(node)
34
- values = multiple_assignment_values(lhs, rhs)
27
+ # multiple assignment
28
+ def parse_masgn_node(node)
29
+ lhs, rhs = parse_children(node)
30
+ values = multiple_assignment_values(lhs, rhs)
35
31
 
36
- { node.type => { lhs => values } }
37
- end
32
+ { node.type => { lhs => values } }
33
+ end
38
34
 
39
- # multiple left hand side
40
- def parse_mlhs_node(node)
41
- parse_children(node).map(&:values).flatten
42
- end
35
+ # multiple left hand side
36
+ def parse_mlhs_node(node)
37
+ parse_children(node).map(&:values).flatten
38
+ end
43
39
 
44
- # constant assignment
45
- def parse_casgn_node(node)
46
- name = node.children[1]
47
- children = node.children[2]
48
- value = children.nil? ? name : [name, parse(node.children[2])]
40
+ # constant assignment
41
+ def parse_casgn_node(node)
42
+ name = node.children[1]
43
+ children = node.children[2]
44
+ value = children.nil? ? name : [name, parse(node.children[2])]
49
45
 
50
- { node.type => value }
51
- end
46
+ { node.type => value }
47
+ end
52
48
 
53
- private
49
+ private
54
50
 
55
- def multiple_assignment_values(lhs, rhs)
56
- if rhs.is_a?(Hash) && rhs.key?(:array)
57
- rhs[:array]
58
- else
59
- [rhs] + (1...lhs.count).map { NilClass }
60
- end
51
+ def multiple_assignment_values(lhs, rhs)
52
+ if rhs.is_a?(Hash) && rhs.key?(:array)
53
+ rhs[:array]
54
+ else
55
+ [rhs] + (1...lhs.count).map { NilClass }
61
56
  end
62
57
  end
63
58
  end
@@ -1,69 +1,64 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module DataTypes
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- def parse_nil_node(node)
11
- NilClass
12
- end
6
+ def parse_nil_node(node)
7
+ NilClass
8
+ end
13
9
 
14
- def parse_true_node(node)
15
- TrueClass
16
- end
10
+ def parse_true_node(node)
11
+ TrueClass
12
+ end
17
13
 
18
- def parse_false_node(node)
19
- FalseClass
20
- end
14
+ def parse_false_node(node)
15
+ FalseClass
16
+ end
21
17
 
22
- def parse_str_node(node)
23
- String
24
- end
18
+ def parse_str_node(node)
19
+ String
20
+ end
25
21
 
26
- # interpolated executed string
27
- def parse_xstr_node(node)
28
- { node.type => parse_children(node).first }
29
- end
22
+ # interpolated executed string
23
+ def parse_xstr_node(node)
24
+ { node.type => parse_children(node).first }
25
+ end
30
26
 
31
- # interpolated string
32
- def parse_dstr_node(node)
33
- values = parse_as_hash(node)[node.type].map do |value|
34
- if value.is_a?(Array)
35
- value.flatten(1)
36
- else
37
- value
38
- end
27
+ # interpolated string
28
+ def parse_dstr_node(node)
29
+ values = parse_as_hash(node)[node.type].map do |value|
30
+ if value.is_a?(Array)
31
+ value.flatten(1)
32
+ else
33
+ value
39
34
  end
40
-
41
- { node.type => values }
42
35
  end
43
36
 
44
- def parse_sym_node(node)
45
- Symbol
46
- end
37
+ { node.type => values }
38
+ end
47
39
 
48
- def parse_float_node(node)
49
- Float
50
- end
40
+ def parse_sym_node(node)
41
+ Symbol
42
+ end
51
43
 
52
- def parse_regexp_node(node)
53
- Regexp
54
- end
44
+ def parse_float_node(node)
45
+ Float
46
+ end
55
47
 
56
- def parse_int_node(node)
57
- node.children[0].class
58
- end
48
+ def parse_regexp_node(node)
49
+ Regexp
50
+ end
59
51
 
60
- def parse_pair_node(node)
61
- { parse(node.children[0]) => parse(node.children[1]) }
62
- end
52
+ def parse_int_node(node)
53
+ node.children[0].class
54
+ end
63
55
 
64
- alias_method :parse_hash_node, :parse_as_hash
65
- alias_method :parse_array_node, :parse_as_hash
56
+ def parse_pair_node(node)
57
+ { parse(node.children[0]) => parse(node.children[1]) }
66
58
  end
59
+
60
+ alias_method :parse_hash_node, :parse_as_hash
61
+ alias_method :parse_array_node, :parse_as_hash
67
62
  end
68
63
  end
69
64
  end
@@ -1,99 +1,94 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Keywords
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- alias_method :parse_or_node, :parse_as_hash
11
- alias_method :parse_and_node, :parse_as_hash
12
- alias_method :parse_def_node, :parse_as_hash
13
- alias_method :parse_yield_node, :parse_as_hash
14
- alias_method :parse_rescue_node, :parse_as_hash
15
- alias_method :parse_resbody_node, :parse_as_hash
6
+ alias_method :parse_or_node, :parse_as_hash
7
+ alias_method :parse_and_node, :parse_as_hash
8
+ alias_method :parse_def_node, :parse_as_hash
9
+ alias_method :parse_yield_node, :parse_as_hash
10
+ alias_method :parse_rescue_node, :parse_as_hash
11
+ alias_method :parse_resbody_node, :parse_as_hash
16
12
 
17
- alias_method :parse_break_node, :parse_as_node_type
18
- alias_method :parse_next_node, :parse_as_node_type
19
- alias_method :parse_retry_node, :parse_as_node_type
20
- alias_method :parse_self_node, :parse_as_node_type
13
+ alias_method :parse_break_node, :parse_as_node_type
14
+ alias_method :parse_next_node, :parse_as_node_type
15
+ alias_method :parse_retry_node, :parse_as_node_type
16
+ alias_method :parse_self_node, :parse_as_node_type
21
17
 
22
- def parse_loop_node(node)
23
- condition = node.children[0]
24
- body = node.children[1]
18
+ def parse_loop_node(node)
19
+ condition = node.children[0]
20
+ body = node.children[1]
25
21
 
26
- { node.type => parse(condition), do: parse(body) }
27
- end
22
+ { node.type => parse(condition), do: parse(body) }
23
+ end
28
24
 
29
- alias_method :parse_while_node, :parse_loop_node
30
- alias_method :parse_until_node, :parse_loop_node
25
+ alias_method :parse_while_node, :parse_loop_node
26
+ alias_method :parse_until_node, :parse_loop_node
31
27
 
32
- def parse_for_node(node)
33
- variable = node.children[0]
34
- range = node.children[1]
35
- body = node.children[2]
28
+ def parse_for_node(node)
29
+ variable = node.children[0]
30
+ range = node.children[1]
31
+ body = node.children[2]
36
32
 
37
- { node.type => parse(variable), in: parse(range), do: parse(body) }
38
- end
33
+ { node.type => parse(variable), in: parse(range), do: parse(body) }
34
+ end
39
35
 
40
- def parse_if_node(node)
41
- condition = node.children[0]
42
- if_body = node.children[1]
43
- else_body = node.children[2]
36
+ def parse_if_node(node)
37
+ condition = node.children[0]
38
+ if_body = node.children[1]
39
+ else_body = node.children[2]
44
40
 
45
- clause = { node.type => parse(condition), then: parse(if_body) }
46
- clause[:else] = parse(else_body) if else_body
41
+ clause = { node.type => parse(condition), then: parse(if_body) }
42
+ clause[:else] = parse(else_body) if else_body
47
43
 
48
- clause
49
- end
44
+ clause
45
+ end
50
46
 
51
- def parse_module_node(node)
52
- name = parse(node.children[0])
53
- body = node.children[1].nil? ? nil : parse(node.children[1])
54
- value = body ? [name, body] : [name]
47
+ def parse_module_node(node)
48
+ name = parse(node.children[0])
49
+ body = node.children[1].nil? ? nil : parse(node.children[1])
50
+ value = body ? [name, body] : [name]
55
51
 
56
- { node.type => value }
57
- end
52
+ { node.type => value }
53
+ end
58
54
 
59
- def parse_return_node(node)
60
- children = parse_children(node)
61
- values = children.length == 1 ? children[0] : children
55
+ def parse_return_node(node)
56
+ children = parse_children(node)
57
+ values = children.length == 1 ? children[0] : children
62
58
 
63
- { node.type => values }
64
- end
59
+ { node.type => values }
60
+ end
65
61
 
66
- def parse_kwbegin_node(node)
67
- rescue_given = node.children.first.type == :rescue
62
+ def parse_kwbegin_node(node)
63
+ rescue_given = node.children.first.type == :rescue
68
64
 
69
- if rescue_given
70
- rescue_part = parse(node.children.first)[:rescue]
65
+ if rescue_given
66
+ rescue_part = parse(node.children.first)[:rescue]
71
67
 
72
- {
73
- begin: rescue_part.first,
74
- rescue: rescue_part.last[:resbody].first
75
- }
76
- else
77
- { begin: parse(node.children.last) }
78
- end
68
+ {
69
+ begin: rescue_part.first,
70
+ rescue: rescue_part.last[:resbody].first
71
+ }
72
+ else
73
+ { begin: parse(node.children.last) }
79
74
  end
75
+ end
80
76
 
81
- def parse_case_node(node)
82
- case_part = parse(node.children.first)
83
- when_parts = node.children[1...-1].map { |child| parse(child) }
84
- else_part = parse(node.children.last)
77
+ def parse_case_node(node)
78
+ case_part = parse(node.children.first)
79
+ when_parts = node.children[1...-1].map { |child| parse(child) }
80
+ else_part = parse(node.children.last)
85
81
 
86
- statement = { case: when_parts.unshift(case_part) }
87
- statement[:case] << { else: else_part } if else_part
88
- statement
89
- end
82
+ statement = { case: when_parts.unshift(case_part) }
83
+ statement[:case] << { else: else_part } if else_part
84
+ statement
85
+ end
90
86
 
91
- def parse_when_node(node)
92
- when_part = parse(node.children[0])
93
- then_part = parse(node.children[1])
87
+ def parse_when_node(node)
88
+ when_part = parse(node.children[0])
89
+ then_part = parse(node.children[1])
94
90
 
95
- { when: when_part, then: then_part }
96
- end
91
+ { when: when_part, then: then_part }
97
92
  end
98
93
  end
99
94
  end
@@ -1,40 +1,35 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module LanguageElements
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- alias_method :parse_block_node, :parse_as_hash
11
- alias_method :parse_args_node, :parse_as_hash
12
- alias_method :parse_arg_node, :parse_as_last_child_hash
13
- alias_method :parse_blockarg_node, :parse_as_last_child_hash
14
- alias_method :parse_restarg_node, :parse_as_last_child_hash
6
+ alias_method :parse_block_node, :parse_as_hash
7
+ alias_method :parse_args_node, :parse_as_hash
8
+ alias_method :parse_arg_node, :parse_as_last_child_hash
9
+ alias_method :parse_blockarg_node, :parse_as_last_child_hash
10
+ alias_method :parse_restarg_node, :parse_as_last_child_hash
15
11
 
16
- # optional argument
17
- alias_method :parse_optarg_node, :parse_as_hash
12
+ # optional argument
13
+ alias_method :parse_optarg_node, :parse_as_hash
18
14
 
19
- # keyword argument
20
- alias_method :parse_kwarg_node, :parse_as_last_child_hash
15
+ # keyword argument
16
+ alias_method :parse_kwarg_node, :parse_as_last_child_hash
21
17
 
22
- # optional keyword argument
23
- alias_method :parse_kwoptarg_node, :parse_as_hash
18
+ # optional keyword argument
19
+ alias_method :parse_kwoptarg_node, :parse_as_hash
24
20
 
25
- # keyword rest argument
26
- alias_method :parse_kwrestarg_node, :parse_as_last_child_hash
21
+ # keyword rest argument
22
+ alias_method :parse_kwrestarg_node, :parse_as_last_child_hash
27
23
 
28
- def parse_block_pass_node(node)
29
- { node.type => node.children.first.children.last }
30
- end
24
+ def parse_block_pass_node(node)
25
+ { node.type => node.children.first.children.last }
26
+ end
31
27
 
32
- def parse_splat_node(node)
33
- children = parse_children(node).flatten(1)
34
- values = children.length == 1 ? children[0] : children
28
+ def parse_splat_node(node)
29
+ children = parse_children(node).flatten(1)
30
+ values = children.length == 1 ? children[0] : children
35
31
 
36
- { node.type => values }
37
- end
32
+ { node.type => values }
38
33
  end
39
34
  end
40
35
  end
@@ -1,18 +1,13 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Ranges
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- # inclusive range a..b
11
- alias_method :parse_irange_node, :parse_as_hash
6
+ # inclusive range a..b
7
+ alias_method :parse_irange_node, :parse_as_hash
12
8
 
13
- # exclusive range a...b
14
- alias_method :parse_erange_node, :parse_as_hash
15
- end
9
+ # exclusive range a...b
10
+ alias_method :parse_erange_node, :parse_as_hash
16
11
  end
17
12
  end
18
13
  end
@@ -1,26 +1,21 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module VariableTypes
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- alias_method :parse_const_node, :parse_as_last_child_hash
6
+ alias_method :parse_const_node, :parse_as_last_child_hash
11
7
 
12
- # local variable
13
- alias_method :parse_lvar_node, :parse_as_last_child_hash
8
+ # local variable
9
+ alias_method :parse_lvar_node, :parse_as_last_child_hash
14
10
 
15
- # instance variable
16
- alias_method :parse_ivar_node, :parse_as_last_child_hash
11
+ # instance variable
12
+ alias_method :parse_ivar_node, :parse_as_last_child_hash
17
13
 
18
- # class variable
19
- alias_method :parse_cvar_node, :parse_as_last_child_hash
14
+ # class variable
15
+ alias_method :parse_cvar_node, :parse_as_last_child_hash
20
16
 
21
- # global variable
22
- alias_method :parse_gvar_node, :parse_as_last_child_hash
23
- end
17
+ # global variable
18
+ alias_method :parse_gvar_node, :parse_as_last_child_hash
24
19
  end
25
20
  end
26
21
  end
@@ -1,22 +1,17 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Wrappers
6
- extend ActiveSupport::Concern
7
4
  include Parsable::Node
8
5
 
9
- included do
10
- def parse_send_node(node)
11
- if [:Rational, :Complex].include?(node.children[1])
12
- return node.children[1].to_s.constantize
13
- end
14
-
15
- parse_children(node).flatten(1)
6
+ def parse_send_node(node)
7
+ if [:Rational, :Complex].include?(node.children[1])
8
+ return Kernel.const_get(node.children[1].to_s)
16
9
  end
17
10
 
18
- alias_method :parse_begin_node, :parse_children
11
+ parse_children(node).flatten(1)
19
12
  end
13
+
14
+ alias_method :parse_begin_node, :parse_children
20
15
  end
21
16
  end
22
17
  end
@@ -1,6 +1,5 @@
1
1
  require 'code_breaker/parsable'
2
2
  require 'parser/current'
3
- require 'active_support/inflector'
4
3
 
5
4
  module CodeBreaker
6
5
  class Parser
@@ -1,3 +1,3 @@
1
1
  module CodeBreaker
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Götze
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4'
26
+ version: '2.3'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
118
  version: '0'
133
119
  requirements: []
134
120
  rubyforge_project:
135
- rubygems_version: 2.6.4
121
+ rubygems_version: 2.5.1
136
122
  signing_key:
137
123
  specification_version: 4
138
124
  summary: Breaking a Ruby code snippet into a sequence of classes and their connecting