Skip to content

Instantly share code, notes, and snippets.

@prathamesh-sonpatki
Created December 17, 2013 18:19
Show Gist options
  • Save prathamesh-sonpatki/8009948 to your computer and use it in GitHub Desktop.
Save prathamesh-sonpatki/8009948 to your computer and use it in GitHub Desktop.
require 'ripper'
require 'pp'
code =<<STR
10.times do |n|
puts n
end
STR
puts code
pp Ripper.lex code
# 10.times do |n|
# puts n
# end
# [[[1, 0], :on_int, "10"],
# [[1, 2], :on_period, "."],
# [[1, 3], :on_ident, "times"],
# [[1, 8], :on_sp, " "],
# [[1, 9], :on_kw, "do"],
# [[1, 11], :on_sp, " "],
# [[1, 12], :on_op, "|"],
# [[1, 13], :on_ident, "n"],
# [[1, 14], :on_op, "|"],
# [[1, 15], :on_ignored_nl, "\n"],
# [[2, 0], :on_sp, " "],
# [[2, 2], :on_ident, "puts"],
# [[2, 6], :on_sp, " "],
# [[2, 7], :on_ident, "n"],
# [[2, 8], :on_nl, "\n"],
# [[3, 0], :on_kw, "end"],
# [[3, 3], :on_nl, "\n"]]
@prathamesh-sonpatki
Copy link
Author

Why ruby has two types of new lines? on_ignored_nl and on_nl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment