Permalink
Browse files

fix transforming of string literal with balanced parens

  • Loading branch information...
1 parent 60d4a62 commit ee35839eb10c05cc08823d77b689473f85f93b09 @yob committed May 26, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 foo.rb
View
11 foo.rb
@@ -48,10 +48,10 @@ class PdfTransform < Parslet::Transform
rule(:string_literal => subtree(:value)) {
if value.is_a?(String)
value
- elsif value.is_a?(Array) && value.empty?
- ""
+ elsif value.is_a?(Array) && value.size > 0
+ PdfTransform.new.apply(value.first)
else
- PdfTransform.new.apply(value)
+ ""
end
}
@@ -113,6 +113,11 @@ def parse_token
transform.apply(ast).should == [ "" ]
end
+ it "transforms a nested literal string" do
+ ast = [{ :string_literal => [{:string_literal => "abc"}] }]
+ transform.apply(ast).should == [ "abc" ]
+ end
+
it "transforms a hex string without captials" do
str = [{ :string_hex => "00ffab"}]
transform.apply(str).should == [ "\x00\xff\xab" ]

0 comments on commit ee35839

Please sign in to comment.