Skip to content

Commit

Permalink
Start handling simplification of interpolated strings and regexps.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Apr 4, 2012
1 parent 7cfd3b9 commit 95878e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ripper_ruby_parser/sexp_handlers/literals.rb
Expand Up @@ -48,6 +48,9 @@ def process_regexp_literal exp

if rest.empty?
s(:lit, Regexp.new(string, numflags))
elsif rest.size == 1 and rest[0].sexp_type == :evstr and rest[0][1].sexp_type == :str
string += rest[0][1][1]
s(:lit, Regexp.new(string, numflags))
else
rest << numflags if numflags > 0
sexp_type = if flags =~ /o/
Expand Down
6 changes: 6 additions & 0 deletions test/unit/parser_literals_test.rb
Expand Up @@ -43,6 +43,12 @@
s(:evstr,
s(:call, nil, :bar, s(:arglist))), 16)
end

describe "containing just a literal string" do
it "performs the interpolation when it is at the end" do
'/foo#{"bar"}/'.must_be_parsed_as s(:lit, /foobar/)
end
end
end
end
end
Expand Down

0 comments on commit 95878e0

Please sign in to comment.