sourcify 0.2.0 → 0.2.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.
- data/HISTORY.txt +7 -0
- data/VERSION +1 -1
- data/lib/sourcify/proc.rb +28 -5
- data/lib/sourcify/proc/parser.rb +6 -34
- data/lib/sourcify/proc/scanner.rb +1312 -1242
- data/lib/sourcify/proc/scanner.rl +103 -92
- data/lib/sourcify/proc/scanner/extensions.rb +0 -1
- data/sourcify.gemspec +2 -4
- data/spec/dump_object_space_procs.rb +1 -1
- data/spec/proc/created_on_the_fly_proc_spec.rb +33 -125
- data/spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb +13 -0
- data/spec/proc_scanner/single_quote_str_spec.rb +13 -0
- metadata +4 -6
- data/spec/proc_scanner/to_proc_spec.rb +0 -15
@@ -89,98 +89,9 @@ module Sourcify
|
|
89
89
|
};
|
90
90
|
*|;
|
91
91
|
|
92
|
-
## MACHINE >>
|
93
|
-
|
94
|
-
delimiter = [\~\`\!\@\#\$\%\^\&\*\)\-\_\+\=\}\]\:\;\'\"\>\,\.\?\/\|\\];
|
95
|
-
(^delimiter* . delimiter) -- ('\\' . delimiter) => {
|
96
|
-
unless push_dstring(ts, te)
|
97
|
-
fgoto main;
|
98
|
-
end
|
99
|
-
};
|
100
|
-
*|;
|
101
|
-
|
102
|
-
## MACHINE >> Main
|
103
|
-
main := |*
|
104
|
-
|
105
|
-
## == Start/end of do..end block
|
106
|
-
|
107
|
-
kw_do => {
|
108
|
-
push(:kw_do, ts, te)
|
109
|
-
increment_counter(:do_end)
|
110
|
-
fgoto new_statement;
|
111
|
-
};
|
112
|
-
|
113
|
-
kw_end => {
|
114
|
-
push(:kw_end, ts, te)
|
115
|
-
decrement_counter(:do_end)
|
116
|
-
};
|
117
|
-
|
118
|
-
## == Start/end of {...} block
|
119
|
-
|
120
|
-
lbrace => {
|
121
|
-
push(:lbrace, ts, te)
|
122
|
-
increment_counter(:brace)
|
123
|
-
};
|
124
|
-
|
125
|
-
rbrace => {
|
126
|
-
push(:rbrace, ts, te)
|
127
|
-
decrement_counter(:brace)
|
128
|
-
};
|
129
|
-
|
130
|
-
assoc => {
|
131
|
-
push(:assoc, ts, te)
|
132
|
-
fix_counter_false_start(:brace)
|
133
|
-
};
|
134
|
-
|
135
|
-
label => {
|
136
|
-
push_label(ts, te)
|
137
|
-
fix_counter_false_start(:brace)
|
138
|
-
};
|
139
|
-
|
140
|
-
## == New statement
|
141
|
-
|
142
|
-
newline => {
|
143
|
-
push(:newline, ts, te)
|
144
|
-
increment_lineno
|
145
|
-
fgoto new_statement;
|
146
|
-
};
|
147
|
-
|
148
|
-
smcolon | lparen | assgn | kw_then | comma => {
|
149
|
-
push(:newline_alias, ts, te)
|
150
|
-
fgoto new_statement;
|
151
|
-
};
|
152
|
-
|
153
|
-
## == Comment
|
154
|
-
|
155
|
-
'#' => {
|
156
|
-
fgoto per_line_comment;
|
157
|
-
};
|
158
|
-
|
159
|
-
newline . '=begin' . ospaces . (ospaces . ^newline+)* . newline => {
|
160
|
-
push_comment(ts, te)
|
161
|
-
increment_lineno
|
162
|
-
fgoto block_comment;
|
163
|
-
};
|
164
|
-
|
165
|
-
## == Misc
|
166
|
-
|
167
|
-
var => { push(:var, ts, te) };
|
168
|
-
const => { push(:const, ts, te) };
|
169
|
-
symbol => { push(:symbol, ts, te) };
|
170
|
-
mspaces => { push(:space, ts, te) };
|
171
|
-
any => { push(:any, ts, te) };
|
172
|
-
'&:' . meth => { push(:to_proc, ts, te) };
|
173
|
-
|
174
|
-
## == Heredoc
|
175
|
-
|
176
|
-
('<<' | '<<-') . ["']? . (const | var) . ["']? . newline => {
|
177
|
-
push_heredoc(ts, te)
|
178
|
-
increment_lineno
|
179
|
-
fgoto heredoc;
|
180
|
-
};
|
181
|
-
|
92
|
+
## MACHINE >> String
|
93
|
+
string := |*
|
182
94
|
## == Single quote strings
|
183
|
-
|
184
95
|
sqs1 = "'" . ([^\']* | ([^\'\\]*[\\][\'][^\']*)*) . '\\\\'* . "'";
|
185
96
|
sqs2 = '~' . ([^\~]* | ([^\~\\]*[\\][\~][^\~]*)*) . '\\\\'* . '~';
|
186
97
|
sqs3 = '`' . ([^\`]* | ([^\`\\]*[\\][\`][^\`]*)*) . '\\\\'* . '`';
|
@@ -222,7 +133,6 @@ module Sourcify
|
|
222
133
|
};
|
223
134
|
|
224
135
|
## == Double quote strings
|
225
|
-
|
226
136
|
dqs1 = '"' . (([^\"]* | ([^\"\\]*[\\][\"][^\"]*)*) -- '#{') . '\\\\'* . ('"' | '#{');
|
227
137
|
dqs2 = '`' . (([^\`]* | ([^\`\\]*[\\][\`][^\`]*)*) -- '#{') . '\\\\'* . ('`' | '#{');
|
228
138
|
dqs3 = '/' . (([^\/]* | ([^\/\\]*[\\][\/][^\/]*)*) -- '#{') . '\\\\'* . ('/' | '#{');
|
@@ -266,6 +176,107 @@ module Sourcify
|
|
266
176
|
end
|
267
177
|
};
|
268
178
|
|
179
|
+
## == Anything accidentally caught
|
180
|
+
any => {
|
181
|
+
push(:any, ts, te)
|
182
|
+
fgoto main;
|
183
|
+
};
|
184
|
+
|
185
|
+
*|;
|
186
|
+
|
187
|
+
## MACHINE >> Double quote string
|
188
|
+
double_quote_str := |*
|
189
|
+
delimiter = [\~\`\!\@\#\$\%\^\&\*\)\-\_\+\=\}\]\:\;\'\"\>\,\.\?\/\|\\];
|
190
|
+
(^delimiter* . delimiter) -- ('\\' . delimiter) => {
|
191
|
+
unless push_dstring(ts, te)
|
192
|
+
fgoto main;
|
193
|
+
end
|
194
|
+
};
|
195
|
+
*|;
|
196
|
+
|
197
|
+
## MACHINE >> Main
|
198
|
+
main := |*
|
199
|
+
|
200
|
+
## == Start/end of do..end block
|
201
|
+
|
202
|
+
kw_do => {
|
203
|
+
push(:kw_do, ts, te)
|
204
|
+
increment_counter(:do_end)
|
205
|
+
fgoto new_statement;
|
206
|
+
};
|
207
|
+
|
208
|
+
kw_end => {
|
209
|
+
push(:kw_end, ts, te)
|
210
|
+
decrement_counter(:do_end)
|
211
|
+
};
|
212
|
+
|
213
|
+
## == Start/end of {...} block
|
214
|
+
|
215
|
+
lbrace => {
|
216
|
+
push(:lbrace, ts, te)
|
217
|
+
increment_counter(:brace)
|
218
|
+
};
|
219
|
+
|
220
|
+
rbrace => {
|
221
|
+
push(:rbrace, ts, te)
|
222
|
+
decrement_counter(:brace)
|
223
|
+
};
|
224
|
+
|
225
|
+
assoc => {
|
226
|
+
push(:assoc, ts, te)
|
227
|
+
fix_counter_false_start(:brace)
|
228
|
+
};
|
229
|
+
|
230
|
+
label => {
|
231
|
+
push_label(ts, te)
|
232
|
+
fix_counter_false_start(:brace)
|
233
|
+
};
|
234
|
+
|
235
|
+
## == New statement
|
236
|
+
|
237
|
+
newline => {
|
238
|
+
push(:newline, ts, te)
|
239
|
+
increment_lineno
|
240
|
+
fgoto new_statement;
|
241
|
+
};
|
242
|
+
|
243
|
+
smcolon | lparen | assgn | kw_then | comma => {
|
244
|
+
push(:newline_alias, ts, te)
|
245
|
+
fgoto new_statement;
|
246
|
+
};
|
247
|
+
|
248
|
+
## == Comment
|
249
|
+
|
250
|
+
'#' => {
|
251
|
+
fgoto per_line_comment;
|
252
|
+
};
|
253
|
+
|
254
|
+
newline . '=begin' . ospaces . (ospaces . ^newline+)* . newline => {
|
255
|
+
push_comment(ts, te)
|
256
|
+
increment_lineno
|
257
|
+
fgoto block_comment;
|
258
|
+
};
|
259
|
+
|
260
|
+
## == Strings
|
261
|
+
|
262
|
+
('<<' | '<<-') . ["']? . (const | var) . ["']? . newline => {
|
263
|
+
push_heredoc(ts, te)
|
264
|
+
increment_lineno
|
265
|
+
fgoto heredoc;
|
266
|
+
};
|
267
|
+
|
268
|
+
('"' | "'" | '`' | '/' | '%') => {
|
269
|
+
fhold; fgoto string;
|
270
|
+
};
|
271
|
+
|
272
|
+
## == Misc
|
273
|
+
|
274
|
+
var => { push(:var, ts, te) };
|
275
|
+
const => { push(:const, ts, te) };
|
276
|
+
symbol => { push(:symbol, ts, te) };
|
277
|
+
mspaces => { push(:space, ts, te) };
|
278
|
+
any => { push(:any, ts, te) };
|
279
|
+
|
269
280
|
*|;
|
270
281
|
|
271
282
|
}%%
|
data/sourcify.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sourcify}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["NgTzeYang"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-14}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{ngty77@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -73,7 +73,6 @@ Gem::Specification.new do |s|
|
|
73
73
|
"spec/proc_scanner/per_line_comment_spec.rb",
|
74
74
|
"spec/proc_scanner/single_quote_str_spec.rb",
|
75
75
|
"spec/proc_scanner/spec_helper.rb",
|
76
|
-
"spec/proc_scanner/to_proc_spec.rb",
|
77
76
|
"spec/spec_helper.rb"
|
78
77
|
]
|
79
78
|
s.homepage = %q{http://github.com/ngty/sourcify}
|
@@ -84,7 +83,6 @@ Gem::Specification.new do |s|
|
|
84
83
|
s.test_files = [
|
85
84
|
"spec/proc_scanner/kw_do_alias1_spec.rb",
|
86
85
|
"spec/proc_scanner/single_quote_str_spec.rb",
|
87
|
-
"spec/proc_scanner/to_proc_spec.rb",
|
88
86
|
"spec/proc_scanner/kw_do_alias2_spec.rb",
|
89
87
|
"spec/proc_scanner/double_colons_spec.rb",
|
90
88
|
"spec/proc_scanner/block_comment_spec.rb",
|
@@ -26,7 +26,7 @@ def dump_object_space_procs(debug = false)
|
|
26
26
|
'== NOTE: dump files can be found at %s' % dump_dir
|
27
27
|
|
28
28
|
# Core processing
|
29
|
-
ObjectSpace.each_object(Proc).to_a.
|
29
|
+
ObjectSpace.each_object(Proc).to_a.select{|o| o.source_location }.
|
30
30
|
group_by{|o| o.source_location[0] }.each do |ofile, objs|
|
31
31
|
nfile = File.join(dump_dir, ofile.gsub('/','~'))
|
32
32
|
File.open(nfile,'w') do |f|
|
@@ -17,153 +17,61 @@ describe "Created on the fly proc" do
|
|
17
17
|
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
18
18
|
end
|
19
19
|
|
20
|
-
should "not raise even with prepending
|
20
|
+
should "not raise even with prepending #to_proc on the same line" do
|
21
21
|
x, y = klass.new.method(:test).to_proc, lambda { 1+2 }
|
22
22
|
y.to_source.should.not.be.nil
|
23
23
|
end
|
24
24
|
|
25
|
-
should "not raise even with appending
|
25
|
+
should "not raise even with appending #to_proc on the same line" do
|
26
26
|
x, y = lambda { 1+2 }, klass.new.method(:test).to_proc
|
27
27
|
x.to_source.should.not.be.nil
|
28
28
|
end
|
29
29
|
|
30
|
-
should "not raise even with nested
|
30
|
+
should "not raise even with nested #to_proc on the same line" do
|
31
31
|
x = lambda { klass.new.method(:test).to_proc }
|
32
32
|
x.to_source.should.not.be.nil
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
should "not raise with nested #to_proc on diff line" do
|
36
|
+
(
|
37
|
+
lambda do
|
38
|
+
klass.new.method(:test).to_proc
|
39
|
+
end
|
40
|
+
).to_source.should.not.be.nil
|
41
|
+
end
|
38
42
|
|
39
|
-
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
lambda {
|
43
|
-
x, y = klass.new.test(&:blah), lambda { 1+2 }
|
44
|
-
x.to_source
|
45
|
-
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
46
|
-
end
|
45
|
+
describe '&:blah raising Sourcify::CannotHandleCreatedOnTheFlyProcError' do
|
47
46
|
|
48
|
-
|
47
|
+
should "raise when created by &:blah" do
|
48
|
+
lambda {
|
49
49
|
x, y = klass.new.test(&:blah), lambda { 1+2 }
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
should "not raise even with appending &:blah on the same line" do
|
54
|
-
x, y = lambda { 1+2 }, klass.new.test(&:blah)
|
55
|
-
x.to_source.should.not.be.nil
|
56
|
-
end
|
57
|
-
|
58
|
-
should "not raise even with nested &:blah on the same line" do
|
59
|
-
x = lambda { klass.new.test(&:blah) }
|
60
|
-
x.to_source.should.not.be.nil
|
61
|
-
end
|
62
|
-
|
63
|
-
should "not raise with nested &:blah on diff line" do
|
64
|
-
(
|
65
|
-
lambda do
|
66
|
-
klass.new.test(&:blah)
|
67
|
-
end
|
68
|
-
).to_source.should.not.be.nil
|
69
|
-
end
|
70
|
-
|
50
|
+
x.to_source
|
51
|
+
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
71
52
|
end
|
72
53
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
should "raise w no other proc on the same line" do
|
78
|
-
lambda {
|
79
|
-
x = klass.new.test(&:blah)
|
80
|
-
x.to_source
|
81
|
-
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
82
|
-
end
|
83
|
-
|
84
|
-
should "raise w prepending proc of different arity on the same line" do
|
85
|
-
lambda {
|
86
|
-
y, x = lambda {|a| 1+2 }, klass.new.test(&:blah)
|
87
|
-
x.to_source
|
88
|
-
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
89
|
-
end
|
90
|
-
|
91
|
-
should "raise w appending proc of different arity on the same line" do
|
92
|
-
lambda {
|
93
|
-
x, y = klass.new.test(&:blah), lambda {|a| 1+2 }
|
94
|
-
x.to_source
|
95
|
-
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
96
|
-
end
|
97
|
-
|
98
|
-
should "raise w nested proc of different arity on the same line" do
|
99
|
-
lambda {
|
100
|
-
y = lambda {|a| klass.new.test(&:blah) }
|
101
|
-
x = y.call(1).to_source
|
102
|
-
}.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "not raise with nested &:blah on diff line" do
|
106
|
-
(
|
107
|
-
lambda do
|
108
|
-
klass.new.test(&:blah)
|
109
|
-
end
|
110
|
-
).to_source.should.not.be.nil
|
111
|
-
end
|
54
|
+
should "not raise even with prepending &:blah on the same line" do
|
55
|
+
x, y = klass.new.test(&:blah), lambda { 1+2 }
|
56
|
+
y.to_source.should.not.be.nil
|
57
|
+
end
|
112
58
|
|
59
|
+
should "not raise even with appending &:blah on the same line" do
|
60
|
+
x, y = lambda { 1+2 }, klass.new.test(&:blah)
|
61
|
+
x.to_source.should.not.be.nil
|
113
62
|
end
|
114
63
|
|
115
|
-
|
116
|
-
|
117
|
-
should
|
118
|
-
|
119
|
-
y, x = lambda { 1+2 }, klass.new.test(&:blah)
|
120
|
-
x.to_source
|
121
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
122
|
-
end
|
123
|
-
|
124
|
-
should 'raise w appending proc w zero arg (arity -1) on the same line' do
|
125
|
-
lambda {
|
126
|
-
x, y = klass.new.test(&:blah), lambda { 1+2 }
|
127
|
-
x.to_source
|
128
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
129
|
-
end
|
130
|
-
|
131
|
-
should 'raise w nested proc w zero arg (arity -1) on the same line' do
|
132
|
-
lambda {
|
133
|
-
x = lambda { klass.new.test(&:blah) }
|
134
|
-
x.call.to_source
|
135
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
136
|
-
end
|
137
|
-
|
138
|
-
should 'raise w prepending proc w single optional arg (arity -1) on the same line' do
|
139
|
-
lambda {
|
140
|
-
y, x = lambda {|*a| 1+2 }, klass.new.test(&:blah)
|
141
|
-
x.to_source
|
142
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
143
|
-
end
|
144
|
-
|
145
|
-
should 'raise w appending proc w single optional arg (arity -1) on the same line' do
|
146
|
-
lambda {
|
147
|
-
x, y = klass.new.test(&:blah), lambda {|*a| 1+2 }
|
148
|
-
x.to_source
|
149
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
150
|
-
end
|
151
|
-
|
152
|
-
should 'raise w nested proc w single optional arg (arity -1) on the same line' do
|
153
|
-
lambda {
|
154
|
-
x = lambda {|*a| klass.new.test(&:blah) }
|
155
|
-
x.call.to_source
|
156
|
-
}.should.raise(Sourcify::MultipleMatchingProcsPerLineError)
|
157
|
-
end
|
158
|
-
|
159
|
-
should "not raise with nested &:blah on diff line" do
|
160
|
-
(
|
161
|
-
lambda do
|
162
|
-
x = klass.new.test(&:blah)
|
163
|
-
end
|
164
|
-
).to_source.should.not.be.nil
|
165
|
-
end
|
64
|
+
should "not raise even with nested &:blah on the same line" do
|
65
|
+
x = lambda { klass.new.test(&:blah) }
|
66
|
+
x.to_source.should.not.be.nil
|
67
|
+
end
|
166
68
|
|
69
|
+
should "not raise with nested &:blah on diff line" do
|
70
|
+
(
|
71
|
+
lambda do
|
72
|
+
klass.new.test(&:blah)
|
73
|
+
end
|
74
|
+
).to_source.should.not.be.nil
|
167
75
|
end
|
168
76
|
|
169
77
|
end
|