Skip to content

Commit

Permalink
+ Fixes atoms_spec (and thus most of parslet)
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Feb 21, 2011
1 parent 4937ac1 commit 33c29dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/parslet/atoms/base.rb
Expand Up @@ -194,10 +194,13 @@ def flatten(value, named=false) # :nodoc:
end

def flatten_sequence(list) # :nodoc:
list.compact.inject('') { |r, e| # and then merge flat elements
foldl(list.compact) { |r, e| # and then merge flat elements
merge_fold(r, e)
}
end
def foldl(list, &block)
list[1..-1].inject(list.first, &block)
end
def merge_fold(l, r) # :nodoc:
# equal pairs: merge.
if l.class == r.class
Expand All @@ -212,8 +215,8 @@ def merge_fold(l, r) # :nodoc:
# unequal pairs: hoist to same level.

# special case: If one of them is a string, the other is more important
return l if r.class == String
return r if l.class == String
return l if r.respond_to? :to_str
return r if l.respond_to? :to_str

# otherwise just create an array for one of them to live in
return l + [r] if r.class == Hash
Expand Down
2 changes: 1 addition & 1 deletion lib/parslet/atoms/str.rb
Expand Up @@ -26,7 +26,7 @@ def try(source, context) # :nodoc:

# Failures:
return error(source, @error_msgs[:premature]) unless s && s.size==str.size
return error(source, @error_msgs[:failed]+s.inspect, error_pos)
return error(source, @error_msgs[:failed]+s.str.inspect, error_pos)
end

def to_s_inner(prec) # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion spec/parslet/atoms_spec.rb
Expand Up @@ -327,7 +327,7 @@ def src(str); Parslet::Source.new str; end
end

context "(str('a') >> str('ignore') >> str('b')) (no .as(...))" do
it "should return an empty subtree" do
it "should return simply the original string" do
(str('a') >> str('ignore') >> str('b')).
parse('aignoreb').should == 'aignoreb'
end
Expand Down

0 comments on commit 33c29dd

Please sign in to comment.