This module is a backend of Pugs::Compiler::Rule, helping
Pugs::Compiler::Rule translates the perl 6 rule into haskell
Parsec parsing code. This is part of the bootstap.
c.f. http://svn.perl.org/parrot/trunk/compilers/pge/P6Rule.grammar
http://www.cs.uu.nl/~daan/download/parsec/parsec.html
The boostrap steps are listed:
1. This module, Pugs::Grammar::MiniPerl6, uses Pugs::Compiler::Rule
to read a special *mixed* perl 6 rule whose production rules
are written in perl 5 (the current requirement of P::C::Rule).
1a. The rule is used to translate a subset of perl 6, MiniPerl6,
to haskell.
2. Then, Pugs::Compiler::Emit::Parsec lands and uses this module
to translate the full perl 6 grammar into a parser. The full
grammar can now write production rules in MiniPerl6 since
P::C::E::Parsec can use this module to translate such production
rules to haskell and makes the final output be pure Haskell.
3. When compiling Pugs, the .hs preprocessor will use
Pugs::Compiler::Emit::Parsec to accept the full perl 6 grammar
generating Parser.hs. Then GHC will compile it to executable.
4. The executable can now read the full perl 6 grammar again
generating compiler in PIL. Then self hosting is done.
The mixed rule looks like this:
rule yadaLiteral {
$<sym> := [ <'...'> | <'???'> | <'!!!'> ]
{ use v5;
return App(
Var( doYada( $<sym> ) ),
Nothing,
[ Val( VStr( $<sym> . ' - not yet implemented') ) ]
)
}
}
Which is different from the real rule (note the lack of "use v5" and
'.' is replaced by '~'):
rule yadaLiteral {
$<sym> := [ <'...'> | <'???'> | <'!!!'> ]
{ return App(
Var( doYada( $<sym> ) ),
Nothing,
[ Val( VStr( $<sym> ~ ' - not yet implemented') ) ]
)
}
}
The supposed output (of both modules, Pugs::Grammar::MiniPerl6 and
Pugs::Compiler::Emit::Parsec) is:
yadaLiteral = expRule $ do
sym <- choice . map symbol $ words " ... ??? !!! "
return $ App (Var $ doYada sym) Nothing [Val $ VStr (sym ++ " - not yet implemented")]
Currently, this rule is in src/Pugs/Parser/Literal.hs:
{-|
Match one of the \'yada-yada-yada\' placeholder expressions (@...@, @???@ or
@!!!@), returning a call to @&fail@, @&warn@ or @&die@ respectively.
-}
yadaLiteral :: RuleParser Exp
yadaLiteral = expRule $ do
sym <- choice . map symbol $ words " ... ??? !!! "
return $ App (Var $ doYada sym) Nothing [Val $ VStr (sym ++ " - not yet implemented")]
where
doYada "..." = "&fail_" -- XXX rename to fail() eventually
doYada "???" = "&warn"
doYada "!!!" = "&die"
doYada _ = error "Bad yada symbol"
Spec of MiniPerl6
The MiniPerl6 includes only these language constructions
(c.f. lib/Pugs/Grammar/MiniPerl6.grammar)
Var: $<name> $0 $1 ...
Return: return
Call: Foo( exp, exp... ) # parantheses are necessary
Bar
Infix: ~ + -
Lit: [exp, exp]
(exp, exp) # not implemented
123
"string" # no 'string', no interpolating, no escape except \" and \\
Variable: my $a = 1 + 2 # one a time, no parantheses, never changed