Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
Last active December 16, 2015 18:39
Show Gist options
  • Save RyanScottLewis/5479156 to your computer and use it in GitHub Desktop.
Save RyanScottLewis/5479156 to your computer and use it in GitHub Desktop.
Ripper S-EXP output
class Foo
def self.parse
new.parse
end
def parse
if true
if false
puts "omg" if true
else
puts "wtf" if true
end
else
if true
puts "omg" if false
elsif nil
puts "wtf" unless false
else false
case 22
when 0 .. 2
puts "baby"
when 3 .. 6
puts "little child"
when 7 .. 12
puts "child"
when 13 .. 18
puts "youth"
else
puts "adult"
end
end
end
end
end
[:program,
[[:class,
[:const_ref, [:@const, "Foo", [1, 14]]],
nil,
[:bodystmt,
[[:defs,
[:var_ref, [:@kw, "self", [3, 14]]],
[:@period, ".", [3, 18]],
[:@ident, "parse", [3, 19]],
[:params, nil, nil, nil, nil, nil, nil, nil],
[:bodystmt,
[[:call,
[:vcall, [:@ident, "new", [4, 12]]],
:".",
[:@ident, "parse", [4, 16]]]],
nil,
nil,
nil]],
[:def,
[:@ident, "parse", [7, 14]],
[:params, nil, nil, nil, nil, nil, nil, nil],
[:bodystmt,
[[:if,
[:var_ref, [:@kw, "true", [8, 15]]],
[[:if,
[:var_ref, [:@kw, "false", [9, 17]]],
[[:if_mod,
[:var_ref, [:@kw, "true", [10, 30]]],
[:command,
[:@ident, "puts", [10, 16]],
[:args_add_block,
[[:string_literal,
[:string_content, [:@tstring_content, "omg", [10, 22]]]]],
false]]]],
[:else,
[[:if_mod,
[:var_ref, [:@kw, "true", [12, 30]]],
[:command,
[:@ident, "puts", [12, 16]],
[:args_add_block,
[[:string_literal,
[:string_content, [:@tstring_content, "wtf", [12, 22]]]]],
false]]]]]]],
[:else,
[[:if,
[:var_ref, [:@kw, "true", [15, 17]]],
[[:if_mod,
[:var_ref, [:@kw, "false", [16, 30]]],
[:command,
[:@ident, "puts", [16, 16]],
[:args_add_block,
[[:string_literal,
[:string_content, [:@tstring_content, "omg", [16, 22]]]]],
false]]]],
[:else,
[[:unless_mod,
[:var_ref, [:@kw, "false", [18, 34]]],
[:command,
[:@ident, "puts", [18, 16]],
[:args_add_block,
[[:string_literal,
[:string_content, [:@tstring_content, "wtf", [18, 22]]]]],
false]]]]]]]]]],
nil,
nil,
nil]]],
nil,
nil,
nil]]]]
[
[0] :program,
[1] [
[0] [
[0] :class,
[1] [
[0] :const_ref,
[1] [
[0] :@const,
[1] "Foo",
[2] [
[0] 1,
[1] 14
]
]
],
[2] nil,
[3] [
[0] :bodystmt,
[1] [
[0] [
[0] :defs,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "self",
[2] [
[0] 3,
[1] 14
]
]
],
[2] [
[0] :@period,
[1] ".",
[2] [
[0] 3,
[1] 18
]
],
[3] [
[0] :@ident,
[1] "parse",
[2] [
[0] 3,
[1] 19
]
],
[4] [
[0] :params,
[1] nil,
[2] nil,
[3] nil,
[4] nil,
[5] nil,
[6] nil,
[7] nil
],
[5] [
[0] :bodystmt,
[1] [
[0] [
[0] :call,
[1] [
[0] :vcall,
[1] [
[0] :@ident,
[1] "new",
[2] [
[0] 4,
[1] 12
]
]
],
[2] :".",
[3] [
[0] :@ident,
[1] "parse",
[2] [
[0] 4,
[1] 16
]
]
]
],
[2] nil,
[3] nil,
[4] nil
]
],
[1] [
[0] :def,
[1] [
[0] :@ident,
[1] "parse",
[2] [
[0] 7,
[1] 14
]
],
[2] [
[0] :params,
[1] nil,
[2] nil,
[3] nil,
[4] nil,
[5] nil,
[6] nil,
[7] nil
],
[3] [
[0] :bodystmt,
[1] [
[0] [
[0] :if,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "true",
[2] [
[0] 8,
[1] 15
]
]
],
[2] [
[0] [
[0] :if,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "false",
[2] [
[0] 9,
[1] 17
]
]
],
[2] [
[0] [
[0] :if_mod,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "true",
[2] [
[0] 10,
[1] 30
]
]
],
[2] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 10,
[1] 16
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "omg",
[2] [
[0] 10,
[1] 22
]
]
]
]
],
[2] false
]
]
]
],
[3] [
[0] :else,
[1] [
[0] [
[0] :if_mod,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "true",
[2] [
[0] 12,
[1] 30
]
]
],
[2] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 12,
[1] 16
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "wtf",
[2] [
[0] 12,
[1] 22
]
]
]
]
],
[2] false
]
]
]
]
]
]
],
[3] [
[0] :else,
[1] [
[0] [
[0] :if,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "true",
[2] [
[0] 15,
[1] 17
]
]
],
[2] [
[0] [
[0] :if_mod,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "false",
[2] [
[0] 16,
[1] 30
]
]
],
[2] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 16,
[1] 16
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "omg",
[2] [
[0] 16,
[1] 22
]
]
]
]
],
[2] false
]
]
]
],
[3] [
[0] :elsif,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "nil",
[2] [
[0] 17,
[1] 20
]
]
],
[2] [
[0] [
[0] :unless_mod,
[1] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "false",
[2] [
[0] 18,
[1] 34
]
]
],
[2] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 18,
[1] 16
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "wtf",
[2] [
[0] 18,
[1] 22
]
]
]
]
],
[2] false
]
]
]
],
[3] [
[0] :else,
[1] [
[0] [
[0] :var_ref,
[1] [
[0] :@kw,
[1] "false",
[2] [
[0] 19,
[1] 19
]
]
],
[1] [
[0] :case,
[1] [
[0] :@int,
[1] "22",
[2] [
[0] 20,
[1] 21
]
],
[2] [
[0] :when,
[1] [
[0] [
[0] :dot2,
[1] [
[0] :@int,
[1] "0",
[2] [
[0] 21,
[1] 21
]
],
[2] [
[0] :@int,
[1] "2",
[2] [
[0] 21,
[1] 26
]
]
]
],
[2] [
[0] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 22,
[1] 18
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "baby",
[2] [
[0] 22,
[1] 24
]
]
]
]
],
[2] false
]
]
],
[3] [
[0] :when,
[1] [
[0] [
[0] :dot2,
[1] [
[0] :@int,
[1] "3",
[2] [
[0] 23,
[1] 21
]
],
[2] [
[0] :@int,
[1] "6",
[2] [
[0] 23,
[1] 26
]
]
]
],
[2] [
[0] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 24,
[1] 18
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "little child",
[2] [
[0] 24,
[1] 24
]
]
]
]
],
[2] false
]
]
],
[3] [
[0] :when,
[1] [
[0] [
[0] :dot2,
[1] [
[0] :@int,
[1] "7",
[2] [
[0] 25,
[1] 21
]
],
[2] [
[0] :@int,
[1] "12",
[2] [
[0] 25,
[1] 26
]
]
]
],
[2] [
[0] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 26,
[1] 18
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "child",
[2] [
[0] 26,
[1] 24
]
]
]
]
],
[2] false
]
]
],
[3] [
[0] :when,
[1] [
[0] [
[0] :dot2,
[1] [
[0] :@int,
[1] "13",
[2] [
[0] 27,
[1] 21
]
],
[2] [
[0] :@int,
[1] "18",
[2] [
[0] 27,
[1] 27
]
]
]
],
[2] [
[0] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 28,
[1] 18
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "youth",
[2] [
[0] 28,
[1] 24
]
]
]
]
],
[2] false
]
]
],
[3] [
[0] :else,
[1] [
[0] [
[0] :command,
[1] [
[0] :@ident,
[1] "puts",
[2] [
[0] 30,
[1] 18
]
],
[2] [
[0] :args_add_block,
[1] [
[0] [
[0] :string_literal,
[1] [
[0] :string_content,
[1] [
[0] :@tstring_content,
[1] "adult",
[2] [
[0] 30,
[1] 24
]
]
]
]
],
[2] false
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
],
[2] nil,
[3] nil,
[4] nil
]
]
],
[2] nil,
[3] nil,
[4] nil
]
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment