live_ast_ruby_parser 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  = live_ast_ruby_parser ChangeLog
3
3
 
4
+ == Version 0.6.0
5
+
6
+ * added new testing API methods
7
+ * fixed a recursion issue
8
+ * optimized
9
+
4
10
  == Version 0.5.2
5
11
 
6
12
  * doc fixes
data/MANIFEST CHANGED
@@ -1,8 +1,10 @@
1
1
  CHANGES.rdoc
2
2
  MANIFEST
3
+ MANIFEST
3
4
  README.rdoc
4
5
  Rakefile
5
6
  devel/jumpstart.rb
6
7
  lib/live_ast_ruby_parser.rb
7
- lib/live_ast_ruby_parser/test_forms.rb
8
- lib/live_ast_ruby_parser/unparser.rb
8
+ lib/live_ast_ruby_parser/test.rb
9
+ lib/live_ast_ruby_parser/unparser.rb
10
+ lib/live_ast_ruby_parser/version.rb
data/Rakefile CHANGED
@@ -1,18 +1,21 @@
1
1
  require_relative 'devel/jumpstart'
2
2
 
3
3
  Jumpstart.new "live_ast_ruby_parser" do |s|
4
+ s.camel_name = "LiveASTRubyParser"
4
5
  s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
5
6
  s.github_user = "quix"
6
- s.version = "0.5.2"
7
7
  s.description = s.summary
8
-
9
- # my code compensates for a ruby_parser bug; make this equal for now
10
- s.dependencies << ["ruby_parser", "= 2.0.6"]
11
-
12
- s.dependencies << ["ruby2ruby"]
8
+ s.dependencies = [
9
+ #
10
+ # my code compensates for a ruby_parser bug; make this equal for now
11
+ #
12
+ ["ruby_parser", "= 2.0.6"],
13
+ ["ruby2ruby", ">= 0"],
14
+ ]
13
15
  end
14
16
 
15
- # testing done inside live_ast
16
17
  task :test do
18
+ puts "Testing is done with the LiveAST test suite."
17
19
  end
18
20
 
21
+ task :default => :test
@@ -1,18 +1,14 @@
1
1
  require 'ruby_parser'
2
- require 'sexp_processor'
3
2
  require 'live_ast/base'
4
3
 
5
- class LiveASTRubyParser < SexpProcessor
6
- #
7
- # Whether this is Ryan Davis' unified sexp format.
8
- #
9
- def self.unified?
10
- true
11
- end
4
+ class LiveASTRubyParser
5
+ VERSION = "0.6.0"
12
6
 
13
7
  #
14
- # Returns a line --> sexp hash where sexp corresponds to the
15
- # method or block defined at the given line.
8
+ # Returns a line-to-sexp hash where sexp corresponds to the method
9
+ # or block defined at the given line.
10
+ #
11
+ # This method is the only requirement of a LiveAST parser plugin.
16
12
  #
17
13
  def parse(source)
18
14
  @defs = {}
@@ -20,36 +16,23 @@ class LiveASTRubyParser < SexpProcessor
20
16
  @defs
21
17
  end
22
18
 
23
- def process_defn(sexp)
24
- result = Sexp.new
25
- result << sexp.shift
26
- result << sexp.shift
27
- result << process(sexp.shift)
28
- result << process(sexp.shift)
29
-
30
- store_sexp(result, sexp.line)
31
- s()
32
- end
33
-
34
- def process_iter(sexp)
35
- line = sexp[1].line
36
-
37
- result = Sexp.new
38
- result << sexp.shift
39
- result << process(sexp.shift)
40
- result << process(sexp.shift)
41
- result << process(sexp.shift)
42
-
43
- #
44
- # ruby_parser bug: a method without args attached to a
45
- # multi-line block reports the wrong line. workaround.
46
- #
47
- if result[1][3].size == 1
48
- line = sexp.line
19
+ def process(sexp)
20
+ case sexp.first
21
+ when :defn
22
+ store_sexp(sexp, sexp.line)
23
+ when :iter
24
+ #
25
+ # ruby_parser bug: a method without args attached to a
26
+ # multi-line block reports the wrong line. workaround.
27
+ #
28
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=28940&group_id=439&atid=1778
29
+ #
30
+ store_sexp(sexp, sexp[1][3].size == 1 ? sexp.line : sexp[1].line)
49
31
  end
50
32
 
51
- store_sexp(result, line)
52
- s()
33
+ sexp.each do |elem|
34
+ process(elem) if elem.is_a? Sexp
35
+ end
53
36
  end
