Kurt Hutchinson writes:
> For specifying in-rule repetitions, why not use the rule modifer we
> already have for specifying whole-rule repetitions; namely, C<:x>. Allow
> :x inside rules like :i and :w, and we get something like this:
>     rx :w/ three m's\:         [:3x        m] /
>     rx :w/ three to five m's\: [:x(3..5)   m] /
>     rx :w/ done at runtime\:   [:x($m..$n) m] /

That's an interesting idea.  But I'd have to agree with your next
paragraph on the issue.

> It seems straightforward to me, but I admit I don't know how difficult
> that would be for parsing/compiling purposes. However, it seems too
> different from :i and :w on some level, to be treated the same.
> 
> So instead of a match modifier, how about adding a special named
> assertion akin to C<before> and C<after> called C<x>, that takes an
> argument:
>     rx :w/ three m's\:        <x(3)      m> /
>     rx :w/ three to five m's: <x(3..5)   m> /
>     rx :w/ done at runtime\:  <x($m..$n) m> /
> 
> Repitition is a kind of assertion, after all, and it seems like it
> should get to play in the same angle-bracket sandbox as the other
> assertions.

Yes, we considered this.  First of all, the "m" there is illegal if
you've got parens.  Once you get the closing paren, you need to get a >
or it's a parse error.

But there's this:

    <x(3..5, 'm')>

The trouble is that it doesn't look in the slightest like a quantifier
anymore.  **{} does, even if it is a big fat ugly one.

> I confess that I've purposely left out a small detail, and I'm sure
> you've all noticed: non-greedy matching. I couldn't come up with a way
> that looked all that nice.

That's okay, none of it looked nice. :-p

> I don't know if putting the C<?> after the argument would even work:
>     rx :w/ non-greedy m's\: <x(3..5)? m> /
> And putting it before the argument (as part of the assertion name?) just
> looks weird:
>     rx :w/ non-greedy m's\: <x?(3..5) m> /

Both of those are illegal syntactically, so no dice.

> So maybe this proposal is a complete no-go because of non-greediness,
> but I thought I'd throw it out there anyway because it seemed to me to
> fit in with assertions rather well, and I like the generalized assertion
> idea.

I am definitely fond of the generalized assertion idea.  I just don't
think it belongs here.  (It certainly doesn't half-belong like it did in
A5: / [foo]<3,5> /.  That's not an assertion!)

Thanks for your suggestions, though.

Luke

Reply via email to