On Tue, Feb 22, 2011 at 7:54 PM, John Mair <jrmair / gmail.com> wrote:
> Why not use Ripper for 1.9 code and RubyParser for 1.8 code?

Existing tools use ParseTree sexps, which are RubyParser sexps. The
toolchain is not complete without a compiler (ruby2ruby + eval). The
1.8 syntax restriction only applies to files containing ASTs which are
actually requested. All other files may be filled with stabby lambdas,
if you like.

Here is the LiveAST readme synopsis with RubyParser:

% ruby synopsis.rb
s(:defn, :default, s(:args), s(:scope, s(:block, s(:str, "hello"))))
s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:str, "foo"))
s(:iter, s(:call, nil, :query, s(:arglist)), nil, s(:str, "bar"))
s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:str, "dynamic"))
s(:defn, :g, s(:args), s(:scope, s(:block, s(:str, "dynamic"))))

Now with Ripper:

% ruby -r live_ast_ripper synopsis.rb
[:def, [:@ident, "default", [4, 6]], [:params, nil, nil, nil, nil,
nil], [:bodystmt, [[:string_literal, [:string_content,
[:@tstring_content, "hello", [5, 5]]]]], nil, nil, nil]]
[:method_add_block, [:method_add_arg, [:fcall, [:@ident, "lambda",
[18, 4]]], []], [:brace_block, nil, [[:string_literal,
[:string_content, [:@tstring_content, "foo", [18, 14]]]]]]]
[:method_add_block, [:method_add_arg, [:fcall, [:@ident, "query", [28,
0]]], []], [:do_block, nil, [[:string_literal, [:string_content,
[:@tstring_content, "bar", [29, 3]]]]]]]
[:method_add_block, [:method_add_arg, [:fcall, [:@ident, "lambda", [1,
0]]], []], [:brace_block, nil, [[:string_literal, [:string_content,
[:@tstring_content, "dynamic", [1, 10]]]]]]]
[:def, [:@ident, "g", [1, 4]], [:params, nil, nil, nil, nil, nil],
[:bodystmt, [[:string_literal, [:string_content, [:@tstring_content,
"dynamic", [1, 9]]]]], nil, nil, nil]]

I'm willing to bet that 4 out of 5 dentists prefer RubyParser. Notice
the distinction being made between {} and do/end for blocks
(brace_block & do_block). Ripper is a more general tool; it's a less
abstract AST. The live_ast_ripper plugin is still available -- it's
just not the default.

JL