Skip to content

Commit

Permalink
Handle BEGIN and END blocks properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Feb 7, 2014
1 parent 8bf0a3f commit da15cec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/ripper_ruby_parser/sexp_processor.rb
Expand Up @@ -129,6 +129,16 @@ def process_comment exp
sexp
end

def process_BEGIN exp
_, body = exp.shift 2
s(:iter, s(:preexe), s(:args), *map_body(body))
end

def process_END exp
_, body = exp.shift 2
s(:iter, s(:postexe), s(:args), *map_body(body))
end

# number literals
def process_at_int exp
make_literal(exp) {|val| Integer(val) }
Expand Down
14 changes: 14 additions & 0 deletions test/unit/parser_test.rb
Expand Up @@ -685,6 +685,20 @@
end
end

describe "for the END keyword" do
it "converts to a :postexe iterator" do
"END { foo }".
must_be_parsed_as s(:iter, s(:postexe), s(:args), s(:call, nil, :foo))
end
end

describe "for the BEGIN keyword" do
it "converts to a :preexe iterator" do
"BEGIN { foo }".
must_be_parsed_as s(:iter, s(:preexe), s(:args), s(:call, nil, :foo))
end
end

describe "for constant lookups" do
it "works when explicitely starting from the root namespace" do
"::Foo".
Expand Down

0 comments on commit da15cec

Please sign in to comment.