Skip to content

Commit

Permalink
Fixed Label match naming bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Nov 17, 2010
1 parent b5326a7 commit ca9def7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/citrus.rb
Expand Up @@ -611,6 +611,11 @@ def embed
def inspect # :nodoc:
to_s
end

def extend_match(match) # :nodoc:
match.names << name if named?
match.extend(extension) if extension
end
end

# A Terminal is a Rule that matches directly on the input stream and may not
Expand Down Expand Up @@ -944,6 +949,11 @@ def exec(input, events=[])
def to_s
label.to_s + ':' + rule.embed
end

def extend_match(match) # :nodoc:
match.names << label
super
end
end

# A Repeat is a Predicate that specifies a minimum and maximum number of times
Expand Down Expand Up @@ -1237,11 +1247,9 @@ def dump_lines(indent=' ') # :nodoc:

private

# Extends this match with the extensions provided by its #rules.
def extend! # :nodoc:
extenders.each do |rule|
self.names << rule.name if rule.named?
extend(rule.extension) if rule.extension
rule.extend_match(self)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/label_test.rb
Expand Up @@ -6,6 +6,16 @@ def test_terminal?
assert_equal(false, rule.terminal?)
end

def test_match
abc = Rule.new('abc')
abc.name = 'abc'
label = Label.new(abc, 'a_label')
label.name = 'label'
match = label.parse('abc')
assert(match)
assert_equal([:abc, :a_label, :label], match.names)
end

def test_to_s
rule = Label.new('a', 'label')
assert_equal('label:"a"', rule.to_s)
Expand Down

0 comments on commit ca9def7

Please sign in to comment.