GW wrote:
> I found something that could be problematic (haven't yet found out if it
> should be a special case) in Synopsis 5. More precisely it is under the
> chapter "Accessing captured subrules" in the test case
> t/regex/from_perl6_rules/capture.t lines 67–71:
> ok(eval(' "bookkeeper" ~~ m/<single> ($/<single>)/ '), 'Named backref',
> :todo<feature>);
> How can the parser know what you mean by $/<single>? Maybe you want $/
> followed by <single> or maybe $/<single>?

I don't know if this is the answer to your particular question, but
these questions are usually answered by "Longest Token Matching" (LTM).
This principle says that every grammar rule that parses the source code
eats up as many characters as possible.

So I think this means here that $/<single> will be parsed as one long
token instead of two separate tokens.

The same rule applies for interpolation in strings:

"my big $house.uc" is parsed as "my big { $house.uc }", ie $house.uc is
taken as one token, even though a valid interpretation would be to
interpolate $house first and then append .uc to that string.

> A rewrite of this to $<single> would solve this specific problem, but
> not situations like: $/<single><sth>. Variants like $/.<single> are also
> ambiguous.
> A solution could be something like like the Perl5 style: ${/<single><sth>}

The Perl 6 solution is that you disambiguate with whitespace if you
don't want to follow the LTM-rule (ie you'd say '$/ <single>' in the regex).

For string interpolation embedded closures ("my big {$house}.uc") can be
used for disambiguation.


Reply via email to