Changeset 5366


Ignore:
Timestamp:
06/19/09 10:58:54 (3 years ago)
Author:
azawawi
Message:

[Perl 6] Refactored colorizer task into PGE and STD. PGE coloring is now a background task.

Location:
trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6
Files:
1 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6/Perl6Document.pm

    r5344 r5366  
    1414my $COLORIZE_TIMER; 
    1515my $COLORIZE_TIMEOUT = 100; # wait n-millisecond before starting the Perl6 colorize task 
    16  
    17 # used for coloring by parrot 
    18 my %perl6_colors = ( 
    19     quote_expression => Padre::Constant::PADRE_BLUE, 
    20     parse            => undef, 
    21     statement_block  => undef, 
    22     statementlist    => undef, 
    23     statement        => undef, 
    24     expr             => undef, 
    25     'term:'          => undef, 
    26     noun             => undef, 
    27     value => undef, 
    28     quote => undef, 
    29     quote_concat => undef, 
    30     quote_term => undef, 
    31     quote_literal => undef, 
    32     post => Padre::Constant::PADRE_MAGENTA, 
    33     dotty => undef, 
    34     dottyop => undef, 
    35     methodop => Padre::Constant::PADRE_GREEN, 
    36     name => Padre::Constant::PADRE_GREEN, 
    37     identifier => undef, 
    38     term => undef, 
    39     args => undef, 
    40     arglist => undef, 
    41     EXPR => undef, 
    42     statement_control => undef, 
    43     use_statement => undef, 
    44     sym => Padre::Constant::PADRE_RED, 
    45     'infix:='  => Padre::Constant::PADRE_GREEN, 
    46     'infix:+'  => Padre::Constant::PADRE_GREEN, 
    47 #   'infix:*'  => Padre::Constant::PADRE_GREEN, 
    48 #   'infix:/'  => Padre::Constant::PADRE_GREEN, 
    49     'infix:,'  => Padre::Constant::PADRE_GREEN, 
    50     'infix:..' => undef, 
    51     'prefix:=' => undef, 
    52     'infix:|' => undef, 
    53     'infix:==' => undef, 
    54     'infix:*=' => undef, 
    55     twigil => undef, 
    56     if_statement => undef, 
    57     'infix:eq' => undef, 
    58     semilist => undef, 
    59     scope_declarator => undef, 
    60     scoped => undef, 
    61     variable_declarator => undef, 
    62     declarator => undef, 
    63     variable => Padre::Constant::PADRE_RED, #Padre::Constant::PADRE_DIM_GRAY, 
    64     integer => undef, 
    65     number => Padre::Constant::PADRE_BROWN, 
    66     circumfix => undef, 
    67     param_sep => undef, 
    68     sigil => undef, 
    69     desigilname => undef, 
    70     longname => undef, 
    71     parameter => undef, 
    72     param_var => undef, 
    73     quant => undef, 
    74     pblock => undef, 
    75     block => undef, 
    76     signature => undef, 
    77     for_statement => undef, 
    78     xblock => undef, 
    79     lambda => Padre::Constant::PADRE_GREEN, 
    80 ); 
    81  
    82 #    'regex_block' => Padre::Constant::PADRE_BLACK, 
    83 #    'number' => Padre::Constant::PADRE_ORANGE, 
    84 #    'param_var' => Padre::Constant::PADRE_CRIMSON, 
    85 #    '_hash' => Padre::Constant::PADRE_ORANGE, 
    86  
    8716 
    8817sub text_with_one_nl { 
     
    10433    my $self = shift; 
    10534     
    106     # temporary overlay using the parse tree given by parrot 
    107     # TODO: let the user select which one to use 
    108     # TODO: but the parrot parser in the background 
    109     #require Padre::Plugin::Perl6::Util; 
    110     #my $perl6 = Padre::Plugin::Perl6::Util::get_perl6(); 
    111     #if ($perl6) { 
    112     #   $self->_parrot_color($perl6); 
    113     #   return; 
    114     #} 
    115  
    11635    my $config = Padre::Plugin::Perl6::plugin_config(); 
    11736    if($config->{p6_highlight} || $self->{force_p6_highlight}) { 
     
    12443                $main, $timer_id,  
    12544                sub {  
    126                     # Create a coloring task and hand off to the task manager 
    127                     require Padre::Plugin::Perl6::Perl6ColorizerTask; 
    128                     my $task = Padre::Plugin::Perl6::Perl6ColorizerTask->new( 
    129                         text => $self->text_with_one_nl, 
    130                         editor => $self->editor, 
    131                         document => $self); 
     45                    # temporary overlay using the parse tree given by parrot 
     46                    # TODO: let the user select which one to use 
     47                    my $colorizer = 'PGE'; 
     48                    my $task; 
     49                    if($colorizer eq 'STD') { 
     50                        # Create an STD coloring task  
     51                        require Padre::Plugin::Perl6::Perl6StdColorizerTask; 
     52                        $task = Padre::Plugin::Perl6::Perl6StdColorizerTask->new( 
     53                            text => $self->text_with_one_nl, 
     54                            editor => $self->editor, 
     55                            document => $self); 
     56                    } else { 
     57                        # Create a PGE coloring task 
     58                        require Padre::Plugin::Perl6::Perl6PgeColorizerTask; 
     59                        $task = Padre::Plugin::Perl6::Perl6PgeColorizerTask->new( 
     60                            text => $self->text_with_one_nl, 
     61                            editor => $self->editor, 
     62                            document => $self); 
     63                        $task->schedule(); 
     64                    } 
     65                    # hand off to the task manager 
    13266                    $task->schedule(); 
    13367 
     
    14680        $COLORIZE_TIMER->Start( $COLORIZE_TIMEOUT, Wx::wxTIMER_ONE_SHOT ); 
    14781    } 
    148 } 
    149  
    150 sub _parrot_color { 
    151     my ($self, $perl6) = @_; 
    152      
    153     my $editor = $self->editor; 
    154  
    155     use File::Temp qw(tempdir); 
    156     my $dir = tempdir(CLEANUP => 1); 
    157     my $file = "$dir/file"; 
    158  
    159     if (open my $fh, '>', $file) { 
    160         print $fh $self->text_get; 
    161     }    
    162  
    163     my @data = `"$perl6" --target=parse --dumper=padre "$file"`; 
    164     chomp @data; 
    165     my @pd; 
    166     foreach my $line (@data) { 
    167         $line =~ s/^\s+//; 
    168         my ($start, $length, $type, $str) = split /\s+/, $line, 4; 
    169         push @pd, { 
    170             start => $start, 
    171             length => $length, 
    172             type => $type, 
    173             str => $str, 
    174             }; 
    175         if (not exists ($perl6_colors{$type})) { 
    176             warn "No Perl6 color definiton for '$type':  $str\n"; 
    177             next; 
    178         } 
    179         next if not defined $perl6_colors{$type}; # no need to color 
    180         my $color = $perl6_colors{$type}; 
    181         $editor->StartStyling($start, $color); 
    182         $editor->SetStyling($length, $color); 
    183  
    184     } 
    185     $self->{_parse_tree} = \@pd; 
    186  
    187     #use Data::Dumper; 
    188     #print Dumper \@data; 
    189  
    190     return; 
    19182} 
    19283 
  • trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6/Perl6StdColorizerTask.pm

    r5365 r5366  
    1 package Padre::Plugin::Perl6::Perl6ColorizerTask; 
     1package Padre::Plugin::Perl6::Perl6StdColorizerTask; 
    22 
    33use strict; 
Note: See TracChangeset for help on using the changeset viewer.