Changeset 21789 for src/perl6

Show
Ignore:
Timestamp:
08/05/08 10:09:44 (4 months ago)
Author:
lwall
Message:

[STD vs t] more Mutually Assured Construction

Location:
src/perl6
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r21784 r21789  
    1616$::COMPILING::LINE = 1; 
    1717$::COMPILING::FILE = '(eval)'; 
     18$::GOAL = "(eof)"; 
    1819 
    1920{ package DEBUG; 
     
    624625                                no strict 'refs'; 
    625626                                if ($DEBUG & DEBUG::fates or ($DEBUG & DEBUG::lexer and $x == $last)) { 
    626                                     my $p = $pats[$x] // '<nopat>'; 
     627                                    my $p = $pats[$x-1] // '<nopat>'; 
    627628                                    $self->deb("\$$x: $beg..$end\t$$x\t ", 
    628629                                        $x == $last ? "====>" : "---->", 
  • src/perl6/STD.pm

    r21784 r21789  
    55my $PKG is context = ""; 
    66my @PKGS; 
     7my $GOAL is context = "(eof)"; 
    78 
    89# random rule for debugging, please ignore 
     
    6061method TOP ($STOP = undef) { 
    6162    if defined $STOP { 
     63        my $GOAL is context = $STOP; 
    6264        self.unitstop($STOP).comp_unit; 
    6365    } 
     
    458460} 
    459461 
    460  
    461462token lambda { '->' | '<->' } 
    462463 
     464# Look for an expression followed by a required lambda. 
     465token xblock { 
     466    :my $GOAL is context = '{'; 
     467    <EXPR> 
     468    <.ws> 
     469    <pblock> 
     470} 
    463471 
    464472token block { 
     
    477485token regex_block { 
    478486    :my $lang = ::Regex; 
     487    :my $GOAL is context = '}'; 
    479488 
    480489    [ <quotepair> <.ws> 
     
    587596rule statement_control:if {\ 
    588597    <sym> 
    589     <EXPR>                           {*}                        #= if expr 
    590     <pblock>                         {*}                        #= if block 
    591     $<elsif> = ( 'elsif'<?spacey> <EXPR>       {*}                #= elsif expr 
    592                         <pblock>     {*} )*                     #= elsif block 
    593     $<else> = ( 'else'<?spacey> <pblock>       {*} )?             #= else 
     598    <xblock> 
     599    $<elsif> = ( 
     600        'elsif'<?spacey> <xblock>       {*}                #= elsif 
     601    )* 
     602    $<else> = ( 
     603        'else'<?spacey> <pblock>       {*}             #= else 
     604    )? 
    594605} 
    595606 
     
    597608rule statement_control:unless {\ 
    598609    <sym>  
    599     <EXPR>                           {*}                        #= expr 
    600     <pblock>                         {*}                        #= block 
     610    <xblock> 
    601611    [ <!before 'else'> || <.panic: "unless does not take \"else\" in Perl 6; please rewrite using \"if\""> ] 
    602612} 
     
    607617    [ <?before '(' ['my'? '$'\w+ '=']? '<' '$'?\w+ '>' ')'>   #' 
    608618        <.panic: "This appears to be Perl 5 code"> ]? 
    609     <EXPR>                             {*}                      #= expr 
    610     <pblock>                           {*}                      #= block 
     619    <xblock> 
    611620} 
    612621 
     
    614623rule statement_control:until {\ 
    615624    <sym> 
    616     <EXPR>                             {*}                      #= expr 
    617     <pblock>                           {*}                      #= block 
     625    <xblock> 
    618626} 
    619627 
     
    647655    [ <?before 'my'? '$'\w+ '(' > 
    648656        <.panic: "This appears to be Perl 5 code"> ]? 
    649     <EXPR>                             {*}                      #= expr 
    650     <pblock>                           {*}                      #= block 
    651 } 
    652  
     657    <xblock> 
     658} 
    653659 
    654660rule statement_control:given {\ 
    655661    <sym> 
    656     <EXPR>                             {*}                      #= expr 
    657     <pblock>                           {*}                      #= block 
     662    <xblock> 
    658663} 
    659664rule statement_control:when {\ 
    660665    <sym> 
    661     <EXPR>                             {*}                      #= expr 
    662     <pblock>                           {*}                      #= block 
     666    <xblock> 
    663667} 
    664668rule statement_control:default {<sym> <block> } 
     
    15021506    [ 
    15031507    | <ident> 
    1504     | '(' :: <EXPR> [ ')' || <.panic: "Unable to parse indirect name; couldn't find right parenthesis"> ] 
     1508    | '(' :: <in: ')', 'EXPR', 'indirect name'> 
    15051509    ] 
    15061510} 
     
    24132417 
    24142418token named_param { 
     2419    :my $GOAL is context = ')'; 
    24152420    ':' 
    24162421    [ 
     
    24322437        <?{ $<sigil>.text eq '@' || $<sigil>.text eq '%' }> 
    24332438        <ident>? 
    2434         <.ws> 
    24352439        <?before <[ \< \( \[ \{ ]> > 
    24362440        <postcircumfix> 
     
    25252529## term 
    25262530token term:sym<undef> ( --> Term) { 
    2527     <sym> » \h* 
    2528     [ <?before '$/' > 
     2531    <sym> » 
     2532    [ <?before \h*'$/' > 
    25292533        <obs('$/ variable as input record separator', 
    25302534             "the filehandle's .slurp method")> 
    25312535    ]? 
    2532     [ <?before < $ @ % & > > 
     2536    [ <?before \h*< $ @ % & > > 
    25332537        <obs('undef as a verb', 'undefine function')> 
    25342538    ]? 
    25352539} 
     2540 
     2541token term:sym<next> ( --> Term) 
     2542    { <sym> » <.ws> <termish>? } 
     2543 
     2544token term:sym<last> ( --> Term) 
     2545    { <sym> » <.ws> <termish>? } 
     2546 
     2547token term:sym<redo> ( --> Term) 
     2548    { <sym> » <.ws> <termish>? } 
     2549 
     2550token term:sym<goto> ( --> Term) 
     2551    { <sym> » <.ws> <termish> } 
    25362552 
    25372553token term:sym<self> ( --> Term) 
     
    28772893## conditional 
    28782894token infix:sym<?? !!> ( --> Conditional) { 
     2895    :my $GOAL is context = '!!'; 
    28792896    '??' 
    28802897    <.ws> 
     
    28942911    { <sym> <obs('?: for the conditional operator', '??!!')> } 
    28952912 
    2896  
    28972913## assignment 
    28982914# There is no "--> type" because assignment may be coerced to either 
     
    29502966    { <sym> } 
    29512967 
    2952 token prefix:sym<...> ( --> List_prefix) 
    2953 { 
    2954     '...' 
    2955 } 
    2956  
    2957 token prefix:sym<???> ( --> List_prefix) 
    2958 { 
    2959     '???' 
    2960 } 
    2961  
    2962 token prefix:sym<!!!> ( --> List_prefix) 
    2963 { 
    2964     '!!!' 
    2965 } 
     2968token term:sym<...> ( --> List_prefix) 
     2969    { <sym> <args>? } 
     2970 
     2971token term:sym<???> ( --> List_prefix) 
     2972    { <sym> <args>? } 
     2973 
     2974token term:sym<!!!> ( --> List_prefix) 
     2975    { <sym> <args>? } 
    29662976 
    29672977token term:sigil ( --> List_prefix) 
     
    29772987token term:ident ( --> Term ) 
    29782988{ 
    2979     <ident> 
     2989    :my $i; 
     2990    $i = <ident> <args( $¢.is_type($i.text) )> 
     2991} 
     2992 
     2993token term:opfunc ( --> Term ) 
     2994{ 
     2995    <category> <colonpair>+ <args> 
     2996} 
     2997 
     2998token args ($istype = 0) { 
     2999    :my $listopy = 0; 
    29803000    [ 
    29813001    | '.(' <in: ')', 'semilist', 'argument list'> {*}             #= func args 
    29823002    | '(' <in: ')', 'semilist', 'argument list'> {*}              #= func args 
    29833003    | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*} #= func args 
    2984     ] 
    2985  
    2986     [ 
     3004    | :: [<?before \s> <!{ $istype }> <.ws> <!infixstopper> <arglist>]? { $listopy = 1 } 
     3005    ] 
     3006 
     3007    [ 
     3008    || <?{ $listopy }> 
    29873009    || ':' <?before \s> <arglist>    # either switch to listopiness 
    2988     || {{ $+prevop = $<O> = {}; }}   # or allow adverbs 
     3010    || {{ $+prevop = $<O> = {}; }}   # or allow adverbs (XXX needs hoisting?) 
    29893011    ] 
    29903012} 
     
    30093031 
    30103032    # unrecognized names are assumed to be post-declared listops. 
    3011     || <?before \s> <arglist> 
    3012         {*}                                                     #= listop args 
    3013     || 
    3014         [ 
    3015         | '.(' <in: ')', 'semilist', 'argument list'> 
    3016             {*}                                                 #= func args 
    3017  
    3018         | '(' <in: ')', 'semilist', 'argument list'> 
    3019             {*}                                                 #= func args 
    3020  
    3021         | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> 
    3022             {*}                                                 #= func args 
    3023  
    3024  
    3025         | ::  {*}                                               #= listop noarg 
    3026         ] 
    3027  
    3028         [ 
    3029         || ':' <?before \s> <arglist>    # either switch to listopiness 
    3030         || {{ $+prevop = $<O> = {}; }}   # or allow adverbs 
    3031         ] 
     3033    || <args>? 
     3034#    || <?before \s> <arglist> 
     3035#        {*}                                                     #= listop args 
     3036#    || 
     3037#        [ 
     3038#        | '.(' <in: ')', 'semilist', 'argument list'> 
     3039#            {*}                                                 #= func args 
     3040# 
     3041#        | '(' <in: ')', 'semilist', 'argument list'> 
     3042#            {*}                                                 #= func args 
     3043# 
     3044#        | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> 
     3045#            {*}                                                 #= func args 
     3046# 
     3047# 
     3048#        | ::  {*}                                               #= listop noarg 
     3049#        ] 
     3050# 
     3051#        [ 
     3052#        || ':' <?before \s> <arglist>    # either switch to listopiness 
     3053#        || {{ $+prevop = $<O> = {}; }}   # or allow adverbs 
     3054#        ] 
    30323055    ] 
    30333056} 
     
    31013124 
    31023125token terminator:sym<!!> ( --> Terminator) 
    3103     { <?before '!!' > } 
     3126    { <?before '!!' > <?{ $+GOAL eq '!!' }> } 
    31043127 
    31053128regex infixstopper { 
    31063129    | <?before <stopper> > 
    3107     | <?before '{' | <lambda> > <?{ $¢.<_>[$¢.pos]<ws> }> 
     3130    | <?before '!!' > <?{ $+GOAL eq '!!' }> 
     3131    | <?before '{' | <lambda> > <?{ $+GOAL eq '{' and $¢.<_>[$¢.pos]<ws> }> 
    31083132} 
    31093133 
     
    33763400    # suppress fancy end-of-line checking 
    33773401    token codeblock { 
     3402        :my $GOAL is context = '}'; 
    33783403        '{' :: [ :lang($¢.cursor_fresh($+LANG)) <statementlist> ] 
    33793404        [ '}' || <.panic: "Unable to parse statement list; couldn't find right brace"> ] 
     
    37193744} 
    37203745 
     3746# not quite a "between" combinator... 
    37213747token in (Str $stop, Str $insides, Str $name = $insides) { 
     3748    :my $GOAL is context = $stop; 
    37223749    <x=$insides> $stop {{ $/.{$insides} = $<x>; delete $<x> }} || <.panic: "Unable to parse $name; couldn't find final '$stop'"> 
    37233750} 
  • src/perl6/gimme5

    r21743 r21789  
    15791579        my $var = $$self{var}; 
    15801580        my $re = $$self{atom}->walk(@_); 
    1581         "bindvar($var,$re)";    # doesn't do "let" semantics yet 
     1581        "($var = $re)"; # doesn't do "let" semantics yet 
    15821582    } 
    15831583}