Skip to content
This repository
tree: f226bf64d4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 69 lines (56 sloc) 2.035 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
our $Sig;
use STD;

grammar NieczaGrammar is STD;

grammar CgOp is STD {
    rule nibbler { <cgexp> }

    token category:cgexp { <sym> }
    proto token cgexp {*}

    token cgopname { <-[ ' " ( ) { } \[ \] \s ]> + }

    token cgexp:op { <[ ( \[ ]>:s {} <cgopname> [ <cgexp> ]* <[ ) \] ]> }
    token cgexp:name { <cgopname> }
    token cgexp:quote { <?before <[ ' " ]>> {} [ :lang(%*LANG<MAIN>) <quote> ] }
    token cgexp:decint { <decint> }
    token cgexp:p6exp { :lang(%*LANG<MAIN>) '{' ~ '}' <statementlist> }
    token cgexp:bad { <!before <[ ) \] ]> > {}
[ <?stdstopper> <.panic: "Missing cgop"> ]
<.panic: "Unparsable cgop">
}
}

grammar Q is STD::Q { #} {
    method tweak(:$CgOp, *%_) {
        if $CgOp.defined { self.cursor_fresh(NieczaGrammar::CgOp) }
        else { nextsame }
    }
}

grammar P6 is STD::P6 {
    method unitstart() {
        $*CURLEX{'!sub'} = $*unit.create_sub(
            outer => $*settingref,
            outer_frame => $*niecza_outer_frame,
            class => 'Routine',
            cur_pkg => $*unit.abs_pkg('GLOBAL'),
            name => "mainline",
            run_once => !$*settingref || ?$*niecza_outer_frame ||
                $*settingref.run_once);
        $*CURLEX<!sub>.set_return_pass;
        $*CURLEX{'!sub'}.add_my_name('$_') if !$*settingref;
        $*CURLEX{'!sub'}.set_signature($Sig.simple());

        # XXX a bit of a hack
        if $*FILE<name> eq ('(eval)' | '-e') && !$*niecza_outer_ref {
            $*CURLEX<!sub>.set_extend('strict', False);
        }

        $*unit.set_mainline($*CURLEX<!sub>);

        %*LANG<Q> = NieczaGrammar::Q ;
        %*LANG<MAIN> = NieczaGrammar::P6 ;

        my @names;
        loop (my $C = $*CURLEX<!sub>; $C; $C.=outer) {
            for $C.lex_names -> $name {
                $name := $name.substr(1) if $name && substr($name,0,1) eq '&';
                push @names, $name;
            }
        }
        self.batch_categoricals(@names);
        self;
    }
}

method p6class () { NieczaGrammar::P6 }
Something went wrong with that request. Please try again.