Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Differences between JRuby and Ruby2 Ripper output
SOURCE: defined?(a)
RESULT:
[:program, [:stmts_add, [:stmts_new], [:defined, [:@rparen, ")", [1, 10]]]]]
SOURCE: "my name is #{name}"
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:string_literal,
[:string_add,
[:string_add,
[:string_content],
[:@tstring_content, "my name is ", [1, 1]]],
[:string_embexpr, [:@rbrace, "}", [1, 18]]]]]]]
SOURCE: /#{name}/
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:regexp_literal,
[:regexp_add, [:regexp_new], [:string_embexpr, [:@rbrace, "}", [1, 7]]]],
[:@regexp_end, "/", [1, 8]]]]]
SOURCE: ->() { }
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:lambda,
[:params, nil, nil, nil, nil, nil],
[:stmts_add, [:stmts_new], [:void_stmt]]]]]
SOURCE: a >= 3
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:binary, [:vcall, [:@ident, "a", [1, 0]]], :<=, [:@int, "3", [1, 5]]]]]
require 'ripper'
require 'pp'
def show(source)
sexp = Ripper::SexpBuilder.new(source).parse
puts "SOURCE: #{source}"
puts "RESULT:"
pp sexp
puts
end
show "defined?(a)"
show '"my name is #{name}"'
show '/#{name}/'
show "->() { }"
show "a >= 3"
SOURCE: defined?(a)
RESULT:
[:program,
[:stmts_add, [:stmts_new], [:defined, [:vcall, [:@ident, "a", [1, 9]]]]]]
SOURCE: "my name is #{name}"
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:string_literal,
[:string_add,
[:string_add,
[:string_content],
[:@tstring_content, "my name is ", [1, 1]]],
[:string_embexpr,
[:stmts_add, [:stmts_new], [:vcall, [:@ident, "name", [1, 14]]]]]]]]]
SOURCE: /#{name}/
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:regexp_literal,
[:regexp_add,
[:regexp_new],
[:string_embexpr,
[:stmts_add, [:stmts_new], [:vcall, [:@ident, "name", [1, 3]]]]]],
[:@regexp_end, "/", [1, 8]]]]]
SOURCE: ->() { }
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:lambda,
[:paren, [:params, nil, nil, nil, nil, nil, nil, nil]],
[:stmts_add, [:stmts_new], [:void_stmt]]]]]
SOURCE: a >= 3
RESULT:
[:program,
[:stmts_add,
[:stmts_new],
[:binary, [:vcall, [:@ident, "a", [1, 0]]], :>=, [:@int, "3", [1, 5]]]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.