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/
pgp8PlSCL64gJ.pgp
Description: PGP signature
