Changeset 2161
- Timestamp:
- 12/22/08 11:26:37 (3 years ago)
- Location:
- trunk/Padre-Plugin-Perl6/lib/Padre
- Files:
-
- 3 added
- 2 edited
-
Document/Perl6.pm (modified) (4 diffs)
-
Plugin/Perl6.pm (modified) (1 diff)
-
Task (added)
-
Task/SyntaxChecker (added)
-
Task/SyntaxChecker/Perl6.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre-Plugin-Perl6/lib/Padre/Document/Perl6.pm
r2155 r2161 14 14 our @ISA = 'Padre::Document'; 15 15 16 my $keywords; 17 my $issues = []; 16 sub text_with_one_nl { 17 my $self = shift; 18 my $text = $self->text_get; 19 my $nlchar = "\n"; 20 if ( $self->get_newline_type eq 'WIN' ) { 21 $nlchar = "\r\n"; 22 } 23 elsif ( $self->get_newline_type eq 'MAC' ) { 24 $nlchar = "\r"; 25 } 26 $text =~ s/$nlchar/\n/g; 27 return $text; 28 } 18 29 19 30 # Naive way to parse and colorize perl6 files … … 22 33 23 34 my $editor = $self->editor; 24 my $text = $self->text_ get;35 my $text = $self->text_with_one_nl; 25 36 26 37 my $t0 = Benchmark->new; … … 31 42 my @tokens; 32 43 eval { @tokens = $p->tokens; 1; }; 44 $self->{issues} = []; 33 45 if($EVAL_ERROR) { 34 46 say "Parsing error, bye bye ->colorize " . $EVAL_ERROR; 35 47 my @errors = split /\n/, $EVAL_ERROR; 36 my $lineno = -1; 37 my $error_msg = ""; 48 my $lineno = undef; 38 49 for my $error (@errors) { 39 if($error =~ / error.+line (\d+)/) {50 if($error =~ /line (\d+):$/) { 40 51 $lineno = $1; 41 $error_msg = $error; 52 } 53 if($lineno) { 54 push @{$self->{issues}}, { line => $lineno, msg => $error, severity => 'E', }; 42 55 } 43 56 } 44 # update errors45 $issues = [ { line => $lineno, msg => $error_msg, severity => 'E', desc => $EVAL_ERROR, } ];46 57 return; 47 } else { 48 # no errors... 49 $issues = []; 50 } 58 } 51 59 52 60 $self->remove_color; … … 113 121 } 114 122 123 # Checks the syntax of a Perl document. 124 # Documented in Padre::Document! 125 # Implemented as a task. See Padre::Task::SyntaxChecker::Perl6 115 126 sub check_syntax { 127 my $self = shift; 128 my %args = @ARG; 129 $args{background} = 0; 130 return $self->_check_syntax_internals(\%args); 131 } 132 133 sub check_syntax_in_background { 134 my $self = shift; 135 my %args = @ARG; 136 $args{background} = 1; 137 return $self->_check_syntax_internals(\%args); 138 } 139 140 sub _check_syntax_internals { 116 141 my $self = shift; 117 return $self->_check_syntax_internal; 118 } 119 120 sub check_syntax_in_background { 142 my $args = shift; 143 144 my $text = $self->text_with_one_nl; 145 unless ( defined $text and $text ne '' ) { 146 return []; 147 } 148 149 # Do we really need an update? 150 require Digest::MD5; 151 use Encode qw(encode_utf8); 152 my $md5 = Digest::MD5::md5(encode_utf8($text)); 153 unless ( $args->{force} ) { 154 if ( defined( $self->{last_checked_md5} ) 155 && $self->{last_checked_md5} eq $md5 156 ) { 157 return; 158 } 159 } 160 $self->{last_checked_md5} = $md5; 161 162 require Padre::Task::SyntaxChecker::Perl6; 163 my $task = Padre::Task::SyntaxChecker::Perl6->new( 164 notebook_page => $self->editor, 165 text => $text, 166 issues => $self->{issues}, 167 ( exists $args->{on_finish} ? (on_finish => $args->{on_finish}) : () ), 168 ); 169 if ($args->{background}) { 170 # asynchroneous execution (see on_finish hook) 171 $task->schedule(); 172 return(); 173 } 174 else { 175 # serial execution, returning the result 176 return() if $task->prepare() =~ /^break$/; 177 $task->run(); 178 return $task->{syntax_check}; 179 } 180 return; 181 } 182 183 sub keywords { 121 184 my $self = shift; 122 return $self->_check_syntax_internal; 123 } 124 125 sub _check_syntax_internal { 126 my $self = shift; 127 return $issues; 128 } 129 130 sub keywords { 131 if (! defined $keywords) { 132 $keywords = YAML::Tiny::LoadFile( 185 if (! defined $self->{keywords}) { 186 $self->{keywords} = YAML::Tiny::LoadFile( 133 187 Padre::Util::sharefile( 'languages', 'perl6', 'perl6.yml' ) 134 188 ); 135 189 } 136 return $ keywords;190 return $self->{keywords}; 137 191 } 138 192 -
trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6.pm
r2153 r2161 59 59 } 60 60 61 sub text_with_one_nl { 62 my $self = shift; 63 my $doc = shift; 64 my $text = $doc->text_get // ''; 65 66 my $nlchar = "\n"; 67 if ( $doc->get_newline_type eq 'WIN' ) { 68 $nlchar = "\r\n"; 69 } 70 elsif ( $doc->get_newline_type eq 'MAC' ) { 71 $nlchar = "\r"; 72 } 73 $text =~ s/$nlchar/\n/g; 74 return $text; 75 } 76 61 77 sub export_html { 62 78 my ($self, $type) = @ARG; 63 79 64 if(!defined Padre::Documents->current) { 80 my $doc = Padre::Documents->current; 81 if(!defined $doc) { 65 82 return; 66 83 } 67 68 my $text = Padre::Documents->current->text_get() // ''; 69 84 if($doc->get_mimetype ne q{application/x-perl6}) { 85 return; 86 } 87 88 my $text = $self->text_with_one_nl($doc); 70 89 my $p = Syntax::Highlight::Perl6->new( 71 90 text => $text,
Note: See TracChangeset
for help on using the changeset viewer.
