package Grammar::Perl6; use base 'Pugs::Grammar::Base', 'Pugs::Grammar::Rule', 'Grammar::Perl6Init'; use Runtime::RuleCompiler qw(rule); use Pugs::Grammar::Rule; use Pugs::Runtime::Match; *{'immediate_statement_rule'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); ? <@Grammar::Perl6::statements> ? { return $() } RULE *{'grammar'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); * { return $() } RULE *{'indirect_object'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); ? \: { return $ } RULE *{'rule_decl'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); rule ? \{ \} { return { rule_decl => $() ,} } RULE *{'grammar_name'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); grammar ? \; { return { grammar_name => $() ,} } RULE *{'condition_rule'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=(if|unless)?\(?$:=()?\) ?$:=() { return { condition => $() } } RULE *{'meth_call_term'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=() \. $:=()\(?$:=(?)?\)? { return { meth_call_term => $() } } RULE *{'meth_call_statement'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=() \. $:=()\(?$:=(?)?\)?\; { return { meth_call => $() } } RULE *{'sub_call_term'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()\(?$:=(?)?\)? { return { sub_call_term => $() } } RULE *{'sub_call_statement'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\(?$:=(?)?\)?\; { return { sub_call => $() } } RULE *{'access_hashref_element'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()\{$:=()\} { return { access_hashref_element => $() } } RULE *{'access_hash_element'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()\{$:=()\} { return { access_hash_element => $() } } RULE *{'assign_hash_to_scalar'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\=?$:=()?\; { return { assign_hash_to_scalar => $() } } RULE *{'assign_slurp_to_variable'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\=?slurp?$:=()?\; { return { slurp => $() } } RULE *{'assign_open_to_variable'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\=?open?$:=()?\; { return { _open => $() } } RULE *{'assign'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\=?$:=()?\; { return { assign => $() } } RULE *{'sub_call'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $:=()?\(?$:=(?)?\)?\; { return { sub_call => $() } } RULE *{'_push'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (push|unshift) ? \, ? $ := (.*?) ? \; { return { _push => $() ,} } RULE *{'pod'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); \=[pod|head1|kwid|for] .*? \=cut RULE *{'use_v6'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); use v6 \-pugs ? \; RULE *{'require'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); require ? \; { eval 'require '.$()->[2]{ident}[0]{ident}; return { require_bareword => $() ,} } RULE *{'use_rule'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); use ? \; { eval 'use '.$()->[2]{ident}[0]{ident}; return { use_bareword => $() ,} } RULE *{'term1'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); <@Grammar::Perl6::terms> RULE *{'list'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); [ ? \, ? ]* ? RULE *{'block'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); \{ $ := ( [ ? <@Grammar::Perl6::statements> ]* ) ? \} { return { block => $ ,} } RULE *{'macro_decl'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); macro $ := () \: \< $ := (.*?) \> ? \( ? ? ? \) ? is parsed ? \( ? \/ ? ? \/ ? \) ? { eval Emitter::Perl5::emit({macro => $()}); return { macro => $() ,} } RULE *{'empty_list'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); \(\) { return { empty_list => $() } } RULE *{'_open'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (open) ? \; { return { _open => $(), } } RULE *{'_print_with_fh'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (print|say|warn|die) ? \; { return { _print_with_fh => $() ,} } RULE *{'_print'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (print|say|warn|die) ? \; { return { _print => $() ,} } RULE *{'_my'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (my|our|local) ? \; { return { _my => $() ,} } RULE *{'_simple_statement'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (die|\.\.\.) \; { return { _simple_statement => $() ,} } RULE *{'sub_decl'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); sub $ := (infix|prefix|postfix) \: \< $ := (.*?) \> ? { return { sub_decl => $() ,} } RULE *{'sub_defin'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); sub ? ? { return { sub_defin => $() ,} } RULE *{'term2'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := () ? $ := (<@Grammar::Perl6::ops>) ? $ := () { return { sub_application_term => $() ,} } RULE *{'sub_application'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); $ := (|) ? $ := (<@Grammar::Perl6::ops>) ? $ := (|) ? \; { return { sub_application => $() ,} } RULE *{'eval_perl5'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); eval ? \( ? ? \, ? \: lang \< perl5 \> ? \) ? \; { return { eval_perl5 => $ } } RULE *{'_return'} = Pugs::Compiler::Rule->compile(<<'RULE')->code(); return $ := (|) ? \; { return { _return => $() ,} } RULE push @terms, sub { Grammar::Perl6->indirect_object(@_) }; push @statements, sub { Grammar::Perl6->rule_decl(@_) }; push @statements, sub { Grammar::Perl6->grammar_name(@_) }; push @statements, sub { Grammar::Perl6->condition_rule(@_) }; push @statements, sub { Grammar::Perl6->meth_call_statement(@_) }; push @terms, sub { Grammar::Perl6->meth_call_term(@_) }; push @statements, sub { Grammar::Perl6->sub_call_statement(@_) }; push @terms, sub { Grammar::Perl6->sub_call_term(@_) }; push @terms, sub { Grammar::Perl6->access_hashref_element(@_) }; push @statements, sub { Grammar::Perl6->access_hashref_element(@_) }; push @terms, sub { Grammar::Perl6->access_hash_element(@_) }; push @statements, sub { Grammar::Perl6->access_hash_element(@_) }; push @statements, sub { Grammar::Perl6->assign_hash_to_scalar(@_) }; push @statements, sub { Grammar::Perl6->assign_slurp_to_variable(@_) }; push @statements, sub { Grammar::Perl6->assign_open_to_variable(@_) }; push @statements, sub { Grammar::Perl6->assign(@_) }; push @statements, sub { Grammar::Perl6->sub_call(@_) }; push @terms, sub { Grammar::Perl6->sub_call(@_) }; push @statements, sub { Grammar::Perl6->_push(@_) }; push @statements, sub { Grammar::Perl6->pod(@_) }; push @statements, sub { Grammar::Perl6->use_v6(@_) }; push @statements, sub { Grammar::Perl6->require(@_) }; push @statements, sub { Grammar::Perl6->use_rule(@_) }; push @statements, sub { Grammar::Perl6->block(@_) }; push @statements, sub { Grammar::Perl6->macro_decl(@_) }; push @terms, sub { Grammar::Perl6->empty_list(@_) }; push @terms, sub { Grammar::Perl6->varhash(@_) }; push @terms, sub { Grammar::Perl6->varscalar(@_) }; push @terms, sub { Grammar::Perl6->variable(@_) }; push @terms, sub { Grammar::Perl6->literal(@_) }; push @statements, sub { Grammar::Perl6->_open(@_) }; push @terms, sub { Grammar::Perl6->_open(@_) }; push @statements, sub { Grammar::Perl6->_print_with_fh(@_) }; push @statements, sub { Grammar::Perl6->_print(@_) }; push @statements, sub { Grammar::Perl6->_my(@_) }; push @statements, sub { Grammar::Perl6->_simple_statement(@_) }; push @statements, sub { Grammar::Perl6->sub_decl(@_) }; push @statements, sub { Grammar::Perl6->sub_defin(@_) }; push @statements, sub { Grammar::Perl6->sub_application(@_) }; push @statements, sub { Grammar::Perl6->eval_perl5(@_) }; push @statements, sub { Grammar::Perl6->_return(@_) }; 1;