Me writes:
: > : Would something like these DWIM?
: > : 
: > :     # match pat1 _ pat2 and capture pat2 match:
: > :     / pat1 { ($foo) = / pat2 / } /
: > 
: > Yes
: 
: So a match in a closure starts where the outer match
: was. Simple enough.
: 
: Will:
: 
:     # match pat1 _ pat2 _ pat3 and capture pat2 match:
:     / pat1 { ($foo) = / pat2 / } pat3 /
: 
: work?

As long as they're all working off of the same regex state, I
don't see why not.  Except that you'd better have a () in
pat2 to capture something, if we keep the same rules as Perl 5.

: > I don't think the return of the closure will be interpreted as
: > [a string to be matched or a boolean success indicator or
: > indeed anything, at least not something that the regex
: > pays attention to]. Closures will be used for side effects,
: > and I'd hate to see a lot of closures ending in a cryptic C<0;>.
: 
: Right.
: 
: Here's a thought, no need to respond just yet:
: Perhaps the regex could look to see if the return
: value has one of a set of properties. If it does not,
: the regex ignores the return value. Otherwise it
: uses the value in accord with the property:
: 
:     # match pat1 _ 'foo bar':
:     / pat1 { 'foo bar' is pat } /
: 
: Not exactly a compelling example, but the point is
: this might be an appropriate way for closure return
: values to participate in regex matching operation.

I don't see why you can't just use $('foo bar') for that.  Or
<$('foo bar')> if you really want a pattern and not a string.

: Aiui, one has regular perl code (not regex) read
: access to what is *matched by* a parens, but not
: write access to the *matching of* a parens.
: 
: So, one can do:
: 
:     / pat1 ( pat2 ) { $foo = $-1 } /
: 
: to read the value, but not
: 
:     # made up, no thought applied, syntax
:     # match pat1 _ pat2 _ pat2
:     / pat1 { .match 2 } ( pat2 )  /
: 
: where .match is followed by an expression that
: applies some control to the next parens. I'm out
: of my depth here, but can you see what I'm trying
: to get to? To see how far one can have closures,
: and hence regular perl syntax, take on regex
: control duties.

The entire state of the regex match is potentially available via the
topic object.  The only question is what the object is willing to
let you modify (and whether there's a better syntax already).

To answer the deeper question, yes, it's probably possible to run the
entire control structure using nothing but closures.  We could also
change Perl's syntax to use nothing but parens, but we're not gonna.  :-)

Larry

Reply via email to