54
37
 
55
38
  def store_sexp(sexp, line)
@@ -57,7 +40,7 @@ class LiveASTRubyParser < SexpProcessor
57
40
  end
58
41
  end
59
42
 
60
- LiveASTRubyParser.autoload :Unparser, 'live_ast_ruby_parser/unparser'
61
- LiveASTRubyParser.autoload :TestForms, 'live_ast_ruby_parser/test_forms'
43
+ LiveASTRubyParser.autoload :Unparser, 'live_ast_ruby_parser/unparser'
44
+ LiveASTRubyParser.autoload :Test, 'live_ast_ruby_parser/test'
62
45
 
63
46
  LiveAST.parser = LiveASTRubyParser
@@ -1,6 +1,24 @@
1
1
 
2
- # For testing with LiveAST.
3
- module LiveASTRubyParser::TestForms
2
+ #
3
+ # Used by the LiveAST test suite.
4
+ #
5
+ module LiveASTRubyParser::Test
6
+ class << self
7
+ #
8
+ # Whether this is Ryan Davis's unified sexp format.
9
+ #
10
+ def unified_sexp?
11
+ true
12
+ end
13
+
14
+ #
15
+ # Whether the unparser output matches that of ruby2ruby.
16
+ #
17
+ def unparser_matches_ruby2ruby?
18
+ true
19
+ end
20
+ end
21
+
4
22
  #
5
23
  # no_arg_def(:f, "A#f") returns the ast of
6
24
  #
@@ -115,4 +133,42 @@ module LiveASTRubyParser::TestForms
115
133
  s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
116
134
  s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
117
135
  end
136
+
137
+ #
138
+ # nested_lambdas("foo") returns the ast of
139
+ #
140
+ # lambda {
141
+ # lambda {
142
+ # "foo"
143
+ # }
144
+ # }
145
+ #
146
+ def nested_lambdas(str)
147
+ s(:iter,
148
+ s(:call, nil, :lambda, s(:arglist)),
149
+ nil,
150
+ s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:str, str)))
151
+ end
152
+
153
+ # nested_defs(:f, :g, "foo") returns the ast of
154
+ #
155
+ # def f
156
+ # Class.new do
157
+ # def g
158
+ # "foo"
159
+ # end
160
+ # end
161
+ # end
162
+ #
163
+ def nested_defs(u, v, str)
164
+ s(:defn,
165
+ u,
166
+ s(:args),
167
+ s(:scope,
168
+ s(:block,
169
+ s(:iter,
170
+ s(:call, s(:const, :Class), :new, s(:arglist)),
171
+ nil,
172
+ s(:defn, v, s(:args), s(:scope, s(:block, s(:str, str))))))))
173
+ end
118
174
  end
@@ -4,15 +4,10 @@ require 'ruby2ruby'
4
4
  # Used by +to_ruby+ in LiveAST.
5
5
  #
6
6
  module LiveASTRubyParser::Unparser
7
- class << self
8
- # Whether the unparsed code matches ruby2ruby output.
9
- def ruby2ruby?
10
- true
11
- end
12
-
13
- # Return a ruby source string which reflects the given AST.
14
- def unparse(sexp)
15
- Ruby2Ruby.new.process(sexp)
16
- end
7
+ #
8
+ # Return a ruby source string which reflects the given AST.
9
+ #
10
+ def self.unparse(sexp)
11
+ Ruby2Ruby.new.process(sexp)
17
12
  end
18
13
  end
@@ -0,0 +1,3 @@
1
+ class LiveASTRubyParser
2
+ VERSION = "0.6.0"
3
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: live_ast_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.2
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James M. Lawrence
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-24 00:00:00 -05:00
13
+ date: 2011-02-26 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -46,13 +46,14 @@ extra_rdoc_files:
46
46
  - README.rdoc
47
47
  files:
48
48
  - CHANGES.rdoc
49
+ - MANIFEST
49
50
  - README.rdoc
50
51
  - Rakefile
51
52
  - devel/jumpstart.rb
52
53
  - lib/live_ast_ruby_parser.rb
53
- - lib/live_ast_ruby_parser/test_forms.rb
54
+ - lib/live_ast_ruby_parser/test.rb
54
55
  - lib/live_ast_ruby_parser/unparser.rb
55
- - MANIFEST
56
+ - lib/live_ast_ruby_parser/version.rb
56
57
  has_rdoc: true
57
58
  homepage: http://quix.github.com/live_ast_ruby_parser
58
59
  licenses: []