Changeset 22576 for src/perl6

Show
Ignore:
Timestamp:
10/11/08 09:27:34 (6 weeks ago)
Author:
lwall
Message:

[viv] now outputs p6 variables, declarations
[STD] more random hackage for viv and :exists
[STD] now parses declaration initializers as normal assignops

Location:
src/perl6
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD.pm

    r22575 r22576  
    984984    :dba('infix or meta-infix') 
    985985    [ 
    986     | <colonpair> { $<fake> = 1; $<sym> = ':'; %<O><prec> = %loose_unary<prec>;  } 
     986    | <colonpair> { 
     987            $<fake> = 1; 
     988            $<sym> = ':'; 
     989            %<O><prec> = %loose_unary<prec>; 
     990            %<O><assoc> = 'left'; 
     991        } 
    987992    | <infix> 
    988993       [ 
     
    11801185      #  <?{ $<sigil> eq '@' | '%' }> 
    11811186        <.unsp>? 
    1182         [ 
     1187        $<shape> = [ 
    11831188        | '(' ~ ')' <signature> 
    11841189        | :dba('shape definition') '[' ~ ']' <semilist> 
     
    11921197 
    11931198    <post_constraint>* 
    1194  
    1195     # XXX generalize to any assignment operator? 
    1196     :dba('variable initializer') 
    1197     [ 
    1198     | '=' <.ws> <EXPR( ($<SIGIL> // '') eq '$' ?? item %item_assignment !! item %list_prefix )> 
    1199     | '.=' <.ws> <dottyop> 
    1200     ]? 
    12011199} 
    12021200 
     
    12041202    :dba('scoped declarator') 
    12051203    [ 
    1206     | <declarator> 
     1204    | <declarator> { $<SIGIL> = $<declarator><SIGIL> } 
    12071205    | <regex_declarator> 
    12081206    | <package_declarator> 
    12091207    | <fulltypename>+ <multi_declarator> 
    1210     | <multi_declarator> 
     1208    | <multi_declarator> { $<SIGIL> = $<multi_declarator><SIGIL> } 
    12111209#    | <?before <[A..Z]> > <name> <.panic("Apparent type name " ~ $<name>.text ~ " is not declared yet")> 
    12121210    ] 
     
    12141212 
    12151213 
    1216 token scope_declarator:my       { <sym> <scoped> } 
    1217 token scope_declarator:our      { <sym> <scoped> } 
    1218 token scope_declarator:state    { <sym> <scoped> } 
    1219 token scope_declarator:constant { <sym> <scoped> } 
    1220 token scope_declarator:has      { <sym> <scoped> } 
     1214token scope_declarator:my       { <sym> <scoped> { $<SIGIL> = $<scoped><SIGIL> } } 
     1215token scope_declarator:our      { <sym> <scoped> { $<SIGIL> = $<scoped><SIGIL> } } 
     1216token scope_declarator:state    { <sym> <scoped> { $<SIGIL> = $<scoped><SIGIL> } } 
     1217token scope_declarator:constant { <sym> <scoped> { $<SIGIL> = $<scoped><SIGIL> } } 
     1218token scope_declarator:has      { <sym> <scoped> { $<SIGIL> = $<scoped><SIGIL> } } 
    12211219 
    12221220 
     
    13061304token declarator { 
    13071305    [ 
    1308     | <variable_declarator> 
     1306    | <variable_declarator> { $<SIGIL> = $<variable_declarator><SIGIL> } 
    13091307    | '(' ~ ')' <signature> <trait>* 
    13101308    | <routine_declarator> 
     
    13141312} 
    13151313 
    1316 token multi_declarator:multi { <sym> <.ws> [ <declarator> || <routine_def> ] } 
    1317 token multi_declarator:proto { <sym> <.ws> [ <declarator> || <routine_def> ] } 
    1318 token multi_declarator:only  { <sym> <.ws> [ <declarator> || <routine_def> ] } 
    1319 token multi_declarator:null  { <declarator> } 
     1314token multi_declarator:multi { <sym> <.ws> [ <declarator> { $<SIGIL> = $<declarator><SIGIL> } || <routine_def> ] } 
     1315token multi_declarator:proto { <sym> <.ws> [ <declarator> { $<SIGIL> = $<declarator><SIGIL> } || <routine_def> ] } 
     1316token multi_declarator:only  { <sym> <.ws> [ <declarator> { $<SIGIL> = $<declarator><SIGIL> } || <routine_def> ] } 
     1317token multi_declarator:null  { <declarator> { $<SIGIL> = $<declarator><SIGIL> } } 
    13201318 
    13211319token routine_declarator:sub       { <sym> <routine_def> } 
  • src/perl6/viv

    r22575 r22576  
    1414my $OPT_pos = 0; 
    1515my $OPT_match = 0; 
     16my $OPT_log = 0; 
    1617our $ORIG; 
    1718our $POS; 
    18 my %did_ws; 
     19my @did_ws; 
    1920 
    2021 
     
    3334            $output = 'p6'; 
    3435            $OPT_pos = 1; 
     36        } 
     37        elsif ($switch eq '--log') { 
     38            $OPT_log = 1; 
    3539        } 
    3640        elsif ($switch eq '--pos') { 
     
    196200                } 
    197201            } 
    198             elsif ($arity eq 'CHAIN') { 
     202            elsif ($self->{sym} eq 'identifier') { 
     203                $text .= join('', reverse @zyg); 
     204            } 
     205            else { 
    199206                $text .= join('', @zyg); 
    200             } 
    201             else { 
    202                 $text .= join('', reverse @zyg); 
    203207            } 
    204208        } 
     
    213217 
    214218    sub ret { my $self = shift; 
    215         warn ref $self, " returns ", $_[0], "\n"; 
     219        warn ref $self, " returns ", $_[0], "\n" if $OPT_log; 
    216220        $_[0]; 
    217221    } 
     
    255259        my $ws = $self->{WS} // 0; 
    256260        my $pos = $self->{POS}; 
    257         if ($ws and not $did_ws{$pos}++) { 
     261        if ($ws and not $did_ws[$pos]++) { 
    258262            substr($ORIG, $pos - $ws, $ws) 
    259263        } 
     
    282286    sub emit_p6 { my $self = shift; 
    283287        my $text = $self->SUPER::emit_p6(@_); 
    284         my $finalws = $$POS[-1]{ws}; 
    285         $text .= substr($ORIG, $finalws, -1) if $finalws; 
     288        if (not @did_ws[@$POS-1]) { 
     289            my $finalws = $$POS[-1]{ws}; 
     290            $text .= substr($ORIG, $finalws, -1) if $finalws; 
     291        } 
    286292        $self->ret($text); 
    287293    } 
     
    357363} 
    358364 
     365{ package VAST::scope_declarator; our @ISA = 'VAST::AddSym'; } 
    359366{ package VAST::statement_control; our @ISA = 'VAST::AddSym'; } 
    360367{ package VAST::version; our @ISA = 'VAST::AddSym'; } 
    361368 
     369{ package VAST::variable_declarator; our @ISA = 'VAST::Base'; 
     370    sub emit_p6 { my $self = shift; 
     371        my $text = $self->get_ws; 
     372        $text .= ($self->get_zyg('variable'))[0]; 
     373        $text .= join '', $self->get_zyg('shape'); 
     374        $text .= join '', $self->get_zyg('trait'); 
     375        $text .= join '', $self->get_zyg('post_constraint'); 
     376        $text; 
     377    } 
     378} 
     379 
    362380if ($0 eq __FILE__) { 
    363381    ::MAIN(@ARGV);