On Wed Jun 03 06:08:46 2009, haakonsk wrote:
> This doesn't work:
>   grammar A { rule TOP { 'a' ' b' {*} } }; my $m = A.parse('a b'); say $/;
> Result: Empty string
> Expected result: "a b"

Rakudo is correct here.

Whitespace in rules is metasyntactic -- it gets replaced by <.ws>.
So, the above rule is really equivalent to

    token { <.ws> 'a' <.ws> ' b' <.ws> {*} <.ws> }

The <.ws> that is inserted between the 'a' and ' b' thus consumes all of
the whitespace, leaving nothing for the leading space of ' b' to match.

> And this doesn't work:
>   grammar A { rule TOP { 'a' <blank> 'b' {*} } }; my $m = A.parse('a
> b'); say $/;
> Result: Empty string
> Expected result: "a b"

Same issue here -- the whitespace after 'a' eats up any whitespace that
might be consumed by the <blank>.

You likely want either C<regex> or C<token> here instead of C<rule>.

Closing ticket, thanks!

Pm


Reply via email to