From ca9def776cce885d6e7f1cf63c214bfd16633495 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 16 Nov 2010 22:55:35 -0800 Subject: [PATCH] Fixed Label match naming bug --- lib/citrus.rb | 14 +++++++++++--- test/label_test.rb | 10 ++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/citrus.rb b/lib/citrus.rb index 0cde2d0..703223e 100644 --- a/lib/citrus.rb +++ b/lib/citrus.rb @@ -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 @@ -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 @@ -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 diff --git a/test/label_test.rb b/test/label_test.rb index a860272..ba2b0fd 100644 --- a/test/label_test.rb +++ b/test/label_test.rb @@ -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)