Last active
December 21, 2015 23:18
-
-
Save jimweirich/6381113 to your computer and use it in GitHub Desktop.
Differences between JRuby and Ruby2 Ripper output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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