use 5.006001; use strict; use warnings; package Pugs::Compiler::Rule; our $VERSION = '0.35'; use base 'Pugs::Compiler::Regex'; sub compile { my ( $class, $rule_source, $param ) = @_; $param = ref $param ? { %$param } : {}; $param->{ratchet} = 1 unless exists $param->{ratchet}; $param->{sigspace} = 1 unless exists $param->{sigspace} || exists $param->{s}; $class->SUPER::compile( $rule_source, $param ); } 1; __END__ =head1 NAME Pugs::Compiler::Rule - Compiler for Perl 6 regexes =head1 VERSION This document describes Pugs::Compiler::Rule 0.28 released on 31 Oct, 2007. =head1 SYNOPSIS Un-named rules are objects: use Pugs::Compiler::Rule; my $rule = Pugs::Compiler::Rule->compile( '((.).).' ); my $match = $rule->match( 'abc' ); if ($match) { # true print $match; # "abc" print $match->from; # 0 print $match->to; # 3 print $match->[0]; # "ab" print $match->[0][0]; # "a" } Named rules are methods in a Grammar: package MyGrammar; use Pugs::Compiler::Rule; use base 'Pugs::Grammar::Base'; Pugs::Compiler::Rule->install( rule => '((.).).' ); my $match = MyGrammar->rule( 'abc' ); Rules may have parameters: $grammar->install(subrule => $source, { signature => $sig } ); $grammar->install(rule => q{ }); where C<$grammar> is normally a Perl 5 package. =head1 DESCRIPTION This module provides an pure Perl 5 implementation for Perl 6 regexes, which does not depend on the Haskell Pugs. It is a front-end to several other modules: Front-end Modules =over 4 =item * L compiles Perl 6 grammars to Perl 5. =item * L compiles Perl 6 rules to Perl 5. =item * L compiles Perl 6 tokens to Perl 5. =item * L compiles Perl 6 regexes to Perl 5. =item * L wraps Perl 5 regexes to return a B object. =back Runtime Classes =over 4 =item * L provides the runtime engine for Rules. =item * L represents a B object. =item * L represents a B class / object. =back Grammars =over 4 =item * L parses the Rules syntax. =item * L is the base Grammar: , . =back Code Emitters =over 4 =item * L converts parsed Rules to Perl 5 code. =item * L converts parsed :ratchet Rules to Perl 5 code. =item * L converts parsed grammars to Perl 5 code. =back =head1 INHERITANCE Pugs::Compiler::Rule isa Pugs::Compiler::Regex =head1 METHODS This class (i.e. L) is a subclass of L and thus owns all the methods of its base class. See L for the detailed docs. =over =item C<< $rule = Pugs::Compiler::Rule->compile($p6_regex, $params) >> Specifically, this class overrides the C method of L which resets the following options' default values: =over =item C<< ratchet => 1 >> Here is an example: $rule = Pugs::Compiler::Rule->compile( 'a*\w', ); my $match = $rule->match('aaa'); # $match->bool is false since no backtracking # happened =item C<< sigspace => 1 >> Here is an example: my $rule = Pugs::Compiler::Rule->compile( 'a b', ); my $match = $rule->match('a b'); ok $match->bool, 'sigspace works'; is $match->(), 'a b', 'sigspace works (2)'; =back =back =head1 CAVEATS This is an experimental development version. The API is still in flux. The set of implemented features depend on the C switch. =head1 AUTHORS The Pugs Team C<< >>. Please join us on irc.freenode.net C<#perl6> if you'd like to participate. =head1 SEE ALSO =over =item * L =item * L =item * L =item * The Perl 6 Rules Spec: L =back =head1 COPYRIGHT Copyright 2006, 2007 by Flavio Soibelmann Glock and others. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut