Skip to content

Instantly share code, notes, and snippets.

@achikin
Last active December 15, 2020 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achikin/804c046c55265dfb5f372349288cefeb to your computer and use it in GitHub Desktop.
Save achikin/804c046c55265dfb5f372349288cefeb to your computer and use it in GitHub Desktop.
Ruby AST
def somefn(x, y)
x + y
end
somefn(1,2)
(defn somefn [x y]
(+ x y))
(somefn 1 2)
(begin
(def :somefn
(args
(arg :x)
(arg :y))
(send
(lvar :x) :+
(lvar :y)))
(send nil :somefn
(int 1)
(int 2)))
require 'parser/current'
code = File.read('ast-example.rb')
parsed_code = Parser::CurrentRuby.parse(code)
puts parsed_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment