yard_ast_editable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/yard_ast_editable.rb +60 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/yard_ast_editable_spec.rb +122 -0
- data/spec/yard_ast_spec.rb +145 -0
- data/yard_ast_editable.gemspec +69 -0
- metadata +151 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "yard", ">= 0.6.3"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.1.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.1"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 akimatter
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= yard_ast_editable
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to yard_ast_editable
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 akimatter. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "yard_ast_editable"
|
16
|
+
gem.homepage = "http://github.com/akm/yard_ast_editable"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{yard extension to modify source code by using AST Node}
|
19
|
+
gem.description = %Q{yard extension to modify source code by using AST Node}
|
20
|
+
gem.email = "akm2000@gmail.com"
|
21
|
+
gem.authors = ["akimatter"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "yard_ast_editable #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'yard'
|
3
|
+
|
4
|
+
module YardAstEditable
|
5
|
+
|
6
|
+
class Fcall
|
7
|
+
attr_reader :node
|
8
|
+
def initialize(node)
|
9
|
+
@node = node
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
@node[0].source
|
14
|
+
end
|
15
|
+
|
16
|
+
def block
|
17
|
+
@node[2]
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments
|
21
|
+
return @arguments if @arguments
|
22
|
+
n = @node[1]
|
23
|
+
@arguments = (n.type == :arg_paren ? n[0] : n) || []
|
24
|
+
@arguments.pop if @arguments.last == false
|
25
|
+
@arguments
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
FCALL_TYPES = [:fcall, :command].freeze
|
31
|
+
|
32
|
+
# メソッドを見つける
|
33
|
+
# fcall_ident: メソッド名
|
34
|
+
def fcall_by_ident(fcall_ident)
|
35
|
+
fcall_ident = fcall_ident.to_s
|
36
|
+
traverse do |child|
|
37
|
+
if FCALL_TYPES.include?(child.type)
|
38
|
+
if child[0].source == fcall_ident
|
39
|
+
if block_given?
|
40
|
+
return(child) if yield(Fcall.new(child))
|
41
|
+
else
|
42
|
+
return(child)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def replace_source(node, new_source)
|
51
|
+
result = full_source.dup
|
52
|
+
result[node.source_range] = new_source
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
YARD::Parser::Ruby::AstNode.module_eval do
|
59
|
+
include YardAstEditable
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'yard_ast_editable'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
block_tree1 = <<EOS
|
5
|
+
# foo1 #1
|
6
|
+
foo1(:name1) do |f1|
|
7
|
+
# bar1 #1
|
8
|
+
bar1 do |b1|
|
9
|
+
# bar1 #2
|
10
|
+
bar1("name2"){|b2|
|
11
|
+
# b2 S
|
12
|
+
puts b2.inspect
|
13
|
+
# b2 E
|
14
|
+
}
|
15
|
+
# bar2 E
|
16
|
+
end
|
17
|
+
end
|
18
|
+
# foo1 #2 S
|
19
|
+
foo1 :name2, :opt1 => true do |f1|
|
20
|
+
# bar1 #3 S
|
21
|
+
bar1{ puts "name2 bar1" }
|
22
|
+
# bar1 #3 E
|
23
|
+
end
|
24
|
+
# foo1 #2 E
|
25
|
+
EOS
|
26
|
+
|
27
|
+
describe "YardAstEditable" do
|
28
|
+
before do
|
29
|
+
@ast = YARD::Parser::Ruby::RubyParser.new(block_tree1, nil).parse.root
|
30
|
+
end
|
31
|
+
|
32
|
+
describe :fcall_by_ident do
|
33
|
+
|
34
|
+
it "foo1 by name only" do
|
35
|
+
node = @ast.fcall_by_ident(:foo1)
|
36
|
+
node.should be_a(YARD::Parser::Ruby::AstNode)
|
37
|
+
node.source.should =~ /^foo1\(:name1\)/
|
38
|
+
node.source.should =~ /bar1 do |b1|/
|
39
|
+
node[0].should be_a(YARD::Parser::Ruby::AstNode)
|
40
|
+
node[0].source.should == "foo1"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "first foo1 by name and block" do
|
44
|
+
node = @ast.fcall_by_ident(:foo1){|fcall|
|
45
|
+
(fcall.arguments.length == 1) && (n = fcall.arguments.first; n.source == ":name1")
|
46
|
+
}
|
47
|
+
node.should be_a(YARD::Parser::Ruby::AstNode)
|
48
|
+
node[0].source.should == "foo1"
|
49
|
+
node[1].source.should == "(:name1)"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "second foo1 by name and block" do
|
53
|
+
node = @ast.fcall_by_ident(:foo1){|fcall|
|
54
|
+
fcall.arguments.length == 2 && (n = fcall.arguments.first; n.source == ":name2")
|
55
|
+
}
|
56
|
+
node.should be_a(YARD::Parser::Ruby::AstNode)
|
57
|
+
node[0].source.should == "foo1"
|
58
|
+
node[1].source.should == ":name2, :opt1 => true"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "find bar1 #1" do
|
62
|
+
node = @ast.fcall_by_ident(:bar1){|fcall| fcall.arguments.empty? }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe :replace_source do
|
67
|
+
it "全体に対して一部を置換" do
|
68
|
+
node = @ast.fcall_by_ident(:foo1){|fcall|
|
69
|
+
fcall.arguments.length == 2 && (n = fcall.arguments.first; n.source == ":name2")
|
70
|
+
}
|
71
|
+
fcall = YardAstEditable::Fcall.new(node)
|
72
|
+
fcall.block.should_not == nil
|
73
|
+
@ast.replace_source(fcall.block, "do\n replaced_block\nend").should == <<EOS
|
74
|
+
# foo1 #1
|
75
|
+
foo1(:name1) do |f1|
|
76
|
+
# bar1 #1
|
77
|
+
bar1 do |b1|
|
78
|
+
# bar1 #2
|
79
|
+
bar1("name2"){|b2|
|
80
|
+
# b2 S
|
81
|
+
puts b2.inspect
|
82
|
+
# b2 E
|
83
|
+
}
|
84
|
+
# bar2 E
|
85
|
+
end
|
86
|
+
end
|
87
|
+
# foo1 #2 S
|
88
|
+
foo1 :name2, :opt1 => true do
|
89
|
+
replaced_block
|
90
|
+
end
|
91
|
+
# foo1 #2 E
|
92
|
+
EOS
|
93
|
+
end
|
94
|
+
|
95
|
+
it "一部に対して一部を置換" do
|
96
|
+
node1 = @ast.fcall_by_ident(:foo1){|fcall|
|
97
|
+
fcall.arguments.length == 1 && (n = fcall.arguments.first; n.source == ":name1")
|
98
|
+
}
|
99
|
+
new_node1 = YARD::Parser::Ruby::RubyParser.new(node1.source, nil).parse.root
|
100
|
+
node2 = new_node1.fcall_by_ident(:bar1){|fcall|
|
101
|
+
fcall.arguments.length == 1 && (n = fcall.arguments.first; n.source == '"name2"')
|
102
|
+
}
|
103
|
+
fcall2 = YardAstEditable::Fcall.new(node2)
|
104
|
+
fcall2.block.should_not == nil
|
105
|
+
expected = <<EOS
|
106
|
+
foo1(:name1) do |f1|
|
107
|
+
# bar1 #1
|
108
|
+
bar1 do |b1|
|
109
|
+
# bar1 #2
|
110
|
+
bar1("name2"){|b2| 'B2'}
|
111
|
+
# bar2 E
|
112
|
+
end
|
113
|
+
end
|
114
|
+
EOS
|
115
|
+
expected.chomp!
|
116
|
+
new_node1.replace_source(fcall2.block, "{|b2| 'B2'}").should == expected
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "YardAst" do
|
4
|
+
def node(expression)
|
5
|
+
YARD::Parser::Ruby::RubyParser.new(expression, nil).parse.root
|
6
|
+
end
|
7
|
+
|
8
|
+
describe YARD::Parser::Ruby::AstNode do
|
9
|
+
describe Symbol do
|
10
|
+
it "normal style" do
|
11
|
+
node(":symbol1").inspect.should == 's(s(:symbol_literal, s(:symbol, s(:ident, "symbol1"))))'
|
12
|
+
end
|
13
|
+
|
14
|
+
{
|
15
|
+
"with double quotation" => ':"symbol1"',
|
16
|
+
"with single quotation" => ":'symbol1'",
|
17
|
+
}.each do |example_name, expression|
|
18
|
+
it(example_name) do
|
19
|
+
node(expression).inspect.should == 's(s(:dyna_symbol, s(s(:tstring_content, "symbol1"))))'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe String do
|
25
|
+
{
|
26
|
+
"with double quotation" => '"symbol1"',
|
27
|
+
"with single quotation" => "'symbol1'",
|
28
|
+
"with %q{}" => "%q{symbol1}",
|
29
|
+
}.each do |example_name, expression|
|
30
|
+
it(example_name) do
|
31
|
+
node(expression).inspect.should == 's(s(:string_literal, s(:string_content, s(:tstring_content, "symbol1"))))'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "method invocation" do
|
37
|
+
context "without brace" do
|
38
|
+
it "no arguments" do
|
39
|
+
node("foo1").inspect.should == 's(s(:var_ref, s(:ident, "foo1")))'
|
40
|
+
node("foo1")[0].inspect.should == 's(:var_ref, s(:ident, "foo1"))'
|
41
|
+
node("foo1")[0][0].inspect.should == 's(:ident, "foo1")'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Symbol" do
|
45
|
+
node("foo1 :bar1").inspect.should == 's(s(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false)))'
|
46
|
+
node("foo1 :bar1")[0].inspect.should == 's(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false))'
|
47
|
+
node("foo1 :bar1")[0][0].inspect.should == 's(:ident, "foo1")'
|
48
|
+
node("foo1 :bar1")[0][1].inspect.should == 's(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false)'
|
49
|
+
node("foo1 :bar1")[0][1][0].inspect.should == 's(:symbol_literal, s(:symbol, s(:ident, "bar1")))'
|
50
|
+
node("foo1 :bar1")[0][1][0][0].inspect.should == 's(:symbol, s(:ident, "bar1"))'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "Symbol, variable" do
|
54
|
+
node("foo1 :bar1, baz").inspect.should == 's(s(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false)))'
|
55
|
+
node("foo1 :bar1, baz")[0].inspect.should == 's(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false))'
|
56
|
+
node("foo1 :bar1, baz")[0][0].inspect.should == 's(:ident, "foo1")'
|
57
|
+
node("foo1 :bar1, baz")[0][1].inspect.should == 's(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false)'
|
58
|
+
node("foo1 :bar1, baz")[0][1][0].inspect.should == 's(:symbol_literal, s(:symbol, s(:ident, "bar1")))'
|
59
|
+
node("foo1 :bar1, baz")[0][1][1].inspect.should == 's(:var_ref, s(:ident, "baz"))'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "Symbol, option" do
|
63
|
+
node("foo1 :bar1, :baz1 => true").inspect.should == 's(s(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true")))), false)))'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "Symbol, options" do
|
67
|
+
node("foo1 :bar1, :baz1 => true, :baz2 => 1").inspect.should == 's(s(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true"))), s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz2"))), s(:int, "1"))), false)))'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "brace block" do
|
71
|
+
node("foo1{ baz }").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(), s(:brace_block, nil, s(s(:var_ref, s(:ident, "baz"))))))'
|
72
|
+
node("foo1{ baz }")[0].inspect.should == 's(:fcall, s(:ident, "foo1"), s(), s(:brace_block, nil, s(s(:var_ref, s(:ident, "baz")))))'
|
73
|
+
node("foo1{ baz }")[0][0].inspect.should == 's(:ident, "foo1")'
|
74
|
+
node("foo1{ baz }")[0][1].inspect.should == 's()'
|
75
|
+
node("foo1{ baz }")[0][1].empty?.should == true
|
76
|
+
node("foo1{ baz }")[0][2].inspect.should == 's(:brace_block, nil, s(s(:var_ref, s(:ident, "baz"))))'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "do..end block" do
|
80
|
+
node("foo1 do\n baz\nend").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(), s(:do_block, nil, s(s(:var_ref, s(:ident, "baz"))))))'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "Symbol, option and do...end block" do
|
84
|
+
node("foo1 :bar1, :baz1 => true do\n foo1\nend").inspect.should == 's(s(:command, s(:ident, "foo1"), s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true")))), false), s(:do_block, nil, s(s(:var_ref, s(:ident, "foo1"))))))'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with brace" do
|
89
|
+
it "no arguments" do
|
90
|
+
node("foo1()").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, nil)))'
|
91
|
+
node("foo1()")[0].inspect.should == 's(:fcall, s(:ident, "foo1"), s(:arg_paren, nil))'
|
92
|
+
node("foo1()")[0][0].inspect.should == 's(:ident, "foo1")'
|
93
|
+
node("foo1()")[0][1].inspect.should == 's(:arg_paren, nil)'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "Symbol" do
|
97
|
+
node("foo1(:bar1)").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false))))'
|
98
|
+
node("foo1(:bar1)")[0].inspect.should == 's(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false)))'
|
99
|
+
node("foo1(:bar1)")[0][0].inspect.should == 's(:ident, "foo1")'
|
100
|
+
node("foo1(:bar1)")[0][1].inspect.should == 's(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false))'
|
101
|
+
node("foo1(:bar1)")[0][1][0].inspect.should == 's(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), false)'
|
102
|
+
node("foo1(:bar1)")[0][1][0][0].inspect.should == 's(:symbol_literal, s(:symbol, s(:ident, "bar1")))'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "Symbol, variable" do
|
106
|
+
node("foo1(:bar1, baz)").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false))))'
|
107
|
+
node("foo1(:bar1, baz)")[0].inspect.should == 's(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false)))'
|
108
|
+
node("foo1(:bar1, baz)")[0][0].inspect.should == 's(:ident, "foo1")'
|
109
|
+
node("foo1(:bar1, baz)")[0][1].inspect.should == 's(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false))'
|
110
|
+
node("foo1(:bar1, baz)")[0][1][0].inspect.should == 's(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(:var_ref, s(:ident, "baz")), false)'
|
111
|
+
node("foo1(:bar1, baz)")[0][1][0][0].inspect.should == 's(:symbol_literal, s(:symbol, s(:ident, "bar1")))'
|
112
|
+
node("foo1(:bar1, baz)")[0][1][0][1].inspect.should == 's(:var_ref, s(:ident, "baz"))'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "Symbol, option" do
|
116
|
+
node("foo1(:bar1, :baz1 => true)").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true")))), false))))'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "Symbol, options" do
|
120
|
+
node("foo1(:bar1, :baz1 => true, :baz2 => 1)").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true"))), s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz2"))), s(:int, "1"))), false))))'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "brace block" do
|
124
|
+
node("foo1(){ baz }").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, nil), s(:brace_block, nil, s(s(:var_ref, s(:ident, "baz"))))))'
|
125
|
+
node("foo1(){ baz }")[0].inspect.should == 's(:fcall, s(:ident, "foo1"), s(:arg_paren, nil), s(:brace_block, nil, s(s(:var_ref, s(:ident, "baz")))))'
|
126
|
+
node("foo1(){ baz }")[0][0].inspect.should == 's(:ident, "foo1")'
|
127
|
+
node("foo1(){ baz }")[0][1].inspect.should == 's(:arg_paren, nil)'
|
128
|
+
node("foo1(){ baz }")[0][1].empty?.should == false
|
129
|
+
node("foo1(){ baz }")[0][1][0].should == nil
|
130
|
+
node("foo1(){ baz }")[0][2].inspect.should == 's(:brace_block, nil, s(s(:var_ref, s(:ident, "baz"))))'
|
131
|
+
end
|
132
|
+
|
133
|
+
it "do..end block" do
|
134
|
+
node("foo1() do\n baz\nend").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, nil), s(:do_block, nil, s(s(:var_ref, s(:ident, "baz"))))))'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "Symbol, option and do...end block" do
|
138
|
+
node("foo1(:bar1, :baz1 => true) do\n foo1\nend").inspect.should == 's(s(:fcall, s(:ident, "foo1"), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "bar1"))), s(s(:assoc, s(:symbol_literal, s(:symbol, s(:ident, "baz1"))), s(:var_ref, s(:kw, "true")))), false)), s(:do_block, nil, s(s(:var_ref, s(:ident, "foo1"))))))'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{yard_ast_editable}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["akimatter"]
|
12
|
+
s.date = %q{2010-12-04}
|
13
|
+
s.description = %q{yard extension to modify source code by using AST Node}
|
14
|
+
s.email = %q{akm2000@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/yard_ast_editable.rb",
|
28
|
+
"spec/spec_helper.rb",
|
29
|
+
"spec/yard_ast_editable_spec.rb",
|
30
|
+
"spec/yard_ast_spec.rb",
|
31
|
+
"yard_ast_editable.gemspec"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/akm/yard_ast_editable}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{yard extension to modify source code by using AST Node}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/yard_ast_editable_spec.rb",
|
41
|
+
"spec/yard_ast_spec.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<yard>, [">= 0.6.3"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<yard>, [">= 0.6.3"])
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<yard>, [">= 0.6.3"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yard_ast_editable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- akimatter
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-04 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: yard
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
- 3
|
31
|
+
version: 0.6.3
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
version: 2.1.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 0
|
60
|
+
- 0
|
61
|
+
version: 1.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: jeweler
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 5
|
75
|
+
- 1
|
76
|
+
version: 1.5.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rcov
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id005
|
93
|
+
description: yard extension to modify source code by using AST Node
|
94
|
+
email: akm2000@gmail.com
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.rdoc
|
102
|
+
files:
|
103
|
+
- .document
|
104
|
+
- .rspec
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.rdoc
|
108
|
+
- Rakefile
|
109
|
+
- VERSION
|
110
|
+
- lib/yard_ast_editable.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/yard_ast_editable_spec.rb
|
113
|
+
- spec/yard_ast_spec.rb
|
114
|
+
- yard_ast_editable.gemspec
|
115
|
+
has_rdoc: true
|
116
|
+
homepage: http://github.com/akm/yard_ast_editable
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: -3093227647333841452
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.3.7
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: yard extension to modify source code by using AST Node
|
148
|
+
test_files:
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/yard_ast_editable_spec.rb
|
151
|
+
- spec/yard_ast_spec.rb
|