Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Zero-day rules implementation status in Pugs

0 views
Skip to first unread message

Autrijus Tang

unread,
May 9, 2005, 1:36:39 PM5/9/05
to Damian Conway, perl6-language, perl6-c...@perl.org
On Mon, May 09, 2005 at 10:51:53PM +1000, Damian Conway wrote:
> Autrijus wrote:
>
> >/me eagerly awaits new revelation from Damian...
>
> Be careful what you wish for. Here's draft zero. ;-)

...and here is my status report of the Zero-Day exploit, err,
implementation, in Pugs. :-)

Note that the output from Pugs's interactive command line is in
.perl format. Patrick++ for designing a nicely designed PGE API!

> =head2 Match objects

~~ returns match object:

pugs> true(1 ~~ /1/)
bool::true
pugs> true(1 ~~ /2/)
bool::false

$/ gets assigned:

pugs> 1 ~~ /1/; true $/
bool::true
pugs> 1 ~~ /2/; true $/
bool::false

Match object can take .from, .to and .matches methods:

pugs> 1 ~~ /1/; ($/.from, $/.to, $/.matches)
(0, 1, ())

> =head2 Match results

Failed match:

pugs> "bard" ~~ /food/; (?$/, +$/, ~$/)
(bool::false, 0.0, '')

Successful match:

pugs> "bard" ~~ /(ba) $<x> := (rd)/; (?$/, +$/, ~$/, ~$/[0], ~$/<x>)
(bool::true, 1.0, 'bard', 'ba', 'rd')

> =head2 Subpattern captures

Positional captures:

pugs> 42 ~~ /(.)/; (~$/[0], ~$1, ~$/<1>, ~$<1>)
('4', '4', '4', '4')

Optional captures:

pugs> 42 ~~ /(50)?/; (?$/[0], ?$1, ?$/<1>, ?$<1>)
(bool::false, bool::false, bool::false, bool::false)

> =head2 Nested subpattern captures

pugs> 42 ~~ /(.(.))/; ~$/[0][0]
'2'

> =head2 Quantified subpattern captures

pugs> 42 ~~ /(.)*/; ~$/[0][0]
'4'

> =head2 Indirectly quantified subpattern captures

pugs> 42 ~~ /[4 (.)]*/; ~$/[0][0]
'2'

> =head2 Subpattern numbering

pugs> 42 ~~ /(50) | (42)/; ~$1
'42'

> =head2 Subrule captures

This should work -- but PGE does not yet have any built-in subrules,
and only the <ident> is given in examples. Is there a list for all
builtin (global) subrules?

> =head2 Aliasing

pugs> 42 ~~ /$<match> := (..)/; ~$<match>
'42'

pugs> 42 ~~ /$99 := (..)/; ~$99
'42'

Thanks,
/Autrijus/

Patrick R. Michaud

unread,
May 11, 2005, 12:10:48 PM5/11/05
to perl6-c...@perl.org, perl6-i...@perl.org
On Wed, May 11, 2005 at 08:30:42AM -0700, Larry Wall wrote:
>
> Let's go 0-based and make $0 =:= $/[0] so that $/[] is all the parens.

As Decreed on perl6-language, henceforth PGE shall be using
$0, $1, $2, ... for subpattern captures and aliases into the
match object's array.

Thus It has been Made So (r8062), and there is Great Rejoicing and
Celebration throughout the Lands.

Pm

0 new messages