I suspect the rule:
rule other { . }
means that in
$input = '~i << to
match (although will also end up matching the space after the "i" in
the text string, since white spaces are no longer significant). Or try just
changing the rule to be a token and leave the others as rules.
Phrased another way, the rule as written now is roughly equivalent to
writing
token other { . \s* }
which will match a word character only when it's not immediately followed by
another word character.
Pm
On Sun, Sep 23, 2018 at 08:01:31PM -0400, yary wrote:
> Let's see.
>
> If you have my $input = '~i o<<<', then matches.
>
> 'rule' turns on :sigspace. If you use 'token' instead of 'rule' then
> matches.
>
> I don't quite have the full picture of what's happening.
>
> -y
>
> On Sun, Sep 23, 2018 at 7:07 PM, Mark Carter wrote:
>
> > My grammar doesn't seem to match the 'other' rule. What's wrong with it?
> >
> > grammar Weave {
> > token TOP { * }
> > rule el { | | }
> > rule lt { '<' }
> > rule tilde { '~' \S+ }
> > rule other { . }
> > }
> >
> > class Weaver {
> > has Str $.outstr;
> >
> > method TOP ($/) { make $ ; put("top called") ; put($) }
> > method el($/) { put($/) }
> > method tilde ($/) { say 'tilde called' }
> > method lt($/) { make '' ; put(''); $!outstr ~= 'X' }
> > method other ($/) { $!outstr ~= '.'; say 'other called'; put('.');
> > }
> >
> > }
> >
> > $input = '~i << > my $w = Weaver.new();
> > Weave.parse($input, :actions($w));
> > say $w.outstr; # outputs XXX
> >
> > It never once says 'other called'. It seems to be matching the '<' signs
> > OK, and I think the '~' is OK, too. It's just any other token that it's not
> > matching.
> >