Front page | perl.perl6.language |
Postings from July 2006
Re: Using Rules Today
Thread Previous
|
Thread Next
From:
Flavio S. Glock
Date:
July 7, 2006 14:09
Subject:
Re: Using Rules Today
Message ID:
aa47605d0607071409w55d9a21dg3d7debe899de863b@mail.gmail.com
2006/7/5, Joshua Gatcomb <joshua.gatcomb@gmail.com>:
>
> I have not had a chance to look at Flavio's links yet. Since no one who
> actually knows rules seemed to be inspired to write an example for me - I
> will *eventually* figure it out on my own and post back to the list as an
> FYI.
Here is a simple one that handles '+' and '*' - it could be simplified
a bit, but this one works for me:
---
use Data::Dumper;
use strict;
use Pugs::Compiler::Token;
use Pugs::Runtime::Match::Ratchet;
use base 'Pugs::Grammar::Base';
Pugs::Compiler::Token->install( 'mul','
(<alnum>+)
[ \\* <mul> { return ( $/[0]()*$/{mul}() ) }
| <\'\'>
]
' );
Pugs::Compiler::Token->install( 'sum','
<mul>
[ \\+ <sum> { return $/{mul}()+$/{sum}() }
| <\'\'> { return $/{mul}() }
]
' );
my $s = shift;
my $match = main->sum( $s );
print $match->();
---
- Flavio S. Glock
Thread Previous
|
Thread Next