Last active
December 15, 2020 11:23
-
-
Save achikin/804c046c55265dfb5f372349288cefeb to your computer and use it in GitHub Desktop.
Ruby AST
This file contains 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
def somefn(x, y) | |
x + y | |
end | |
somefn(1,2) |
This file contains 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
(defn somefn [x y] | |
(+ x y)) | |
(somefn 1 2) |
This file contains 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
(begin | |
(def :somefn | |
(args | |
(arg :x) | |
(arg :y)) | |
(send | |
(lvar :x) :+ | |
(lvar :y))) | |
(send nil :somefn | |
(int 1) | |
(int 2))) |
This file contains 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 '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