codeminer 0.1.0 → 0.1.1
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 +4 -4
- data/codeminer.gemspec +2 -1
- data/lib/codeminer/sexp_processor.rb +147 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57fadc4a49e37d6cd394a9682d52e457c84be349
|
4
|
+
data.tar.gz: 9d160a9c4b12d76879acb483221509315a283d66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb6b6aa8e2c0861107fb72bd3e8ac6129588443af39336c8c6845876f3139dfbeb588dedec480941a21419cedd302656f72a1654f7f4f526ec7b36063833fef
|
7
|
+
data.tar.gz: 997d962dfb00175d18698d95a419ec99d65fd7d7ec9ed4d71a3576bb3d9b41e6c0afd8742edea69242ce402938b93754a4cf4e230cfa52c3925cf566c5d4e5ca
|
data/codeminer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'codeminer'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.date = '2014-06-30'
|
5
5
|
|
6
6
|
s.summary = 'Mines Ruby code'
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
lib/codeminer.rb
|
19
19
|
lib/codeminer/parser.rb
|
20
20
|
lib/codeminer/expression_processor.rb
|
21
|
+
lib/codeminer/sexp_processor.rb
|
21
22
|
lib/codeminer/source_extract.rb
|
22
23
|
lib/codeminer/substitution.rb
|
23
24
|
lib/codeminer/token.rb
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module CodeMiner
|
2
|
+
|
3
|
+
class Sexp
|
4
|
+
|
5
|
+
include SourceExtract::Usage
|
6
|
+
|
7
|
+
attr_reader :exp, :file
|
8
|
+
|
9
|
+
def initialize(expressions, exp)
|
10
|
+
@expressions = expressions
|
11
|
+
@exp = exp
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO: kill this and delegate properly
|
15
|
+
def method_missing(meth, *args)
|
16
|
+
if @exp.respond_to?(meth)
|
17
|
+
@exp.send(meth, *args)
|
18
|
+
elsif @expressions.respond_to?(meth)
|
19
|
+
@expressions.send(meth, *args)
|
20
|
+
elsif @exp.exp.respond_to?(meth)
|
21
|
+
@exp.exp.send(meth, *args)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def src_extract
|
28
|
+
@exp.src_extract
|
29
|
+
end
|
30
|
+
|
31
|
+
def each
|
32
|
+
@exp.each
|
33
|
+
end
|
34
|
+
|
35
|
+
def length
|
36
|
+
@expressions.length
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_a
|
40
|
+
@expressions
|
41
|
+
end
|
42
|
+
|
43
|
+
def inspect
|
44
|
+
"s(#{to_a.map(&:inspect).join(', ')})"
|
45
|
+
end
|
46
|
+
|
47
|
+
alias to_s inspect
|
48
|
+
|
49
|
+
def ==(other)
|
50
|
+
@expressions == other
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class SexpFormatter
|
56
|
+
|
57
|
+
attr_reader :exp
|
58
|
+
|
59
|
+
def initialize(exp, parser)
|
60
|
+
@exp = exp
|
61
|
+
@parser = parser
|
62
|
+
end
|
63
|
+
|
64
|
+
def type
|
65
|
+
exp.type
|
66
|
+
end
|
67
|
+
|
68
|
+
def value
|
69
|
+
exp.value
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
exp.each
|
74
|
+
end
|
75
|
+
|
76
|
+
def src_extract
|
77
|
+
exp.src_extract
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_sexp
|
81
|
+
if exp.respond_to?(:each)
|
82
|
+
format(type, *value, each)
|
83
|
+
else
|
84
|
+
exp
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def format(*nodes, children)
|
89
|
+
CodeMiner::Sexp.new([*nodes, *children.map{|e| @parser.to_sexp(e)}], exp)
|
90
|
+
end
|
91
|
+
|
92
|
+
def exp
|
93
|
+
@exp.kind_of?(Sexp) ? @exp.exp : @exp
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
module SexpProcessor
|
99
|
+
|
100
|
+
BLACKLIST = %w(string_embexpr void_stmt)
|
101
|
+
TOKENS = %w(int)
|
102
|
+
|
103
|
+
Ripper::PARSER_EVENT_TABLE.each do |event, arity|
|
104
|
+
next if /_new\z/ =~ event.to_s and arity == 0
|
105
|
+
next if /_add\z/ =~ event.to_s
|
106
|
+
next if /_content\z/ =~ event.to_s
|
107
|
+
next if /_from_[a-z]+\z/ =~ event.to_s
|
108
|
+
next if BLACKLIST.include?(event.to_s)
|
109
|
+
|
110
|
+
if /_add_[a-z]+\z/ =~ event.to_s
|
111
|
+
define_method :"on_#{event}" do |*args|
|
112
|
+
to_sexp_replace(super(*args))
|
113
|
+
end
|
114
|
+
else
|
115
|
+
define_method :"on_#{event}" do |*args|
|
116
|
+
to_sexp(super(*args))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
TOKENS.each do |token|
|
122
|
+
define_method :"on_#{token}" do |exp|
|
123
|
+
to_sexp(super(exp))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_sexp_replace(exp)
|
128
|
+
if exp.respond_to?(:type) || exp.kind_of?(Sexp)
|
129
|
+
formatter = formatters.fetch(exp.type, SexpFormatter)
|
130
|
+
formatter.new(exp, self).to_sexp
|
131
|
+
else
|
132
|
+
exp
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_sexp(exp)
|
137
|
+
if exp.respond_to?(:type)
|
138
|
+
formatter = formatters.fetch(exp.type, SexpFormatter)
|
139
|
+
formatter.new(exp, self).to_sexp
|
140
|
+
else
|
141
|
+
exp
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeminer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Richardson
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/codeminer/processors/symbol_processor.rb
|
144
144
|
- lib/codeminer/processors/token_processor.rb
|
145
145
|
- lib/codeminer/processors/variable_processor.rb
|
146
|
+
- lib/codeminer/sexp_processor.rb
|
146
147
|
- lib/codeminer/source_extract.rb
|
147
148
|
- lib/codeminer/substitution.rb
|
148
149
|
- lib/codeminer/token.rb
|