Changeset 2153
- Timestamp:
- 12/21/08 23:19:47 (3 years ago)
- Location:
- trunk/Padre-Plugin-Perl6/lib/Padre
- Files:
-
- 2 edited
-
Document/Perl6.pm (modified) (2 diffs)
-
Plugin/Perl6.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre-Plugin-Perl6/lib/Padre/Document/Perl6.pm
r2118 r2153 18 18 # Naive way to parse and colorize perl6 files 19 19 sub colorize { 20 my ($self, $first) = @_;20 my ($self, $first) = @_; 21 21 22 my $editor = $self->editor;23 my $text = $self->text_get;24 22 my $editor = $self->editor; 23 my $text = $self->text_get; 24 25 25 my $t0 = Benchmark->new; 26 26 my $p = Syntax::Highlight::Perl6->new( 27 27 text => $text, 28 28 ); 29 29 30 30 my @tokens; 31 31 32 eval {33 @tokens = $p->tokens;32 eval { 33 @tokens = $p->tokens; 34 34 1; 35 };36 37 if($EVAL_ERROR) {38 say "Parsing error, bye bye ->colorize";39 return;40 }41 42 $self->remove_color;43 35 }; 36 37 if($EVAL_ERROR) { 38 say "Parsing error, bye bye ->colorize"; 39 return; 40 } 41 42 $self->remove_color; 43 44 44 my %colors = ( 45 'comp_unit' => Px::PADRE_BLUE, 46 'scope_declarator' => Px::PADRE_RED,47 'routine_declarator' => Px::PADRE_RED,48 'regex_declarator' => Px::PADRE_RED,49 'package_declarator' => Px::PADRE_RED,50 'statement_control' => Px::PADRE_RED,51 'block' => Px::PADRE_BLACK,52 'regex_block' => Px::PADRE_BLACK,53 'noun' => Px::PADRE_BLACK,54 'sigil' => Px::PADRE_GREEN,55 'variable' => Px::PADRE_GREEN, 56 'assertion' => Px::PADRE_GREEN,57 'quote' => Px::PADRE_MAGENTA,58 'number' => Px::PADRE_ORANGE,59 'infix' => Px::PADRE_DIM_GRAY,60 'methodop' => Px::PADRE_BLACK,61 'pod_comment' => Px::PADRE_GREEN,62 'param_var' => Px::PADRE_CRIMSON,63 '_scalar' => Px::PADRE_RED,64 '_array' => Px::PADRE_BROWN,65 '_hash' => Px::PADRE_ORANGE,66 '_comment' => Px::PADRE_GREEN,45 'comp_unit' => Px::PADRE_BLUE, 46 'scope_declarator' => Px::PADRE_RED, 47 'routine_declarator' => Px::PADRE_RED, 48 'regex_declarator' => Px::PADRE_RED, 49 'package_declarator' => Px::PADRE_RED, 50 'statement_control' => Px::PADRE_RED, 51 'block' => Px::PADRE_BLACK, 52 'regex_block' => Px::PADRE_BLACK, 53 'noun' => Px::PADRE_BLACK, 54 'sigil' => Px::PADRE_GREEN, 55 'variable' => Px::PADRE_GREEN, 56 'assertion' => Px::PADRE_GREEN, 57 'quote' => Px::PADRE_MAGENTA, 58 'number' => Px::PADRE_ORANGE, 59 'infix' => Px::PADRE_DIM_GRAY, 60 'methodop' => Px::PADRE_BLACK, 61 'pod_comment' => Px::PADRE_GREEN, 62 'param_var' => Px::PADRE_CRIMSON, 63 '_scalar' => Px::PADRE_RED, 64 '_array' => Px::PADRE_BROWN, 65 '_hash' => Px::PADRE_ORANGE, 66 '_comment' => Px::PADRE_GREEN, 67 67 ); 68 68 for my $htoken (@tokens) { … … 76 76 } 77 77 } 78 78 79 79 my $td = timediff(new Benchmark, $t0); 80 say "->colorize took:" . timestr($td) ; 80 say "->colorize took:" . timestr($td) ; 81 81 } 82 82 83 83 sub get_command { 84 my $self = shift; 85 86 my $filename = $self->filename; 84 my $self = shift; 87 85 88 if (not $ENV{PARROT_PATH}) { 89 die "PARROT_PATH is not defined. Need to point to trunk of Parrot SVN checkout.\n"; 90 } 91 my $parrot = File::Spec->catfile($ENV{PARROT_PATH}, 'parrot'); 92 if (not -x $parrot) { 93 die "$parrot is not an executable.\n"; 94 } 95 my $rakudo = File::Spec->catfile($ENV{PARROT_PATH}, 'languages', 'perl6', 'perl6.pbc'); 96 if (not -e $rakudo) { 97 die "Cannot find Rakudo ($rakudo)\n"; 98 } 86 my $filename = $self->filename; 99 87 100 return qq{"$parrot" "$rakudo" "$filename"}; 88 if (not $ENV{PARROT_PATH}) { 89 die "PARROT_PATH is not defined. Need to point to trunk of Parrot SVN checkout.\n"; 90 } 91 my $parrot = File::Spec->catfile($ENV{PARROT_PATH}, 'parrot'); 92 if (not -x $parrot) { 93 die "$parrot is not an executable.\n"; 94 } 95 my $rakudo = File::Spec->catfile($ENV{PARROT_PATH}, 'languages', 'perl6', 'perl6.pbc'); 96 if (not -e $rakudo) { 97 die "Cannot find Rakudo ($rakudo)\n"; 98 } 99 100 return qq{"$parrot" "$rakudo" "$filename"}; 101 101 102 102 } 103 103 104 104 sub keywords { 105 if (! defined $keywords) {106 $keywords = YAML::Tiny::LoadFile(107 Padre::Util::sharefile( 'languages', 'perl6', 'perl6.yml' )108 );109 }110 return $keywords;105 if (! defined $keywords) { 106 $keywords = YAML::Tiny::LoadFile( 107 Padre::Util::sharefile( 'languages', 'perl6', 'perl6.yml' ) 108 ); 109 } 110 return $keywords; 111 111 } 112 112 -
trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6.pm
r2152 r2153 28 28 29 29 sub padre_interfaces { 30 return 'Padre::Plugin' => 0.20,30 return 'Padre::Plugin' => 0.20, 31 31 } 32 32 33 33 34 34 sub menu_plugins_simple { 35 my $self = shift;36 return 'Perl 6' => [37 'Export Full HTML' => sub { $self->export_html($FULL_HTML); },38 'Export Simple HTML' => sub { $self->export_html($SIMPLE_HTML); },39 'Export Snippet HTML' => sub { $self->export_html($SNIPPET_HTML); },40 'About' => sub { $self->show_about },41 ];35 my $self = shift; 36 return 'Perl 6' => [ 37 'Export Full HTML' => sub { $self->export_html($FULL_HTML); }, 38 'Export Simple HTML' => sub { $self->export_html($SIMPLE_HTML); }, 39 'Export Snippet HTML' => sub { $self->export_html($SNIPPET_HTML); }, 40 'About' => sub { $self->show_about }, 41 ]; 42 42 } 43 43 44 44 sub registered_documents { 45 return 'application/x-perl6' => 'Padre::Document::Perl6',45 return 'application/x-perl6' => 'Padre::Document::Perl6', 46 46 } 47 47 48 48 49 49 sub show_about { 50 my ($main) = @ARG;50 my ($main) = @ARG; 51 51 52 my $about = Wx::AboutDialogInfo->new;53 $about->SetName("Padre::Plugin::Perl6");54 $about->SetDescription(55 "Perl6 syntax highlighting that is based on\nSyntax::Highlight::Perl6\n"56 );57 Wx::AboutBox( $about );58 return;52 my $about = Wx::AboutDialogInfo->new; 53 $about->SetName("Padre::Plugin::Perl6"); 54 $about->SetDescription( 55 "Perl6 syntax highlighting that is based on\nSyntax::Highlight::Perl6\n" 56 ); 57 Wx::AboutBox( $about ); 58 return; 59 59 } 60 60 61 61 sub export_html { 62 my ($self, $type) = @ARG;62 my ($self, $type) = @ARG; 63 63 64 if(!defined Padre::Documents->current) {65 return;66 }64 if(!defined Padre::Documents->current) { 65 return; 66 } 67 67 68 my $text = Padre::Documents->current->text_get() // '';68 my $text = Padre::Documents->current->text_get() // ''; 69 69 70 70 my $p = Syntax::Highlight::Perl6->new( 71 71 text => $text, 72 inline_resources => 1, 72 inline_resources => 1, 73 73 ); 74 74 75 75 my $html; 76 76 eval { 77 given($type) {78 when ($FULL_HTML) { $html = $p->full_html; }79 when ($SIMPLE_HTML) { $html = $p->simple_html; }80 when ($SNIPPET_HTML) { $html = $p->snippet_html; }81 default {82 croak "'$type' should full_html, simple_html or snippet_html";83 }84 }85 1;86 };77 given($type) { 78 when ($FULL_HTML) { $html = $p->full_html; } 79 when ($SIMPLE_HTML) { $html = $p->simple_html; } 80 when ($SNIPPET_HTML) { $html = $p->snippet_html; } 81 default { 82 croak "'$type' should full_html, simple_html or snippet_html"; 83 } 84 } 85 1; 86 }; 87 87 88 if($EVAL_ERROR) {89 say 'Parsing error, bye bye ->export_html';90 return;91 }88 if($EVAL_ERROR) { 89 say 'Parsing error, bye bye ->export_html'; 90 return; 91 } 92 92 93 # create a temporary HTML file94 my $tmp = File::Temp->new(SUFFIX => '.html');95 $tmp->unlink_on_destroy(0);96 my $filename = $tmp->filename;97 print $tmp $html;98 close $tmp99 or croak "Could not close $filename";93 # create a temporary HTML file 94 my $tmp = File::Temp->new(SUFFIX => '.html'); 95 $tmp->unlink_on_destroy(0); 96 my $filename = $tmp->filename; 97 print $tmp $html; 98 close $tmp 99 or croak "Could not close $filename"; 100 100 101 # try to open the HTML file102 my $main = Padre->ide->wx->main_window;103 $main->setup_editor($filename);101 # try to open the HTML file 102 my $main = Padre->ide->wx->main_window; 103 $main->setup_editor($filename); 104 104 105 # launch the HTML file in your default browser106 my $file_url = URI::file->new($filename);107 Wx::LaunchDefaultBrowser($file_url);108 105 # launch the HTML file in your default browser 106 my $file_url = URI::file->new($filename); 107 Wx::LaunchDefaultBrowser($file_url); 108 109 109 return; 110 110 }
Note: See TracChangeset
for help on using the changeset viewer.
