parrotcode: utility PGE subroutines | |
Contents | Libraries |
PGE::Util - utility PGE subroutines
The subroutines and items in this module are provided to make working with PGE a little easier.
This module defines the "PGE::P6Grammar" compiler, which can be used to compile complete sets of rules (grammars). Input to the grammar compiler is a string containing statements of the form
grammar <name> ;
rule <ident> { <p6rule> } ;
# comment
A grammar
statement indicates where to load any subsequent rules. Unlike Perl 6, there can be multiple grammar
statements in the string.
Here's a code snippet to load a set of rules using the grammar compiler:
load_bytecode "PGE.pbc"
load_bytecode "PGE/Util.pir"
$S0 = <<'END'
grammar PGE::Rule;
rule ident { [ _ | <?alpha> ] \w* }
rule name { <ident> [ \:\: <ident> ]* }
END
$P0 = compreg "PGE::P6Grammar"
$P1 = $P0($S0)
# rules <PGE::Rule::ident> and <PGE::Rule::name> have now been loaded
The return value from the compiler is a string containing the PIR generated from the rules in the grammar, which can be saved and used to generate precompiled .pbc files for other packages.
__onload()
compile_rules(STR src)
src
.Hey! The above document had some coding errors, which are explained below:
|