Pugs::Compiler::Grammar.3pm

Langue: en

Autres versions - même langue

Version: 2008-07-29 (fedora - 01/12/10)

Section: 3 (Bibliothèques de fonctions)

NAME

Pugs::Compiler::Grammar - Compiler for Perl 6 Grammars

SYNOSPIS

     use Pugs::Compiler::Grammar;
     my $grammar = q{
         grammar MyC;
 
         token def {
             <type> <?ws> <var_list> <?ws>? ';'
         }
 
         token type { int | float | double | char }
 
         token var_list {
             <ident>**{1} <?ws>? [ ',' <?ws>? <ident> ]*
         }
 
         grammar MyVB;
 
         token def {
             'Dim' <?ws> <MyC.var_list>
             [ <?ws> 'As' <?ws> <MyC.type> ]? <?ws>? ';'
         }
     };
     my $obj = Pugs::Compiler::Grammar->compile($grammar);
     my $perl5 = $obj->perl5;
     eval $perl5; die $@ if $@;
     my $match = MyC->def("float foo;");
     print "type: ", $match->{type}, "\n";
     print "vars: ", $match->{var_list}, "\n";
     $match = MyVB->def("Dim foo, bar;");
     print "vars: ", $match->{'MyC.var_list'}, "\n";
 
 

METHODS

$obj = Pugs::Compile::Grammar->compile($src)
Acts as contructor. Accepts a string containing the grammar specs and returns a Pugs::Compiler::Grammar instance.
$perl5 = $obj->perl5()
Returns a string containing the Perl source for the grammars compiled.

AUTHOR

The Pugs contributors <perl6-compiler@perl.org>. Copyright 2007 by Agent Zhang and others.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>

SEE ALSO

compile_p6grammar.pl, Pugs::Compiler::Regex, Pugs::Grammar::Rule, Pugs::Emitter::Grammar::Perl5.