sourcify 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/HISTORY.txt +11 -0
- data/README.rdoc +52 -28
- data/VERSION +1 -1
- data/lib/sourcify.rb +13 -1
- data/lib/sourcify/proc.rb +7 -4
- data/lib/sourcify/proc/parser.rb +109 -40
- data/lib/sourcify/proc/scanner.rb +2140 -0
- data/lib/sourcify/proc/scanner.rl +285 -0
- data/lib/sourcify/proc/scanner/comment.rb +21 -0
- data/lib/sourcify/proc/scanner/counter.rb +44 -0
- data/lib/sourcify/proc/scanner/dstring.rb +58 -0
- data/lib/sourcify/proc/scanner/extensions.rb +135 -0
- data/lib/sourcify/proc/scanner/heredoc.rb +24 -0
- data/sourcify.gemspec +38 -9
- data/spec/dump_object_space_procs.rb +84 -0
- data/spec/proc/created_on_the_fly_proc_spec.rb +172 -0
- data/spec/proc/others_spec.rb +36 -0
- data/spec/proc/to_sexp_variables_spec.rb +6 -6
- data/spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb +2 -0
- data/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +105 -29
- data/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +85 -17
- data/spec/proc_scanner/block_comment_spec.rb +59 -0
- data/spec/proc_scanner/double_colons_spec.rb +14 -0
- data/spec/proc_scanner/double_quote_str_w_interpolation_spec.rb +62 -0
- data/spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb +75 -0
- data/spec/proc_scanner/heredoc_spec.rb +142 -0
- data/spec/proc_scanner/kw_do_alias1_spec.rb +87 -0
- data/spec/proc_scanner/kw_do_alias2_spec.rb +86 -0
- data/spec/proc_scanner/per_line_comment_spec.rb +34 -0
- data/spec/proc_scanner/single_quote_str_spec.rb +68 -0
- data/spec/proc_scanner/spec_helper.rb +33 -0
- data/spec/proc_scanner/to_proc_spec.rb +15 -0
- data/spec/spec_helper.rb +23 -0
- metadata +39 -10
- data/lib/sourcify/proc/counter.rb +0 -41
- data/lib/sourcify/proc/lexer.rb +0 -40
- data/lib/sourcify/proc/lexer18.rb +0 -237
- data/lib/sourcify/proc/lexer19.rb +0 -204
- data/spec/proc/misc_spec.rb +0 -16
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Heredoc (wo indent)" do
|
4
|
+
%w{X "X" 'X'}.each do |tag|
|
5
|
+
|
6
|
+
should "handle <<#{tag}\\n .. \\nX\\n" do
|
7
|
+
process(%Q(
|
8
|
+
s <<#{tag}
|
9
|
+
aa
|
10
|
+
X
|
11
|
+
)).should.include([:heredoc, "<<#{tag}\n aa \nX"])
|
12
|
+
end
|
13
|
+
|
14
|
+
should "not handle <<#{tag} \\n .. \\nX\\n" do
|
15
|
+
process(%Q(
|
16
|
+
s << #{tag}
|
17
|
+
aa
|
18
|
+
X
|
19
|
+
)).should.not.include([:heredoc, "<<#{tag} \n aa \nX"])
|
20
|
+
end
|
21
|
+
|
22
|
+
should "not handle <<#{tag}\\n .. \\n X\\n" do
|
23
|
+
process(%Q(
|
24
|
+
s <<#{tag}
|
25
|
+
aa
|
26
|
+
X
|
27
|
+
)).should.not.include([:heredoc, "<<#{tag} \n aa \n X"])
|
28
|
+
end
|
29
|
+
|
30
|
+
should "not handle <<#{tag}\\n .. \\nX \\n" do
|
31
|
+
process(%Q(
|
32
|
+
s <<#{tag}
|
33
|
+
aa
|
34
|
+
X
|
35
|
+
)).should.not.include([:heredoc, "<<#{tag} \n aa \nX "])
|
36
|
+
end
|
37
|
+
|
38
|
+
should "not handle class <<#{tag}\\n .. \\nX \\n" do
|
39
|
+
process(%Q(
|
40
|
+
|
41
|
+
class <<#{tag}
|
42
|
+
aa
|
43
|
+
X
|
44
|
+
)).should.not.include([:heredoc, "<<#{tag}\n aa \nX"])
|
45
|
+
end
|
46
|
+
|
47
|
+
should "handle xclass <<#{tag}\\n .. \\nX \\n" do
|
48
|
+
process(%Q(
|
49
|
+
xclass <<#{tag}
|
50
|
+
aa
|
51
|
+
X
|
52
|
+
)).should.include([:heredoc, "<<#{tag}\n aa \nX"])
|
53
|
+
end
|
54
|
+
|
55
|
+
should "handle classx <<#{tag}\\n .. \\nX \\n" do
|
56
|
+
process(%Q(
|
57
|
+
classx <<#{tag}
|
58
|
+
aa
|
59
|
+
X
|
60
|
+
)).should.include([:heredoc, "<<#{tag}\n aa \nX"])
|
61
|
+
end
|
62
|
+
|
63
|
+
should "handle <<#{tag}\\n .. \\nX \\n" do
|
64
|
+
process(%Q(
|
65
|
+
<<#{tag}
|
66
|
+
aa
|
67
|
+
X
|
68
|
+
)).should.include([:heredoc, "<<#{tag}\n aa \nX"])
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "Heredoc (w indent)" do
|
75
|
+
%w{X "X" 'X'}.each do |tag|
|
76
|
+
|
77
|
+
should "handle <<-#{tag}\\n .. \\nX\\n" do
|
78
|
+
process(%Q(
|
79
|
+
s <<-#{tag}
|
80
|
+
aa
|
81
|
+
X
|
82
|
+
)).should.include([:heredoc, "<<-#{tag}\n aa \nX"])
|
83
|
+
end
|
84
|
+
|
85
|
+
should "handle <<-#{tag}\\n .. \\n X\\n" do
|
86
|
+
process(%Q(
|
87
|
+
s <<-#{tag}
|
88
|
+
aa
|
89
|
+
X
|
90
|
+
)).should.include([:heredoc, "<<-#{tag}\n aa \n X"])
|
91
|
+
end
|
92
|
+
|
93
|
+
should "not handle <<-#{tag} \\n .. \\nX\\n" do
|
94
|
+
process(%Q(
|
95
|
+
s <<-#{tag}
|
96
|
+
aa
|
97
|
+
X
|
98
|
+
)).should.not.include([:heredoc, "<<-#{tag} \n aa \n X"])
|
99
|
+
end
|
100
|
+
|
101
|
+
should "not handle <<-#{tag}\\n .. \\nX \\n" do
|
102
|
+
process(%Q(
|
103
|
+
s <<-#{tag}
|
104
|
+
aa
|
105
|
+
X
|
106
|
+
)).should.not.include([:heredoc, "<<-#{tag}\n aa \nX "])
|
107
|
+
end
|
108
|
+
|
109
|
+
should "not handle class <<-#{tag}\\n .. \\nX \\n" do
|
110
|
+
process(%Q(
|
111
|
+
class <<-#{tag}
|
112
|
+
aa
|
113
|
+
X
|
114
|
+
)).should.not.include([:heredoc, "<<-#{tag}\n aa \nX"])
|
115
|
+
end
|
116
|
+
|
117
|
+
should "handle xclass <<-#{tag}\\n .. \\nX \\n" do
|
118
|
+
process(%Q(
|
119
|
+
xclass <<-#{tag}
|
120
|
+
aa
|
121
|
+
X
|
122
|
+
)).should.include([:heredoc, "<<-#{tag}\n aa \nX"])
|
123
|
+
end
|
124
|
+
|
125
|
+
should "handle classx <<-#{tag}\\n .. \\nX \\n" do
|
126
|
+
process(%Q(
|
127
|
+
classx <<-#{tag}
|
128
|
+
aa
|
129
|
+
X
|
130
|
+
)).should.include([:heredoc, "<<-#{tag}\n aa \nX"])
|
131
|
+
end
|
132
|
+
|
133
|
+
should "handle <<-#{tag}\\n .. \\nX \\n" do
|
134
|
+
process(%Q(
|
135
|
+
<<-#{tag}
|
136
|
+
aa
|
137
|
+
X
|
138
|
+
)).should.include([:heredoc, "<<-#{tag}\n aa \nX"])
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Keyword do alias #1 (incrementing do...end counter by 1)" do
|
4
|
+
|
5
|
+
behaves_like 'has started do...end counter'
|
6
|
+
|
7
|
+
%w{class def module begin case module if unless}.each do |kw|
|
8
|
+
|
9
|
+
%w{_ x 1}.each do |c|
|
10
|
+
should "not increment counter with ... (#{kw}#{c} ...)" do
|
11
|
+
do_end_counter(<<EOL
|
12
|
+
aa (#{kw}#{c} bb ... )
|
13
|
+
cc
|
14
|
+
EOL
|
15
|
+
).should.equal([0,0])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "increment counter with ... (#{kw} ...)" do
|
20
|
+
do_end_counter(<<EOL
|
21
|
+
aa (#{kw} bb ... )
|
22
|
+
cc
|
23
|
+
EOL
|
24
|
+
).should.equal([1,1])
|
25
|
+
end
|
26
|
+
|
27
|
+
should "increment counter with ... ; #{kw} ..." do
|
28
|
+
do_end_counter(<<EOL
|
29
|
+
aa; #{kw} bb ...
|
30
|
+
cc
|
31
|
+
EOL
|
32
|
+
).should.equal([1,1])
|
33
|
+
end
|
34
|
+
|
35
|
+
should "increment counter with ... \\n #{kw} ..." do
|
36
|
+
do_end_counter(<<EOL
|
37
|
+
aa
|
38
|
+
#{kw} bb ...
|
39
|
+
cc
|
40
|
+
EOL
|
41
|
+
).should.equal([1,1])
|
42
|
+
end
|
43
|
+
|
44
|
+
should "increment counter with ... \\n \t #{kw} ..." do
|
45
|
+
do_end_counter(<<EOL
|
46
|
+
aa
|
47
|
+
\t #{kw} bb ...
|
48
|
+
cc
|
49
|
+
EOL
|
50
|
+
).should.equal([1,1])
|
51
|
+
end
|
52
|
+
|
53
|
+
should "increment counter with ... , #{kw} ..." do
|
54
|
+
do_end_counter(<<EOL
|
55
|
+
aa , #{kw} bb ...
|
56
|
+
cc
|
57
|
+
EOL
|
58
|
+
).should.equal([1,1])
|
59
|
+
end
|
60
|
+
|
61
|
+
should "increment counter with ... = #{kw} ..." do
|
62
|
+
do_end_counter(<<EOL
|
63
|
+
aa = #{kw} bb ...
|
64
|
+
cc
|
65
|
+
EOL
|
66
|
+
).should.equal([1,1])
|
67
|
+
end
|
68
|
+
|
69
|
+
should "increment counter with ... do #{kw} ..." do
|
70
|
+
do_end_counter(<<EOL
|
71
|
+
aa do #{kw} bb ...
|
72
|
+
cc
|
73
|
+
EOL
|
74
|
+
).should.equal([2,2])
|
75
|
+
end
|
76
|
+
|
77
|
+
should "increment counter with ... then #{kw} ..." do
|
78
|
+
do_end_counter(<<EOL
|
79
|
+
aa then #{kw} bb ...
|
80
|
+
cc
|
81
|
+
EOL
|
82
|
+
).should.equal([1,1])
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Keyword do alias #2 (increment do..end block counter by 0..1)" do
|
4
|
+
|
5
|
+
behaves_like 'has started do...end counter'
|
6
|
+
|
7
|
+
%w{while until for}.each do |kw|
|
8
|
+
|
9
|
+
%w{_ x 1}.each do |c|
|
10
|
+
should "not increment counter with ... (#{kw}#{c} ...)" do
|
11
|
+
do_end_counter(<<EOL
|
12
|
+
aa (#{kw}#{c} bb ... )
|
13
|
+
cc
|
14
|
+
EOL
|
15
|
+
).should.equal([0,0])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "increment counter with ... (#{kw} ...)" do
|
20
|
+
do_end_counter(<<EOL
|
21
|
+
aa (#{kw} bb ... )
|
22
|
+
cc
|
23
|
+
EOL
|
24
|
+
).should.equal([0,1])
|
25
|
+
end
|
26
|
+
|
27
|
+
should "increment counter with ... ; #{kw} ..." do
|
28
|
+
do_end_counter(<<EOL
|
29
|
+
aa; #{kw} bb ...
|
30
|
+
cc
|
31
|
+
EOL
|
32
|
+
).should.equal([0,1])
|
33
|
+
end
|
34
|
+
|
35
|
+
should "increment counter with ... \\n #{kw} ..." do
|
36
|
+
do_end_counter(<<EOL
|
37
|
+
aa
|
38
|
+
#{kw} bb ...
|
39
|
+
cc
|
40
|
+
EOL
|
41
|
+
).should.equal([0,1])
|
42
|
+
end
|
43
|
+
|
44
|
+
should "increment counter with ... \\n \t #{kw} ..." do
|
45
|
+
do_end_counter(<<EOL
|
46
|
+
aa
|
47
|
+
\t #{kw} bb ...
|
48
|
+
cc
|
49
|
+
EOL
|
50
|
+
).should.equal([0,1])
|
51
|
+
end
|
52
|
+
|
53
|
+
should "increment counter with ... = #{kw} ..." do
|
54
|
+
do_end_counter(<<EOL
|
55
|
+
aa = #{kw} bb ...
|
56
|
+
cc
|
57
|
+
EOL
|
58
|
+
).should.equal([0,1])
|
59
|
+
end
|
60
|
+
|
61
|
+
should "increment counter with ... , #{kw} ..." do
|
62
|
+
do_end_counter(<<EOL
|
63
|
+
aa , #{kw} bb ...
|
64
|
+
cc
|
65
|
+
EOL
|
66
|
+
).should.equal([0,1])
|
67
|
+
end
|
68
|
+
|
69
|
+
should "increment counter with ... do #{kw} ..." do
|
70
|
+
do_end_counter(<<EOL
|
71
|
+
aa do #{kw} bb ...
|
72
|
+
cc
|
73
|
+
EOL
|
74
|
+
).should.equal([1,2])
|
75
|
+
end
|
76
|
+
|
77
|
+
should "increment counter with ... then #{kw} ..." do
|
78
|
+
do_end_counter(<<EOL
|
79
|
+
aa then #{kw} bb ...
|
80
|
+
cc
|
81
|
+
EOL
|
82
|
+
).should.equal([0,1])
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Per line comment (# ...)" do
|
4
|
+
|
5
|
+
should 'handle start of line' do
|
6
|
+
process(<<EOL
|
7
|
+
aa
|
8
|
+
# bb
|
9
|
+
cc
|
10
|
+
EOL
|
11
|
+
).should.include([:comment, '# bb'])
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'handle middle of line' do
|
15
|
+
process(<<EOL
|
16
|
+
aa # bb
|
17
|
+
cc
|
18
|
+
EOL
|
19
|
+
).should.include([:comment, '# bb'])
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'ignore within heredoc' do
|
23
|
+
process(<<EOL
|
24
|
+
s <<eol
|
25
|
+
aa
|
26
|
+
# bb
|
27
|
+
cc
|
28
|
+
eol
|
29
|
+
EOL
|
30
|
+
).should.not.include([:comment, '# bb'])
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Single quote strings (\', %q & %w)' do
|
4
|
+
|
5
|
+
%w{~ ` ! @ # $ % ^ & * _ - + = \\ | ; : ' " , . ? /}.map{|w| [w,w] }.concat(
|
6
|
+
[%w{( )}, %w{[ ]}, %w({ }), %w{< >}]
|
7
|
+
).each do |q1,q2|
|
8
|
+
%w{q w}.each do |t|
|
9
|
+
|
10
|
+
should "handle %#{t}#{q1}...#{q2} (wo escape (single))" do
|
11
|
+
process(" xx %#{t}#{q1}hello#{q2} ").should.include([:sstring, "%#{t}#{q1}hello#{q2}"])
|
12
|
+
end
|
13
|
+
|
14
|
+
should "handle %#{t}#{q1}...#{q2} (wo escape (multiple))" do
|
15
|
+
tokens = process(" xx %#{t}#{q1}hello#{q2} %#{t}#{q1}world#{q2} ")
|
16
|
+
tokens.should.include([:sstring, "%#{t}#{q1}hello#{q2}"])
|
17
|
+
tokens.should.include([:sstring, "%#{t}#{q1}world#{q2}"])
|
18
|
+
end
|
19
|
+
|
20
|
+
should "handle %#{t}#{q1}...#{q2} (w escape (single))" do
|
21
|
+
process(" xx %#{t}#{q1}hel\\#{q2}lo#{q2} ").should.
|
22
|
+
include([:sstring, "%#{t}#{q1}hel\\#{q2}lo#{q2}"])
|
23
|
+
end
|
24
|
+
|
25
|
+
should "handle %#{t}#{q1}...#{q2} (w escape (multiple))" do
|
26
|
+
process(" xx %#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2} ").should.
|
27
|
+
include([:sstring, "%#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2}"])
|
28
|
+
end
|
29
|
+
|
30
|
+
# NOTE: We are skipping '\\' cos %q\\\\ is always raise SyntaxError no matter
|
31
|
+
# how many backslashes we add
|
32
|
+
unless q1 == '\\'
|
33
|
+
should "handle %#{t}#{q1}\\\\#{q2}" do
|
34
|
+
process(" xx %#{t}#{q1}\\\\#{q2} %#{t}#{q2}lo#{q2} ").should.
|
35
|
+
include([:sstring, "%#{t}#{q1}\\\\#{q2}"])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "handle '...' (wo escape (single))" do
|
43
|
+
process(" xx 'hello' ").should.include([:sstring, "'hello'"])
|
44
|
+
end
|
45
|
+
|
46
|
+
should "handle '...' (wo escape (multiple))" do
|
47
|
+
tokens = process(" xx 'hello' 'world' ")
|
48
|
+
tokens.should.include([:sstring, "'hello'"])
|
49
|
+
tokens.should.include([:sstring, "'world'"])
|
50
|
+
end
|
51
|
+
|
52
|
+
should "handle '...' (w escape (single))" do
|
53
|
+
process(" xx 'hel\\'lo' ").should.include([:sstring, "'hel\\'lo'"])
|
54
|
+
end
|
55
|
+
|
56
|
+
should "handle '...' (w escape (multiple))" do
|
57
|
+
process(" xx 'h\\'el\\'lo' ").should.include([:sstring, "'h\\'el\\'lo'"])
|
58
|
+
end
|
59
|
+
|
60
|
+
should "handle '\\\\'" do
|
61
|
+
process(%q(
|
62
|
+
aa '\\\\'
|
63
|
+
cc
|
64
|
+
'dd'
|
65
|
+
)).should.include([:sstring, "'\\\\'"])
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
module Sourcify::Proc::Scanner
|
4
|
+
class << self ; attr_reader :tokens ; end
|
5
|
+
class << self ; attr_reader :do_end_counter ; end
|
6
|
+
end
|
7
|
+
|
8
|
+
def process(data)
|
9
|
+
Sourcify::Proc::Scanner.process(data)
|
10
|
+
Sourcify::Proc::Scanner.tokens
|
11
|
+
end
|
12
|
+
|
13
|
+
def do_end_counter(data)
|
14
|
+
Sourcify::Proc::Scanner.process(data)
|
15
|
+
Sourcify::Proc::Scanner.do_end_counter.counts
|
16
|
+
end
|
17
|
+
|
18
|
+
shared 'has started do...end counter' do
|
19
|
+
|
20
|
+
before do
|
21
|
+
Sourcify::Proc::Scanner::DoEndBlockCounter.class_eval do
|
22
|
+
alias_method :orig_started?, :started?
|
23
|
+
def started?; true; end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
Sourcify::Proc::Scanner::DoEndBlockCounter.class_eval do
|
29
|
+
alias_method :started?, :orig_started?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|