Am 27.04.2010 06:31, schrieb St├ęphane Payrard:
When doing an analyse of a sample parse tree, I note that it is
cluttered by the reduction of optional subrules
to  generate a zero length parse subtree. That is, rules with a '?'
quantifier matching zero time.
Suppressing such matching rules from the parse tree would make it
easier to read.
Additionnally, the actions associated with such a quantified rule
matching once would not necessitate a trailing [0].

   my $twigil := $<twigil>  ?? ~$<twigil>[0] !! '';

  would read

   my $twigil := $<twigil>  ?? ~$<twigil>  !! '';

... end even

     my $twigil = $<twigil> // '';

But it raises other questions that need answering.

Currently the ? quantifier is just syntactic sugar for the general quantifier ** 0..1.
Would that behave the same?
Are you proposing that all quantifiers that match zero times should not appear in the parse tree? Then <twigil>+ could either lead to no capture at all, a single value or a list - not very nice.
Or rather special-casing the 0..1 quantifier?

There's also another problem with your approach: If you have
in your regex, and it matches the empty string, it is still a successful match - yet with your proposal, it's impossible to distinguis a successful zero-width match from an unsuccessful match (which can happen in alternations).


Reply via email to