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 +4 -4
- data/code_breaker.gemspec +1 -2
- data/lib/code_breaker/parsable/assignments.rb +37 -42
- data/lib/code_breaker/parsable/data_types.rb +42 -47
- data/lib/code_breaker/parsable/keywords.rb +65 -70
- data/lib/code_breaker/parsable/language_elements.rb +20 -25
- data/lib/code_breaker/parsable/ranges.rb +4 -9
- data/lib/code_breaker/parsable/variable_types.rb +9 -14
- data/lib/code_breaker/parsable/wrappers.rb +6 -11
- data/lib/code_breaker/parser.rb +0 -1
- data/lib/code_breaker/version.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc0d158891183a1deb5f3c0ef4de80a435c85707
|
4
|
+
data.tar.gz: 32999f6fe0c83087e10e0c37211731ff3e3ca224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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',
|
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
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
9
|
+
# instance variable assignment
|
10
|
+
alias_method :parse_ivasgn_node, :parse_as_hash
|
15
11
|
|
16
|
-
|
17
|
-
|
12
|
+
# class variable assignment
|
13
|
+
alias_method :parse_cvasgn_node, :parse_as_hash
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
# global variable assignment
|
16
|
+
alias_method :parse_gvasgn_node, :parse_as_hash
|
21
17
|
|
22
|
-
|
23
|
-
|
18
|
+
# operation assignment
|
19
|
+
alias_method :parse_op_asgn_node, :parse_as_hash
|
24
20
|
|
25
|
-
|
26
|
-
|
21
|
+
# or assignment
|
22
|
+
alias_method :parse_or_asgn_node, :parse_as_hash
|
27
23
|
|
28
|
-
|
29
|
-
|
24
|
+
# and assignment
|
25
|
+
alias_method :parse_and_asgn_node, :parse_as_hash
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
32
|
+
{ node.type => { lhs => values } }
|
33
|
+
end
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
# multiple left hand side
|
36
|
+
def parse_mlhs_node(node)
|
37
|
+
parse_children(node).map(&:values).flatten
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
46
|
+
{ node.type => value }
|
47
|
+
end
|
52
48
|
|
53
|
-
|
49
|
+
private
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
def parse_nil_node(node)
|
7
|
+
NilClass
|
8
|
+
end
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def parse_true_node(node)
|
11
|
+
TrueClass
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def parse_false_node(node)
|
15
|
+
FalseClass
|
16
|
+
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
def parse_str_node(node)
|
19
|
+
String
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
# interpolated executed string
|
23
|
+
def parse_xstr_node(node)
|
24
|
+
{ node.type => parse_children(node).first }
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
45
|
-
|
46
|
-
end
|
37
|
+
{ node.type => values }
|
38
|
+
end
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
def parse_sym_node(node)
|
41
|
+
Symbol
|
42
|
+
end
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
def parse_float_node(node)
|
45
|
+
Float
|
46
|
+
end
|
55
47
|
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
def parse_regexp_node(node)
|
49
|
+
Regexp
|
50
|
+
end
|
59
51
|
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
def parse_int_node(node)
|
53
|
+
node.children[0].class
|
54
|
+
end
|
63
55
|
|
64
|
-
|
65
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
18
|
+
def parse_loop_node(node)
|
19
|
+
condition = node.children[0]
|
20
|
+
body = node.children[1]
|
25
21
|
|
26
|
-
|
27
|
-
|
22
|
+
{ node.type => parse(condition), do: parse(body) }
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
25
|
+
alias_method :parse_while_node, :parse_loop_node
|
26
|
+
alias_method :parse_until_node, :parse_loop_node
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
def parse_for_node(node)
|
29
|
+
variable = node.children[0]
|
30
|
+
range = node.children[1]
|
31
|
+
body = node.children[2]
|
36
32
|
|
37
|
-
|
38
|
-
|
33
|
+
{ node.type => parse(variable), in: parse(range), do: parse(body) }
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
41
|
+
clause = { node.type => parse(condition), then: parse(if_body) }
|
42
|
+
clause[:else] = parse(else_body) if else_body
|
47
43
|
|
48
|
-
|
49
|
-
|
44
|
+
clause
|
45
|
+
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
52
|
+
{ node.type => value }
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
def parse_return_node(node)
|
56
|
+
children = parse_children(node)
|
57
|
+
values = children.length == 1 ? children[0] : children
|
62
58
|
|
63
|
-
|
64
|
-
|
59
|
+
{ node.type => values }
|
60
|
+
end
|
65
61
|
|
66
|
-
|
67
|
-
|
62
|
+
def parse_kwbegin_node(node)
|
63
|
+
rescue_given = node.children.first.type == :rescue
|
68
64
|
|
69
|
-
|
70
|
-
|
65
|
+
if rescue_given
|
66
|
+
rescue_part = parse(node.children.first)[:rescue]
|
71
67
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
statement = { case: when_parts.unshift(case_part) }
|
83
|
+
statement[:case] << { else: else_part } if else_part
|
84
|
+
statement
|
85
|
+
end
|
90
86
|
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
def parse_when_node(node)
|
88
|
+
when_part = parse(node.children[0])
|
89
|
+
then_part = parse(node.children[1])
|
94
90
|
|
95
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
12
|
+
# optional argument
|
13
|
+
alias_method :parse_optarg_node, :parse_as_hash
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
# keyword argument
|
16
|
+
alias_method :parse_kwarg_node, :parse_as_last_child_hash
|
21
17
|
|
22
|
-
|
23
|
-
|
18
|
+
# optional keyword argument
|
19
|
+
alias_method :parse_kwoptarg_node, :parse_as_hash
|
24
20
|
|
25
|
-
|
26
|
-
|
21
|
+
# keyword rest argument
|
22
|
+
alias_method :parse_kwrestarg_node, :parse_as_last_child_hash
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def parse_block_pass_node(node)
|
25
|
+
{ node.type => node.children.first.children.last }
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def parse_splat_node(node)
|
29
|
+
children = parse_children(node).flatten(1)
|
30
|
+
values = children.length == 1 ? children[0] : children
|
35
31
|
|
36
|
-
|
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
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
13
|
-
|
8
|
+
# local variable
|
9
|
+
alias_method :parse_lvar_node, :parse_as_last_child_hash
|
14
10
|
|
15
|
-
|
16
|
-
|
11
|
+
# instance variable
|
12
|
+
alias_method :parse_ivar_node, :parse_as_last_child_hash
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
# class variable
|
15
|
+
alias_method :parse_cvar_node, :parse_as_last_child_hash
|
20
16
|
|
21
|
-
|
22
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
data/lib/code_breaker/parser.rb
CHANGED
data/lib/code_breaker/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|
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.
|
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
|