Created
August 30, 2012 18:39
-
-
Save JacobNinja/3537082 to your computer and use it in GitHub Desktop.
Rubinius parser confusion
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
# Here's the code being evaluated | |
# rubinius-2.0.0dev | |
html_class = build_class("") {|c| c << "required" if required } | |
# => "required" | |
### FIRST EXAMPLE | |
# Symbolic expression tree with no arguments to build_class | |
'html_class = build_class() {|c| c << "required" if required }'.to_sexp | |
# => [:lasgn, :html_class, | |
# [:iter, | |
# [:call, nil, :build_class, [:arglist]], | |
# [:lasgn, :c], [:if, [:call, nil, :required, nil], [:call, [:lvar, :c], :<<, [:arglist, [:str, "required"]]], nil]]] | |
# The block becomes the second argument of `iter` like expected | |
### SECOND EXAMPLE | |
# Symbolic expression tree with 1 argument to build_class | |
'html_class = build_class("") {|c| c << "required" if required }'.to_sexp | |
# => [:lasgn, :html_class, | |
# [:iter, | |
# [:call, nil, :build_class, [:arglist, [:str, ""], [:iter, [:lasgn, :c], [:if, [:call, nil, :required, nil], [:call, [:lvar, :c], :<<, [:arglist, [:str, "required"]]], nil]]]], | |
# [:lasgn, :c], [:if, [:call, nil, :required, nil], [:call, [:lvar, :c], :<<, [:arglist, [:str, "required"]]], nil]]] | |
# Why is the block repeated in the second example? It becomes a parameter to `arglist` and `iter` with the presence of a method argument |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the issue in the #to_sexp output. I'll look into using the AST nodes instead