# New Ticket Created by  David Warring 
# Please include the string:  [perl #117955]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117955 >


Hi There,
I'm noticing some unexpected capture results when I introduce the
conjunctive '&' operator as below:

grammar G {
    rule keyw {\w+}

    rule simple1 { [ <keyw> ] ** 2 }
    rule simple2 { [ <keyw> ] [ <keyw> ] }
    rule conj2 { [ \w+ & <keyw> ] ** 2 }
    rule conj1 { [ <keyw> & \w+ ] [ <keyw> & \w+ ] }
}

for <simple1 simple2 conj1 conj2> -> $rule {
    say "rule: $rule";
    say G.parse("word1 word2", :rule($rule));
}

Output:

rule: simple1
「word1 word2」
 keyw => 「word1」
 keyw => 「word2」

rule: simple2
「word1 word2」
 keyw => 「word1」
 keyw => 「word2」

rule: conj1
「word1 word2」
 keyw => 「word2」

rule: conj2
「word1 word2」
 keyw => 「word2」

Both appear to be fully parse the input. Rules simple1 and simple2 are as I
expected. But conj1 and conj2 appear to be only capturing the last
occurrence of <keyw>.
Hi There,
I'm noticing some unexpected capture results when I introduce the conjunctive '&' operator as below:

grammar G {
    rule keyw {\w+}

    rule simple1 { [ <keyw> ] ** 2 }
    rule simple2 { [ <keyw> ] [ <keyw> ] }
    rule conj2 { [ \w+ & <keyw> ] ** 2 }
    rule conj1 { [ <keyw> & \w+ ] [ <keyw> & \w+ ] }
}

for <simple1 simple2 conj1 conj2> -> $rule {
    say "rule: $rule";
    say G.parse("word1 word2", :rule($rule));
}

Output:

rule: simple1
「word1 word2」
 keyw => 「word1」
 keyw => 「word2」

rule: simple2
「word1 word2」
 keyw => 「word1」
 keyw => 「word2」

rule: conj1
「word1 word2」
 keyw => 「word2」

rule: conj2
「word1 word2」
 keyw => 「word2」

Both appear to be fully parse the input. Rules simple1 and simple2 are as I expected. But conj1 and conj2 appear to be only capturing the last occurrence of <keyw>.

Reply via email to