1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
package Tk::CodeText::Xresources;
use vars qw($VERSION);
$VERSION = '0.2';
use strict;
use base('Tk::CodeText::Template');
sub new {
my ($proto, $rules) = @_;
my $class = ref($proto) || $proto;
if (not defined($rules)) {
$rules = [
['Comment', -foreground => 'lightblue'],
['Path', -foreground => 'brown'],
['Command', -foreground => 'blue'],
['Separator', -foreground => 'darkblue'],
['Value', -foreground => 'orange'],
['False', -foreground => 'red'],
];
};
my $self = $class->SUPER::new($rules);
bless ($self, $class);
return $self;
}
sub highlight {
my ($hlt, $in) = @_;
$hlt->snippet('');
my $out = $hlt->out;
@$out = ();
if ($in =~ /^(\s+!|!)/g) {
$hlt->snippet($in);
$hlt->tokenParse('Comment');
} elsif ($in =~ /^(\s+#|#)/g) {
$hlt->snippet($in);
$hlt->tokenParse('Command');
} elsif ($in =~ /([^:]+)(:)([^:]+)/g) {
$hlt->snippet($1);
$hlt->tokenParse('Path');
$hlt->snippet($2);
$hlt->tokenParse('Separator');
$hlt->snippet($3);
$hlt->tokenParse('Value');
} else {
$hlt->snippet($in);
$hlt->tokenParse('False');
}
return @$out;
}
sub syntax {
my $hlt = shift;
return 'Xresources';
}
1;
__END__
=head1 NAME
Tk::CodeText::Xresources - a Plugin for xresources files syntax highlighting
=head1 SYNOPSIS
require Tk::CodeText::Xresources;
my $sh = new Tk::CodeText::Xresources([
['Comment', -foreground => 'lightblue'],
['Path', -foreground => 'brown'],
['Command', -foreground => 'blue'],
['Separator', -foreground => 'darkblue'],
['Value', -foreground => 'orange'],
['False', -foreground => 'red'],
]);
=head1 DESCRIPTION
Tk::CodeText::Xresources is a plugin module that provides syntax highlighting
for xresources files to a Tk::CodeText text widget.
It inherits Tk::CodeText::Template. See also there.
=head1 METHODS
=over 4
=item B<highlight>(I<$string>);
returns a list of string snippets and tags that can be inserted
in a Tk::Text like widget instantly.
=cut
=head1 AUTHOR
Hans Jeuken (haje@toneel.demon.nl)
=cut
=head1 BUGS
Unknown
=cut
|