Syntax-Highlight-Engine-Kate-0.14/ 0000755 0001750 0001750 00000000000 13226471445 016262 5 ustar manwar manwar Syntax-Highlight-Engine-Kate-0.14/.travis.yml 0000644 0001750 0001750 00000000172 13032300413 020350 0 ustar manwar manwar branches:
except:
- gh-pages
language: perl
perl:
- "5.20"
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- "5.10"
Syntax-Highlight-Engine-Kate-0.14/t/ 0000755 0001750 0001750 00000000000 13226471445 016525 5 ustar manwar manwar Syntax-Highlight-Engine-Kate-0.14/t/perl_todo.t 0000644 0001750 0001750 00000003410 13032300413 020654 0 ustar manwar manwar use strict;
use warnings;
use Test::More;
use Test::Differences;
use lib 't/lib';
use TestHighlight 'highlight_perl';
plan tests => 2;
# https://rt.cpan.org/Ticket/Display.html?id=76182
my $underscore_bug = <<'END';
my
$underscore_bug
=
10_000
;
END
my $want = <<'END';
my
$underscore_bug
=
10_100
;
END
my $have = highlight_perl($underscore_bug);
TODO: {
local $TODO = 'Kate does not yet handle numbers with underscores (10_000)';
eq_or_diff $have, $want, 'Numbers with underscores should parse correctly';
}
# https://rt.cpan.org/Ticket/Display.html?id=76168
my $heredoc_bug = <<'END';
my $heredoc_bug = <<'HEY';
We be here
HEY! <-- this is not the terminator
and here
HEY
END
$have = highlight_perl($heredoc_bug);
$want = <<'END';
my $heredoc_bug = <<'HEY';
We be here
HEY! <-- this is not the terminator
and here
HEY
END
TODO: {
local $TODO = 'Kate sometimes guesses the heredoc terminator incorrectly';
eq_or_diff $have, $want, 'heredocs should parse correctly';
}
__END__
#!/usr/bin/env perl
my $heredoc_bug = <<'HEY';
We be here
HEY! <-- this is not the terminator
and here
HEY
# https://rt.cpan.org/Ticket/Display.html?id=76160
=head1 BORKED
All Perl code after this was considered a "comment" and Kate could not
highlight it correctly.
=cut
my $this_is_not_a_comment = 'or a pipe';
Syntax-Highlight-Engine-Kate-0.14/t/perl/ 0000755 0001750 0001750 00000000000 13226471445 017467 5 ustar manwar manwar Syntax-Highlight-Engine-Kate-0.14/t/perl/before/ 0000755 0001750 0001750 00000000000 13226471445 020731 5 ustar manwar manwar Syntax-Highlight-Engine-Kate-0.14/t/perl/before/maze.pl 0000644 0001750 0001750 00000007073 13032300413 022206 0 ustar manwar manwar #!perl
use strict;
use warnings;
use diagnostics;
use List::Util 'shuffle';
# The size of the maze. Take the arguments from the command line or from the
# default.
my ( $HEIGHT, $WIDTH ) = @ARGV ? @ARGV : ( 20, 20 );
# Time::HiRes was officially released with Perl 5.8.0, though Module::Corelist
# reports that it was actually released as early as v5.7.3. If you don't have
# this module, your version of Perl is probably over a decade old
use Time::HiRes 'usleep';
# In Perl, $^O is the name of your operating system. On Windows (as of this
# writing), it always 'MSWin32'.
use constant IS_WIN32 => 'MSWin32' eq $^O;
# On Windows, we assume that the command to clear the screen is 'cls'. On all
# other systems, we assume it's 'clear'. You may need to adjust this.
use constant CLEAR => IS_WIN32 ? 'cls' : 'clear';
# We will only redraw the screen (and thus show the recursive maze generation)
# if and only if the system is capable of clearing the screen. The system()
# command returns 0 upon success. See perldoc -f system.
# The following line works because $x == $y returns a boolean value.
#use constant CAN_REDRAW => 0 == system(CLEAR);
use constant CAN_REDRAW => 0;
# Time in microseconds between screen redraws. See Time::HiRes and the usleep
# function
use constant DELAY => 10_000;
use constant OPPOSITE_OF => {
north => 'south',
south => 'north',
west => 'east',
east => 'west',
};
my @maze;
tunnel( 0, 0, \@maze );
my $num = 10_000;
system(CLEAR) if CAN_REDRAW;
print render_maze( \@maze );
exit;
sub tunnel {
my ( $x, $y, $maze ) = @_;
if (CAN_REDRAW) {
my $render = render_maze($maze);
system(CLEAR);
print $render;
usleep DELAY;
}
# Here we need to use a unary plus in front of OPPOSITE_OF so that
# Perl understands that this is a constant and that we're not trying
# to access the %OPPOSITE_OF variable.
my @directions = shuffle keys %{ +OPPOSITE_OF };
foreach my $direction (@directions) {
my ( $new_x, $new_y ) = ( $x, $y );
if ( 'east' eq $direction ) { $new_x += 1; }
elsif ( 'west' eq $direction ) { $new_x -= 1; }
elsif ( 'south' eq $direction ) { $new_y += 1; }
else { $new_y -= 1; }
if ( have_not_visited( $new_x, $new_y, $maze ) ) {
$maze->[$y][$x]{$direction} = 1;
$maze->[$new_y][$new_x]{ OPPOSITE_OF->{$direction} } = 1;
# This program will often recurse more than one hundred levels
# deep and this is Perl's default recursion depth level prior to
# issuing warnings. In this case, we're telling Perl that we know
# that we'll exceed the recursion depth and to now warn us about
# it
no warnings 'recursion';
tunnel( $new_x, $new_y, $maze );
}
}
}
sub have_not_visited {
my ( $x, $y, $maze ) = @_;
# the first two lines return false if we're out of bounds
return if $x < 0 or $y < 0;
return if $x > $WIDTH - 1 or $y > $HEIGHT - 1;
# this returns false if we've already visited this cell
return if $maze->[$y][$x];
# return true
return 1;
}
sub render_maze {
my $maze = shift;
my $as_string = "_" x ( 1 + $WIDTH * 2 );
$as_string .= "\n";
for my $y ( 0 .. $HEIGHT - 1 ) {
$as_string .= "|";
for my $x ( 0 .. $WIDTH - 1 ) {
my $cell = $maze->[$y][$x];
$as_string .= $cell->{south} ? " " : "_";
$as_string .= $cell->{east} ? " " : "|";
}
$as_string .= "\n";
}
return $as_string;
}
Syntax-Highlight-Engine-Kate-0.14/t/perl/before/kate.pl 0000755 0001750 0001750 00000073411 13032300413 022200 0 ustar manwar manwar
# Copyright (c) 2006 Hans Jeuken. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Syntax::Highlight::Engine::Kate;
use 5.006;
our $VERSION = '0.06';
use strict;
use warnings;
use Carp;
use Data::Dumper;
use File::Basename;
use base('Syntax::Highlight::Engine::Kate::Template');
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = (@_);
my $add = delete $args{'plugins'};
unless (defined($add)) { $add = [] };
my $language = delete $args{'language'};
unless (defined($language)) { $language = 'Off' };
my $self = $class->SUPER::new(%args);
$self->{'plugins'} = {};
#begin autoinsert
$self->{'extensions'} = {
' *.cls' => ['LaTeX', ],
' *.dtx' => ['LaTeX', ],
' *.ltx' => ['LaTeX', ],
' *.sty' => ['LaTeX', ],
'*.4GL' => ['4GL', ],
'*.4gl' => ['4GL', ],
'*.ABC' => ['ABC', ],
'*.ASM' => ['AVR Assembler', 'PicAsm', ],
'*.BAS' => ['FreeBASIC', ],
'*.BI' => ['FreeBASIC', ],
'*.C' => ['C++', 'C', 'ANSI C89', ],
'*.D' => ['D', ],
'*.F' => ['Fortran', ],
'*.F90' => ['Fortran', ],
'*.F95' => ['Fortran', ],
'*.FOR' => ['Fortran', ],
'*.FPP' => ['Fortran', ],
'*.GDL' => ['GDL', ],
'*.H' => ['C++', ],
'*.JSP' => ['JSP', ],
'*.LOGO' => ['de_DE', 'en_US', 'nl', ],
'*.LY' => ['LilyPond', ],
'*.Logo' => ['de_DE', 'en_US', 'nl', ],
'*.M' => ['Matlab', 'Octave', ],
'*.MAB' => ['MAB-DB', ],
'*.Mab' => ['MAB-DB', ],
'*.PER' => ['4GL-PER', ],
'*.PIC' => ['PicAsm', ],
'*.PRG' => ['xHarbour', 'Clipper', ],
'*.R' => ['R Script', ],
'*.S' => ['GNU Assembler', ],
'*.SQL' => ['SQL', 'SQL (MySQL)', 'SQL (PostgreSQL)', ],
'*.SRC' => ['PicAsm', ],
'*.V' => ['Verilog', ],
'*.VCG' => ['GDL', ],
'*.a' => ['Ada', ],
'*.abc' => ['ABC', ],
'*.ada' => ['Ada', ],
'*.adb' => ['Ada', ],
'*.ado' => ['Stata', ],
'*.ads' => ['Ada', ],
'*.ahdl' => ['AHDL', ],
'*.ai' => ['PostScript', ],
'*.ans' => ['Ansys', ],
'*.asm' => ['AVR Assembler', 'Asm6502', 'Intel x86 (NASM)', 'PicAsm', ],
'*.asm-avr' => ['AVR Assembler', ],
'*.asp' => ['ASP', ],
'*.awk' => ['AWK', ],
'*.bas' => ['FreeBASIC', ],
'*.basetest' => ['BaseTest', ],
'*.bash' => ['Bash', ],
'*.bi' => ['FreeBASIC', ],
'*.bib' => ['BibTeX', ],
'*.bro' => ['Component-Pascal', ],
'*.c' => ['C', 'ANSI C89', 'LPC', ],
'*.c++' => ['C++', ],
'*.cc' => ['C++', ],
'*.cfc' => ['ColdFusion', ],
'*.cfg' => ['Quake Script', ],
'*.cfm' => ['ColdFusion', ],
'*.cfml' => ['ColdFusion', ],
'*.cg' => ['Cg', ],
'*.cgis' => ['CGiS', ],
'*.ch' => ['xHarbour', 'Clipper', ],
'*.cis' => ['Cisco', ],
'*.cl' => ['Common Lisp', ],
'*.cmake' => ['CMake', ],
'*.config' => ['Logtalk', ],
'*.cp' => ['Component-Pascal', ],
'*.cpp' => ['C++', ],
'*.cs' => ['C#', ],
'*.css' => ['CSS', ],
'*.cue' => ['CUE Sheet', ],
'*.cxx' => ['C++', ],
'*.d' => ['D', ],
'*.daml' => ['XML', ],
'*.dbm' => ['ColdFusion', ],
'*.def' => ['Modula-2', ],
'*.desktop' => ['.desktop', ],
'*.diff' => ['Diff', ],
'*.do' => ['Stata', ],
'*.docbook' => ['XML', ],
'*.dox' => ['Doxygen', ],
'*.doxygen' => ['Doxygen', ],
'*.e' => ['E Language', 'Eiffel', 'Euphoria', ],
'*.ebuild' => ['Bash', ],
'*.eclass' => ['Bash', ],
'*.eml' => ['Email', ],
'*.eps' => ['PostScript', ],
'*.err' => ['4GL', ],
'*.ex' => ['Euphoria', ],
'*.exu' => ['Euphoria', ],
'*.exw' => ['Euphoria', ],
'*.f' => ['Fortran', ],
'*.f90' => ['Fortran', ],
'*.f95' => ['Fortran', ],
'*.fe' => ['ferite', ],
'*.feh' => ['ferite', ],
'*.flex' => ['Lex/Flex', ],
'*.for' => ['Fortran', ],
'*.fpp' => ['Fortran', ],
'*.frag' => ['GLSL', ],
'*.gdl' => ['GDL', ],
'*.glsl' => ['GLSL', ],
'*.guile' => ['Scheme', ],
'*.h' => ['C++', 'C', 'ANSI C89', 'Inform', 'LPC', 'Objective-C', ],
'*.h++' => ['C++', ],
'*.hcc' => ['C++', ],
'*.hpp' => ['C++', ],
'*.hs' => ['Haskell', ],
'*.hsp' => ['Spice', ],
'*.ht' => ['Apache Configuration', ],
'*.htm' => ['HTML', ],
'*.html' => ['HTML', 'Mason', ],
'*.hxx' => ['C++', ],
'*.i' => ['progress', ],
'*.idl' => ['IDL', ],
'*.inc' => ['POV-Ray', 'PHP (HTML)', 'LPC', ],
'*.inf' => ['Inform', ],
'*.ini' => ['INI Files', ],
'*.java' => ['Java', ],
'*.js' => ['JavaScript', ],
'*.jsp' => ['JSP', ],
'*.katetemplate' => ['Kate File Template', ],
'*.kbasic' => ['KBasic', ],
'*.kdelnk' => ['.desktop', ],
'*.l' => ['Lex/Flex', ],
'*.ldif' => ['LDIF', ],
'*.lex' => ['Lex/Flex', ],
'*.lgo' => ['de_DE', 'en_US', 'nl', ],
'*.lgt' => ['Logtalk', ],
'*.lhs' => ['Literate Haskell', ],
'*.lisp' => ['Common Lisp', ],
'*.logo' => ['de_DE', 'en_US', 'nl', ],
'*.lsp' => ['Common Lisp', ],
'*.lua' => ['Lua', ],
'*.ly' => ['LilyPond', ],
'*.m' => ['Matlab', 'Objective-C', 'Octave', ],
'*.m3u' => ['M3U', ],
'*.mab' => ['MAB-DB', ],
'*.md' => ['Modula-2', ],
'*.mi' => ['Modula-2', ],
'*.ml' => ['Objective Caml', 'SML', ],
'*.mli' => ['Objective Caml', ],
'*.moc' => ['C++', ],
'*.mod' => ['Modula-2', ],
'*.mup' => ['Music Publisher', ],
'*.not' => ['Music Publisher', ],
'*.o' => ['LPC', ],
'*.octave' => ['Octave', ],
'*.p' => ['Pascal', 'progress', ],
'*.pas' => ['Pascal', ],
'*.pb' => ['PureBasic', ],
'*.per' => ['4GL-PER', ],
'*.per.err' => ['4GL-PER', ],
'*.php' => ['PHP (HTML)', ],
'*.php3' => ['PHP (HTML)', ],
'*.phtm' => ['PHP (HTML)', ],
'*.phtml' => ['PHP (HTML)', ],
'*.pic' => ['PicAsm', ],
'*.pike' => ['Pike', ],
'*.pl' => ['Perl', ],
'*.pls' => ['INI Files', ],
'*.pm' => ['Perl', ],
'*.po' => ['GNU Gettext', ],
'*.pot' => ['GNU Gettext', ],
'*.pov' => ['POV-Ray', ],
'*.pp' => ['Pascal', ],
'*.prg' => ['xHarbour', 'Clipper', ],
'*.pro' => ['RSI IDL', ],
'*.prolog' => ['Prolog', ],
'*.ps' => ['PostScript', ],
'*.py' => ['Python', ],
'*.pyw' => ['Python', ],
'*.rb' => ['Ruby', ],
'*.rc' => ['XML', ],
'*.rdf' => ['XML', ],
'*.reg' => ['WINE Config', ],
'*.rex' => ['REXX', ],
'*.rib' => ['RenderMan RIB', ],
'*.s' => ['GNU Assembler', 'MIPS Assembler', ],
'*.sa' => ['Sather', ],
'*.sce' => ['scilab', ],
'*.scheme' => ['Scheme', ],
'*.sci' => ['scilab', ],
'*.scm' => ['Scheme', ],
'*.sgml' => ['SGML', ],
'*.sh' => ['Bash', ],
'*.shtm' => ['HTML', ],
'*.shtml' => ['HTML', ],
'*.siv' => ['Sieve', ],
'*.sml' => ['SML', ],
'*.sp' => ['Spice', ],
'*.spec' => ['RPM Spec', ],
'*.sql' => ['SQL', 'SQL (MySQL)', 'SQL (PostgreSQL)', ],
'*.src' => ['PicAsm', ],
'*.ss' => ['Scheme', ],
'*.t2t' => ['txt2tags', ],
'*.tcl' => ['Tcl/Tk', ],
'*.tdf' => ['AHDL', ],
'*.tex' => ['LaTeX', ],
'*.tji' => ['TaskJuggler', ],
'*.tjp' => ['TaskJuggler', ],
'*.tk' => ['Tcl/Tk', ],
'*.tst' => ['BaseTestchild', ],
'*.uc' => ['UnrealScript', ],
'*.v' => ['Verilog', ],
'*.vcg' => ['GDL', ],
'*.vert' => ['GLSL', ],
'*.vhd' => ['VHDL', ],
'*.vhdl' => ['VHDL', ],
'*.vl' => ['Verilog', ],
'*.vm' => ['Velocity', ],
'*.w' => ['progress', ],
'*.wml' => ['PHP (HTML)', ],
'*.wrl' => ['VRML', ],
'*.xml' => ['XML', ],
'*.xsl' => ['xslt', ],
'*.xslt' => ['xslt', ],
'*.y' => ['Yacc/Bison', ],
'*.ys' => ['yacas', ],
'*Makefile*' => ['Makefile', ],
'*makefile*' => ['Makefile', ],
'*patch' => ['Diff', ],
'CMakeLists.txt' => ['CMake', ],
'ChangeLog' => ['ChangeLog', ],
'QRPGLESRC.*' => ['ILERPG', ],
'apache.conf' => ['Apache Configuration', ],
'apache2.conf' => ['Apache Configuration', ],
'httpd.conf' => ['Apache Configuration', ],
'httpd2.conf' => ['Apache Configuration', ],
'xorg.conf' => ['x.org Configuration', ],
};
$self->{'sections'} = {
'Assembler' => [
'AVR Assembler',
'Asm6502',
'GNU Assembler',
'Intel x86 (NASM)',
'MIPS Assembler',
'PicAsm',
],
'Configuration' => [
'.desktop',
'Apache Configuration',
'Cisco',
'INI Files',
'WINE Config',
'x.org Configuration',
],
'Database' => [
'4GL',
'4GL-PER',
'LDIF',
'SQL',
'SQL (MySQL)',
'SQL (PostgreSQL)',
'progress',
],
'Hardware' => [
'AHDL',
'Spice',
'VHDL',
'Verilog',
],
'Logo' => [
'de_DE',
'en_US',
'nl',
],
'Markup' => [
'ASP',
'BibTeX',
'CSS',
'ColdFusion',
'Doxygen',
'GNU Gettext',
'HTML',
'JSP',
'Javadoc',
'Kate File Template',
'LaTeX',
'MAB-DB',
'PostScript',
'SGML',
'VRML',
'Wikimedia',
'XML',
'txt2tags',
'xslt',
],
'Other' => [
'ABC',
'Alerts',
'CMake',
'CSS/PHP',
'CUE Sheet',
'ChangeLog',
'Debian Changelog',
'Debian Control',
'Diff',
'Email',
'JavaScript/PHP',
'LilyPond',
'M3U',
'Makefile',
'Music Publisher',
'POV-Ray',
'RPM Spec',
'RenderMan RIB',
],
'Scientific' => [
'GDL',
'Matlab',
'Octave',
'TI Basic',
'scilab',
],
'Script' => [
'Ansys',
],
'Scripts' => [
'AWK',
'Bash',
'Common Lisp',
'Euphoria',
'JavaScript',
'Lua',
'Mason',
'PHP (HTML)',
'PHP/PHP',
'Perl',
'Pike',
'Python',
'Quake Script',
'R Script',
'REXX',
'Ruby',
'Scheme',
'Sieve',
'TaskJuggler',
'Tcl/Tk',
'UnrealScript',
'Velocity',
'ferite',
],
'Sources' => [
'ANSI C89',
'Ada',
'C',
'C#',
'C++',
'CGiS',
'Cg',
'Clipper',
'Component-Pascal',
'D',
'E Language',
'Eiffel',
'Fortran',
'FreeBASIC',
'GLSL',
'Haskell',
'IDL',
'ILERPG',
'Inform',
'Java',
'KBasic',
'LPC',
'Lex/Flex',
'Literate Haskell',
'Logtalk',
'Modula-2',
'Objective Caml',
'Objective-C',
'Pascal',
'Prolog',
'PureBasic',
'RSI IDL',
'SML',
'Sather',
'Stata',
'Yacc/Bison',
'xHarbour',
'yacas',
],
'Test' => [
'BaseTest',
'BaseTestchild',
],
};
$self->{'syntaxes'} = {
'.desktop' => 'Desktop',
'4GL' => 'FourGL',
'4GL-PER' => 'FourGLminusPER',
'ABC' => 'ABC',
'AHDL' => 'AHDL',
'ANSI C89' => 'ANSI_C89',
'ASP' => 'ASP',
'AVR Assembler' => 'AVR_Assembler',
'AWK' => 'AWK',
'Ada' => 'Ada',
'Alerts' => 'Alerts',
'Ansys' => 'Ansys',
'Apache Configuration' => 'Apache_Configuration',
'Asm6502' => 'Asm6502',
'BaseTest' => 'BaseTest',
'BaseTestchild' => 'BaseTestchild',
'Bash' => 'Bash',
'BibTeX' => 'BibTeX',
'C' => 'C',
'C#' => 'Cdash',
'C++' => 'Cplusplus',
'CGiS' => 'CGiS',
'CMake' => 'CMake',
'CSS' => 'CSS',
'CSS/PHP' => 'CSS_PHP',
'CUE Sheet' => 'CUE_Sheet',
'Cg' => 'Cg',
'ChangeLog' => 'ChangeLog',
'Cisco' => 'Cisco',
'Clipper' => 'Clipper',
'ColdFusion' => 'ColdFusion',
'Common Lisp' => 'Common_Lisp',
'Component-Pascal' => 'ComponentminusPascal',
'D' => 'D',
'Debian Changelog' => 'Debian_Changelog',
'Debian Control' => 'Debian_Control',
'Diff' => 'Diff',
'Doxygen' => 'Doxygen',
'E Language' => 'E_Language',
'Eiffel' => 'Eiffel',
'Email' => 'Email',
'Euphoria' => 'Euphoria',
'Fortran' => 'Fortran',
'FreeBASIC' => 'FreeBASIC',
'GDL' => 'GDL',
'GLSL' => 'GLSL',
'GNU Assembler' => 'GNU_Assembler',
'GNU Gettext' => 'GNU_Gettext',
'HTML' => 'HTML',
'Haskell' => 'Haskell',
'IDL' => 'IDL',
'ILERPG' => 'ILERPG',
'INI Files' => 'INI_Files',
'Inform' => 'Inform',
'Intel x86 (NASM)' => 'Intel_x86_NASM',
'JSP' => 'JSP',
'Java' => 'Java',
'JavaScript' => 'JavaScript',
'JavaScript/PHP' => 'JavaScript_PHP',
'Javadoc' => 'Javadoc',
'KBasic' => 'KBasic',
'Kate File Template' => 'Kate_File_Template',
'LDIF' => 'LDIF',
'LPC' => 'LPC',
'LaTeX' => 'LaTeX',
'Lex/Flex' => 'Lex_Flex',
'LilyPond' => 'LilyPond',
'Literate Haskell' => 'Literate_Haskell',
'Logtalk' => 'Logtalk',
'Lua' => 'Lua',
'M3U' => 'M3U',
'MAB-DB' => 'MABminusDB',
'MIPS Assembler' => 'MIPS_Assembler',
'Makefile' => 'Makefile',
'Mason' => 'Mason',
'Matlab' => 'Matlab',
'Modula-2' => 'Modulaminus2',
'Music Publisher' => 'Music_Publisher',
'Objective Caml' => 'Objective_Caml',
'Objective-C' => 'ObjectiveminusC',
'Octave' => 'Octave',
'PHP (HTML)' => 'PHP_HTML',
'PHP/PHP' => 'PHP_PHP',
'POV-Ray' => 'POVminusRay',
'Pascal' => 'Pascal',
'Perl' => 'Perl',
'PicAsm' => 'PicAsm',
'Pike' => 'Pike',
'PostScript' => 'PostScript',
'Prolog' => 'Prolog',
'PureBasic' => 'PureBasic',
'Python' => 'Python',
'Quake Script' => 'Quake_Script',
'R Script' => 'R_Script',
'REXX' => 'REXX',
'RPM Spec' => 'RPM_Spec',
'RSI IDL' => 'RSI_IDL',
'RenderMan RIB' => 'RenderMan_RIB',
'Ruby' => 'Ruby',
'SGML' => 'SGML',
'SML' => 'SML',
'SQL' => 'SQL',
'SQL (MySQL)' => 'SQL_MySQL',
'SQL (PostgreSQL)' => 'SQL_PostgreSQL',
'Sather' => 'Sather',
'Scheme' => 'Scheme',
'Sieve' => 'Sieve',
'Spice' => 'Spice',
'Stata' => 'Stata',
'TI Basic' => 'TI_Basic',
'TaskJuggler' => 'TaskJuggler',
'Tcl/Tk' => 'Tcl_Tk',
'UnrealScript' => 'UnrealScript',
'VHDL' => 'VHDL',
'VRML' => 'VRML',
'Velocity' => 'Velocity',
'Verilog' => 'Verilog',
'WINE Config' => 'WINE_Config',
'Wikimedia' => 'Wikimedia',
'XML' => 'XML',
'Yacc/Bison' => 'Yacc_Bison',
'de_DE' => 'De_DE',
'en_US' => 'En_US',
'ferite' => 'Ferite',
'nl' => 'Nl',
'progress' => 'Progress',
'scilab' => 'Scilab',
'txt2tags' => 'Txt2tags',
'x.org Configuration' => 'Xorg_Configuration',
'xHarbour' => 'XHarbour',
'xslt' => 'Xslt',
'yacas' => 'Yacas',
};
#end autoinsert
$self->{'language '} = '';
bless ($self, $class);
if ($language ne '') {
$self->language($language);
}
return $self;
}
sub extensions {
my $self = shift;
return $self->{'extensions'};
}
#overriding Template's initialize method. now it should not do anything.
sub initialize {
my $cw = shift;
}
sub language {
my $self = shift;
if (@_) {
$self->{'language'} = shift;
$self->reset;
}
return $self->{'language'};
}
sub languageAutoSet {
my ($self, $file) = @_;
my $lang = $self->languagePropose($file);
if (defined $lang) {
$self->language($lang)
} else {
$self->language('Off')
}
}
sub languageList {
my $self = shift;
my $l = $self->{'syntaxes'};
return sort {uc($a) cmp uc($b)} keys %$l;
}
sub languagePropose {
my ($self, $file) = @_;
my $hsh = $self->extensions;
foreach my $key (keys %$hsh) {
my $reg = $key;
$reg =~ s/\./\\./g;
$reg =~ s/\+/\\+/g;
$reg =~ s/\*/.*/g;
$reg = "$reg\$";
if ($file =~ /$reg/) {
return $hsh->{$key}->[0]
}
}
return undef;
}
sub languagePlug {
my ($self, $req) = @_;
unless (exists($self->{'syntaxes'}->{$req})) {
warn "undefined language: $req";
return undef;
}
return $self->{'syntaxes'}->{$req};
}
sub reset {
my $self = shift;
my $lang = $self->language;
if ($lang eq 'Off') {
$self->stack([]);
} else {
my $plug = $self->pluginGet($lang);
my $basecontext = $plug->basecontext;
$self->stack([
[$plug, $basecontext]
]);
}
$self->out([]);
$self->snippet('');
}
sub sections {
my $self = shift;
return $self->{'sections'};
}
sub syntaxes {
my $self = shift;
return $self->{'syntaxes'}
}
1;
__END__
=head1 NAME
Syntax::Highlight::Engine::Kate - a port to Perl of the syntax highlight engine of the Kate texteditor.
=head1 SYNOPSIS
#if you want to create a compiled executable, you may want to do this:
use Syntax::Highlight::Engine::Kate::All;
use Syntax::Highlight::Engine::Kate;
my $hl = new Syntax::Highlight::Engine::Kate(
language => 'Perl',
substitutions => {
"<" => "<",
">" => ">",
"&" => "&",
" " => " ",
"\t" => " ",
"\n" => "
\n",
},
format_table => {
Alert => ["", ""],
BaseN => ["", ""],
BString => ["", ""],
Char => ["", ""],
Comment => ["", ""],
DataType => ["", ""],
DecVal => ["", ""],
Error => ["", ""],
Float => ["", ""],
Function => ["", ""],
IString => ["", ""],
Keyword => ["", ""],
Normal => ["", ""],
Operator => ["", ""],
Others => ["", ""],
RegionMarker => ["", ""],
Reserved => ["", ""],
String => ["", ""],
Variable => ["", ""],
Warning => ["", ""],
},
);
#or
my $hl = new Syntax::Highlight::Engine::Kate::Perl(
substitutions => {
"<" => "<",
">" => ">",
"&" => "&",
" " => " ",
"\t" => " ",
"\n" => "
\n",
},
format_table => {
Alert => ["", ""],
BaseN => ["", ""],
BString => ["", ""],
Char => ["", ""],
Comment => ["", ""],
DataType => ["", ""],
DecVal => ["", ""],
Error => ["", ""],
Float => ["", ""],
Function => ["", ""],
IString => ["", ""],
Keyword => ["", ""],
Normal => ["", ""],
Operator => ["", ""],
Others => ["", ""],
RegionMarker => ["", ""],
Reserved => ["", ""],
String => ["", ""],
Variable => ["", ""],
Warning => ["", ""],
},
);
print "\n\n\n\n";
while (my $in = <>) {
print $hl->highlightText($in);
}
print "\n\n";
=head1 DESCRIPTION
Syntax::Highlight::Engine::Kate is a port to perl of the syntax highlight engine of the
Kate text editor.
The language xml files of kate have been rewritten to perl modules using a script. These modules
function as plugins to this module.
Syntax::Highlight::Engine::Kate inherits Syntax::Highlight::Engine::Kate::Template.
=head1 OPTIONS
=over 4
=item B
Specify the language you want highlighted.
look in the B section for supported languages.
=item B
If you created your own language plugins you may specify a list of them with this option.
plugins => [
["MyModuleName", "MyLanguageName", "*,ext1;*.ext2", "Section"],
....
]
=item B
This option must be specified if the B method needs to do anything useful for you.
All mentioned keys in the synopsis must be specified.
=item B
With this option you can specify additional formatting options.
=back
=head1 METHODS
=over 4
=item B
returns a reference to the extensions hash,
=item B(I$language?>)
Sets and returns the current language that is highlighted. when setting the language a reset is also done.
=item B(I<$filename>);
Suggests language name for the fiven file B<$filename>
=item B
returns a list of languages for which plugins have been defined.
=item B(I<$language>);
returns the module name of the plugin for B<$language>
=item B(I<$filename>);
Suggests language name for the fiven file B<$filename>
=item B
Returns a reference to the sections hash.
=back
=head1 ATTRIBUTES
In the kate XML syntax files you find under the section B<> entries like
. Kate is an editor
so it is ok to have definitions for forground and background colors and so on. However,
since this Module is supposed to be a more universal highlight engine, the attributes need
to be fully abstract. In which case, Kate does not have enough default attributes defined
to fullfill all needs. Kate defines the following standard attributes: B, B,
B, B, B, B, B, B, B, B,
B, B, B, B. This module leaves out the "ds" part and uses
following additional attributes: B, B, B, B, B. I have
modified the XML files so that each highlight mode would get it's own attribute. In quite a few cases
still not enough attributes were defined. So in some languages different modes have the same attribute.
=head1 PLUGINS
Below an overview of existing plugins. All have been tested on use and can be created. The ones for which no samplefile
is available are marked. Those marked OK have highlighted the testfile without appearant mistakes. This does
not mean that all bugs are shaken out.
LANGUAGE MODULE COMMENT
******** ****** ******
.desktop Desktop OK
4GL FourGL No sample file
4GL-PER FourGLminusPER No sample file
ABC ABC OK
AHDL AHDL OK
ANSI C89 ANSI_C89 No sample file
ASP ASP OK
AVR Assembler AVR_Assembler OK
AWK AWK OK
Ada Ada No sample file
Alerts OK hidden module
Ansys Ansys No sample file
Apache Configuration Apache_Configuration No sample file
Asm6502 Asm6502 No sample file
Bash Bash OK
BibTeX BibTeX OK
C C No sample file
C# Cdash No sample file
C++ Cplusplus OK
CGiS CGiS No sample file
CMake CMake OK
CSS CSS OK
CUE Sheet CUE_Sheet No sample file
Cg Cg No sample file
ChangeLog ChangeLog No sample file
Cisco Cisco No sample file
Clipper Clipper OK
ColdFusion ColdFusion No sample file
Common Lisp Common_Lisp OK
Component-Pascal ComponentminusPascal No sample file
D D No sample file
Debian Changelog Debian_Changelog No sample file
Debian Control Debian_Control No sample file
Diff Diff No sample file
Doxygen Doxygen OK
E Language E_Language OK
Eiffel Eiffel No sample file
Email Email OK
Euphoria Euphoria OK
Fortran Fortran OK
FreeBASIC FreeBASIC No sample file
GDL GDL No sample file
GLSL GLSL OK
GNU Assembler GNU_Assembler No sample file
GNU Gettext GNU_Gettext No sample file
HTML HTML OK
Haskell Haskell OK
IDL IDL No sample file
ILERPG ILERPG No sample file
INI Files INI_Files No sample file
Inform Inform No sample file
Intel x86 (NASM) Intel_X86_NASM seems to have issues
JSP JSP OK
Java Java OK
JavaScript JavaScript OK
Javadoc Javadoc No sample file
KBasic KBasic No sample file
Kate File Template Kate_File_Template No sample file
LDIF LDIF No sample file
LPC LPC No sample file
LaTeX LaTex OK
Lex/Flex Lex_Flex OK
LilyPond LilyPond OK
Literate Haskell Literate_Haskell OK
Lua Lua No sample file
M3U M3U OK
MAB-DB MABminusDB No sample file
MIPS Assembler MIPS_Assembler No sample file
Makefile Makefile No sample file
Mason Mason No sample file
Matlab Matlab has issues
Modula-2 Modulaminus2 No sample file
Music Publisher Music_Publisher No sample file
Octave Octave OK
PHP (HTML) PHP_HTML OK
PHP_PHP OK hidden module
POV-Ray POV_Ray OK
Pascal Pascal No sample file
Perl Perl OK
PicAsm PicAsm OK
Pike Pike OK
PostScript PostScript OK
Prolog Prolog No sample file
PureBasic PureBasic OK
Python Python OK
Quake Script Quake_Script No sample file
R Script R_Script No sample file
REXX REXX No sample file
RPM Spec RPM_Spec No sample file
RSI IDL RSI_IDL No sample file
RenderMan RIB RenderMan_RIB OK
Ruby Ruby OK
SGML SGML No sample file
SML SML No sample file
SQL SQL No sample file
SQL (MySQL) SQL_MySQL No sample file
SQL (PostgreSQL) SQL_PostgreSQL No sample file
Sather Sather No sample file
Scheme Scheme OK
Sieve Sieve No sample file
Spice Spice OK
Stata Stata OK
TI Basic TI_Basic No sample file
TaskJuggler TaskJuggler No sample file
Tcl/Tk TCL_Tk OK
UnrealScript UnrealScript OK
VHDL VHDL No sample file
VRML VRML OK
Velocity Velocity No sample file
Verilog Verilog No sample file
WINE Config WINE_Config No sample file
Wikimedia Wikimedia No sample file
XML XML OK
XML (Debug) XML_Debug No sample file
Yacc/Bison Yacc_Bison OK
de_DE De_DE No sample file
en_EN En_EN No sample file
ferite Ferite No sample file
nl Nl No sample file
progress Progress No sample file
scilab Scilab No sample file
txt2tags Txt2tags No sample file
x.org Configuration X_org_Configuration OK
xHarbour XHarbour OK
xslt Xslt No sample file
yacas Yacas No sample file
=head1 BUGS
Float is detected differently than in the Kate editor.
The regular expression engine of the Kate editor, qregexp, appears to be more tolerant to mistakes
in regular expressions than perl. This might lead to error messages and differences in behaviour.
Most of the problems were sorted out while developing, because error messages appeared. For as far
as differences in behaviour is concerned, testing is the only way to find out, so i hope the users
out there will be able to tell me more.
This module is mimicking the behaviour of the syntax highlight engine of the Kate editor. If you find
a bug/mistake in the highlighting, please check if Kate behaves in the same way. If yes, the cause is
likely to be found there.
=head1 TO DO
Rebuild the scripts i am using to generate the modules from xml files so they are more pro-actively tracking
flaws in the build of the xml files like missing lists. Also regular expressions in the xml can be tested better
before used in plugins.
Refine the testmethods in Syntax::Highlight::Engine::Kate::Template, so that choices for casesensitivity,
dynamic behaviour and lookahead can be determined at generate time of the plugin, might increase throughput.
Implement codefolding.
=head1 ACKNOWLEDGEMENTS
All the people who wrote Kate and the syntax highlight xml files.
=head1 AUTHOR AND COPYRIGHT
This module is written and maintained by:
Hans Jeuken < haje at toneel dot demon dot nl >
Copyright (c) 2006 by Hans Jeuken, all rights reserved.
You may freely distribute and/or modify this module under the same terms
as Perl itself.
=head1 SEE ALSO
Syntax::Highlight::Engine::Kate::Template http:://www.kate-editor.org
=cut
Syntax-Highlight-Engine-Kate-0.14/t/perl/before/template.pl 0000755 0001750 0001750 00000065606 13032300413 023076 0 ustar manwar manwar # Copyright (c) 2006 Hans Jeuken. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Syntax::Highlight::Engine::Kate::Template;
our $VERSION = '0.06';
use strict;
use Carp qw(cluck);
use Data::Dumper;
#my $regchars = '\\^.$|()[]*+?';
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = (@_);
my $debug = delete $args{'debug'};
unless (defined($debug)) { $debug = 0 };
my $substitutions = delete $args{'substitutions'};
unless (defined($substitutions)) { $substitutions = {} };
my $formattable = delete $args{'format_table'};
unless (defined($formattable)) { $formattable = {} };
my $engine = delete $args{'engine'};
my $self = {};
$self->{'attributes'} = {},
$self->{'captured'} = [];
$self->{'contextdata'} = {};
$self->{'basecontext'} = '';
$self->{'debug'} = $debug;
$self->{'deliminators'} = '';
$self->{'engine'} = '';
$self->{'format_table'} = $formattable;
$self->{'keywordcase'} = 1;
$self->{'lastchar'} = '';
$self->{'linesegment'} = '';
$self->{'lists'} = {};
$self->{'linestart'} = 1;
$self->{'out'} = [];
$self->{'plugins'} = {};
$self->{'snippet'} = '';
$self->{'snippetattribute'} = '';
$self->{'stack'} = [];
$self->{'substitutions'} = $substitutions;
bless ($self, $class);
unless (defined $engine) { $engine = $self };
$self->engine($engine);
$self->initialize;
return $self;
}
sub attributes {
my $self = shift;
if (@_) { $self->{'attributes'} = shift; };
return $self->{'attributes'};
}
sub basecontext {
my $self = shift;
if (@_) { $self->{'basecontext'} = shift; };
return $self->{'basecontext'};
}
sub captured {
my ($self, $c) = @_;
if (defined($c)) {
my $t = $self->engine->stackTop;
my $n = 0;
my @o = ();
while (defined($c->[$n])) {
push @o, $c->[$n];
$n ++;
}
if (@o) {
$t->[2] = \@o;
}
};
}
sub capturedGet {
my ($self, $num) = @_;
my $s = $self->engine->stack;
if (defined($s->[1])) {
my $c = $s->[1]->[2];
$num --;
if (defined($c)) {
if (defined($c->[$num])) {
my $r = $c->[$num];
return $r;
} else {
warn "capture number $num not defined";
}
} else {
warn "dynamic substitution is called for but nothing to substitute\n";
return undef;
}
} else {
warn "no parent context to take captures from";
}
}
#sub captured {
# my $self = shift;
# if (@_) {
# $self->{'captured'} = shift;
## print Dumper($self->{'captured'});
# };
# return $self->{'captured'}
## my ($self, $c) = @_;
## if (defined($c)) {
## my $t = $self->engine->stackTop;
## my $n = 0;
## my @o = ();
## while (defined($c->[$n])) {
## push @o, $c->[$n];
## $n ++;
## }
## if (@o) {
## $t->[2] = \@o;
## }
## };
#}
#
#sub capturedGet {
# my ($self, $num) = @_;
# my $s = $self->captured;
# if (defined $s) {
# $num --;
# if (defined($s->[$num])) {
# return $s->[$num];
# } else {
# $self->logwarning("capture number $num not defined");
# }
# } else {
# $self->logwarning("dynamic substitution is called for but nothing to substitute");
# return undef;
# }
#}
sub capturedParse {
my ($self, $string, $mode) = @_;
my $s = '';
if (defined($mode)) {
if ($string =~ s/^(\d)//) {
$s = $self->capturedGet($1);
if ($string ne '') {
$self->logwarning("character class is longer then 1 character, ignoring the rest");
}
}
} else {
while ($string ne '') {
if ($string =~ s/^([^\%]*)\%(\d)//) {
my $r = $self->capturedGet($2);
if ($r ne '') {
$s = $s . $1 . $r
} else {
$s = $s . $1 . '%' . $2;
$self->logwarning("target is an empty string");
}
} else {
$string =~ s/^(.)//;
$s = "$s$1";
}
}
}
return $s;
}
sub column {
my $self = shift;
return length($self->linesegment);
}
sub contextdata {
my $self = shift;
if (@_) { $self->{'contextdata'} = shift; };
return $self->{'contextdata'};
}
sub contextInfo {
my ($self, $context, $item) = @_;
if (exists $self->contextdata->{$context}) {
my $c = $self->contextdata->{$context};
if (exists $c->{$item}) {
return $c->{$item}
} else {
return undef;
}
} else {
$self->logwarning("undefined context '$context'");
return undef;
}
}
sub contextParse {
my ($self, $plug, $context) = @_;
if ($context =~ /^#pop/i) {
while ($context =~ s/#pop//i) {
$self->stackPull;
}
} elsif ($context =~ /^#stay/i) {
#don't do anything
} elsif ($context =~ /^##(.+)/) {
my $new = $self->pluginGet($1);
$self->stackPush([$new, $new->basecontext]);
} else {
$self->stackPush([$plug, $context]);
}
}
sub debug {
my $self = shift;
if (@_) { $self->{'debug'} = shift; };
return $self->{'debug'};
}
sub debugTest {
my $self = shift;
if (@_) { $self->{'debugtest'} = shift; };
return $self->{'debugtest'};
}
sub deliminators {
my $self = shift;
if (@_) { $self->{'deliminators'} = shift; };
return $self->{'deliminators'};
}
sub engine {
my $self = shift;
if (@_) { $self->{'engine'} = shift; };
return $self->{'engine'};
}
sub firstnonspace {
my ($self, $string) = @_;
my $line = $self->linesegment;
if (($line =~ /^\s*$/) and ($string =~ /^[^\s]/)) {
return 1
}
return ''
}
sub formatTable {
my $self = shift;
if (@_) { $self->{'format_table'} = shift; };
return $self->{'format_table'};
}
sub highlight {
my ($self, $text) = @_;
$self->snippet('');
my $out = $self->out;
@$out = ();
while ($text ne '') {
my $top = $self->stackTop;
if (defined($top)) {
my ($plug, $context) = @$top;
if ($text =~ s/^(\n)//) {
$self->snippetForce;
my $e = $plug->contextInfo($context, 'lineending');
if (defined($e)) {
$self->contextParse($plug, $e)
}
my $attr = $plug->attributes->{$plug->contextInfo($context, 'attribute')};
$self->snippetParse($1, $attr);
$self->snippetForce;
$self->linesegment('');
my $b = $plug->contextInfo($context, 'linebeginning');
if (defined($b)) {
$self->contextParse($plug, $b)
}
} else {
my $sub = $plug->contextInfo($context, 'callback');
my $result = &$sub($plug, \$text);
unless($result) {
my $f = $plug->contextInfo($context, 'fallthrough');
if (defined($f)) {
$self->contextParse($plug, $f);
} else {
$text =~ s/^(.)//;
my $attr = $plug->attributes->{$plug->contextInfo($context, 'attribute')};
$self->snippetParse($1, $attr);
}
}
}
} else {
push @$out, length($text), 'Normal';
$text = '';
}
}
$self->snippetForce;
return @$out;
}
sub highlightText {
my ($self, $text) = @_;
my $res = '';
my @hl = $self->highlight($text);
while (@hl) {
my $f = shift @hl;
my $t = shift @hl;
unless (defined($t)) { $t = 'Normal' }
my $s = $self->substitutions;
my $rr = '';
while ($f ne '') {
my $k = substr($f , 0, 1);
$f = substr($f, 1, length($f) -1);
if (exists $s->{$k}) {
$rr = $rr . $s->{$k}
} else {
$rr = $rr . $k;
}
}
my $rt = $self->formatTable;
if (exists $rt->{$t}) {
my $o = $rt->{$t};
$res = $res . $o->[0] . $rr . $o->[1];
} else {
$res = $res . $rr;
$self->logwarning("undefined format tag '$t'");
}
}
return $res;
}
sub includePlugin {
my ($self, $language, $text) = @_;
my $eng = $self->engine;
my $plug = $eng->pluginGet($language);
if (defined($plug)) {
my $context = $plug->basecontext;
my $call = $plug->contextInfo($context, 'callback');
if (defined($call)) {
return &$call($plug, $text);
} else {
$self->logwarning("cannot find callback for context '$context'");
}
}
return 0;
}
sub includeRules {
my ($self, $context, $text) = @_;
my $call = $self->contextInfo($context, 'callback');
if (defined($call)) {
return &$call($self, $text);
} else {
$self->logwarning("cannot find callback for context '$context'");
}
return 0;
}
sub initialize {
my $self = shift;
if ($self->engine eq $self) {
$self->stack([[$self, $self->basecontext]]);
}
}
sub keywordscase {
my $self = shift;
if (@_) { $self->{'keywordcase'} = shift; }
return $self->{'keywordscase'}
}
sub languagePlug {
my ($cw, $name) = @_;
my %numb = (
'1' => 'One',
'2' => 'Two',
'3' => 'Three',
'4' => 'Four',
'5' => 'Five',
'6' => 'Six',
'7' => 'Seven',
'8' => 'Eight',
'9' => 'Nine',
'0' => 'Zero',
);
if ($name =~ s/^(\d)//) {
$name = $numb{$1} . $name;
}
$name =~ s/\.//;
$name =~ s/\+/plus/g;
$name =~ s/\-/minus/g;
$name =~ s/#/dash/g;
$name =~ s/[^0-9a-zA-Z]/_/g;
$name =~ s/__/_/g;
$name =~ s/_$//;
$name = ucfirst($name);
return $name;
}
sub lastchar {
my $self = shift;
my $l = $self->linesegment;
if ($l eq '') { return "\n" } #last character was a newline
return substr($l, length($l) - 1, 1);
}
sub lastcharDeliminator {
my $self = shift;
my $deliminators = '\s|\~|\!|\%|\^|\&|\*|\+|\(|\)|-|=|\{|\}|\[|\]|:|;|<|>|,|\\|\||\.|\?|\/';
if ($self->linestart or ($self->lastchar =~ /$deliminators/)) {
return 1;
}
return '';
}
sub linesegment {
my $self = shift;
if (@_) { $self->{'linesegment'} = shift; };
return $self->{'linesegment'};
}
sub linestart {
my $self = shift;
if ($self->linesegment eq '') {
return 1
}
return '';
}
sub lists {
my $self = shift;
if (@_) { $self->{'lists'} = shift; }
return $self->{'lists'}
}
sub out {
my $self = shift;
if (@_) { $self->{'out'} = shift; }
return $self->{'out'};
}
sub listAdd {
my $self = shift;
my $listname = shift;
my $lst = $self->lists;
if (@_) {
my @l = reverse sort @_;
$lst->{$listname} = \@l;
} else {
$lst->{$listname} = [];
}
}
sub logwarning {
my ($self, $warning) = @_;
my $top = $self->engine->stackTop;
if (defined $top) {
my $lang = $top->[0]->language;
my $context = $top->[1];
$warning = "$warning\n Language => $lang, Context => $context\n";
} else {
$warning = "$warning\n STACK IS EMPTY: PANIC\n"
}
cluck($warning);
}
sub parseResult {
my ($self, $text, $string, $lahead, $column, $fnspace, $context, $attr) = @_;
my $eng = $self->engine;
if ($fnspace) {
unless ($eng->firstnonspace($$text)) {
return ''
}
}
if (defined($column)) {
if ($column ne $eng->column) {
return '';
}
}
unless ($lahead) {
$$text = substr($$text, length($string));
my $r;
unless (defined($attr)) {
my $t = $eng->stackTop;
my ($plug, $ctext) = @$t;
$r = $plug->attributes->{$plug->contextInfo($ctext, 'attribute')};
} else {
$r = $self->attributes->{$attr};
}
$eng->snippetParse($string, $r);
}
$eng->contextParse($self, $context);
return 1
}
sub pluginGet {
my ($self, $language) = @_;
my $plugs = $self->{'plugins'};
unless (exists($plugs->{$language})) {
my $modname = 'Syntax::Highlight::Engine::Kate::' . $self->languagePlug($language);
unless (defined($modname)) {
$self->logwarning("no valid module found for language '$language'");
return undef;
}
my $plug;
eval "use $modname; \$plug = new $modname(engine => \$self);";
if (defined($plug)) {
$plugs->{$language} = $plug;
} else {
$self->logwarning("cannot create plugin for language '$language'\n$@");
}
}
if (exists($plugs->{$language})) {
return $plugs->{$language};
}
return undef;
}
sub reset {
my $self = shift;
$self->stack([[$self, $self->basecontext]]);
$self->out([]);
$self->snippet('');
}
sub snippet {
my $self = shift;
if (@_) { $self->{'snippet'} = shift; }
return $self->{'snippet'};
}
sub snippetAppend {
my ($self, $ch) = @_;
return if not defined $ch;
$self->{'snippet'} = $self->{'snippet'} . $ch;
if ($ch ne '') {
$self->linesegment($self->linesegment . $ch);
}
return;
}
sub snippetAttribute {
my $self = shift;
if (@_) { $self->{'snippetattribute'} = shift; }
return $self->{'snippetattribute'};
}
sub snippetForce {
my $self = shift;
my $parse = $self->snippet;
if ($parse ne '') {
my $out = $self->{'out'};
push(@$out, $parse, $self->snippetAttribute);
$self->snippet('');
}
}
sub snippetParse {
my $self = shift;
my $snip = shift;
my $attr = shift;
if ((defined $attr) and ($attr ne $self->snippetAttribute)) {
$self->snippetForce;
$self->snippetAttribute($attr);
}
$self->snippetAppend($snip);
}
sub stack {
my $self = shift;
if (@_) { $self->{'stack'} = shift; }
return $self->{'stack'};
}
sub stackPush {
my ($self, $val) = @_;
my $stack = $self->stack;
unshift(@$stack, $val);
}
sub stackPull {
my ($self, $val) = @_;
my $stack = $self->stack;
return shift(@$stack);
}
sub stackTop {
my $self = shift;
return $self->stack->[0];
}
sub stateCompare {
my ($self, $state) = @_;
my $h = [ $self->stateGet ];
my $equal = 0;
if (Dumper($h) eq Dumper($state)) { $equal = 1 };
return $equal;
}
sub stateGet {
my $self = shift;
my $s = $self->stack;
return @$s;
}
sub stateSet {
my $self = shift;
my $s = $self->stack;
@$s = (@_);
}
sub substitutions {
my $self = shift;
if (@_) { $self->{'substitutions'} = shift; }
return $self->{'substitutions'};
}
sub testAnyChar {
my $self = shift;
my $text = shift;
my $string = shift;
my $insensitive = shift;
my $test = substr($$text, 0, 1);
my $bck = $test;
if ($insensitive) {
$string = lc($string);
$test = lc($test);
}
if (index($string, $test) > -1) {
return $self->parseResult($text, $bck, @_);
}
return ''
}
sub testDetectChar {
my $self = shift;
my $text = shift;
my $char = shift;
my $insensitive = shift;
my $dyn = shift;
if ($dyn) {
$char = $self->capturedParse($char, 1);
}
my $test = substr($$text, 0, 1);
my $bck = $test;
if ($insensitive) {
$char = lc($char);
$test = lc($test);
}
if ($char eq $test) {
return $self->parseResult($text, $bck, @_);
}
return ''
}
sub testDetect2Chars {
my $self = shift;
my $text = shift;
my $char = shift;
my $char1 = shift;
my $insensitive = shift;
my $dyn = shift;
if ($dyn) {
$char = $self->capturedParse($char, 1);
$char1 = $self->capturedParse($char1, 1);
}
my $string = $char . $char1;
my $test = substr($$text, 0, 2);
my $bck = $test;
if ($insensitive) {
$string = lc($string);
$test = lc($test);
}
if ($string eq $test) {
return $self->parseResult($text, $bck, @_);
}
return ''
}
sub testDetectIdentifier {
my $self = shift;
my $text = shift;
if ($$text =~ /^([a-zA-Z_][a-zA-Z0-9_]+)/) {
return $self->parseResult($text, $1, @_);
}
return ''
}
sub testDetectSpaces {
my $self = shift;
my $text = shift;
if ($$text =~ /^([\\040|\\t]+)/) {
return $self->parseResult($text, $1, @_);
}
return ''
}
sub testFloat {
my $self = shift;
my $text = shift;
if ($self->engine->lastcharDeliminator) {
if ($$text =~ /^((?=\.?\d)\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?)/) {
return $self->parseResult($text, $1, @_);
}
}
return ''
}
sub testHlCChar {
my $self = shift;
my $text = shift;
if ($$text =~ /^('.')/) {
return $self->parseResult($text, $1, @_);
}
return ''
}
sub testHlCHex {
my $self = shift;
my $text = shift;
if ($self->engine->lastcharDeliminator) {
if ($$text =~ /^(0x[0-9a-fA-F]+)/) {
return $self->parseResult($text, $1, @_);
}
}
return ''
}
sub testHlCOct {
my $self = shift;
my $text = shift;
if ($self->engine->lastcharDeliminator) {
if ($$text =~ /^(0[0-7]+)/) {
return $self->parseResult($text, $1, @_);
}
}
return ''
}
sub testHlCStringChar {
my $self = shift;
my $text = shift;
if ($$text =~ /^(\\[a|b|e|f|n|r|t|v|'|"|\?])/) {
return $self->parseResult($text, $1, @_);
}
if ($$text =~ /^(\\x[0-9a-fA-F][0-9a-fA-F]?)/) {
return $self->parseResult($text, $1, @_);
}
if ($$text =~ /^(\\[0-7][0-7]?[0-7]?)/) {
return $self->parseResult($text, $1, @_);
}
return ''
}
sub testInt {
my $self = shift;
my $text = shift;
if ($self->engine->lastcharDeliminator) {
if ($$text =~ /^([+-]?\d+)/) {
return $self->parseResult($text, $1, @_);
}
}
return ''
}
sub testKeyword {
my $self = shift;
my $text = shift;
my $list = shift;
my $eng = $self->engine;
my $deliminators = $self->deliminators;
if (($eng->lastcharDeliminator) and ($$text =~ /^([^$deliminators]+)/)) {
my $match = $1;
my $l = $self->lists->{$list};
if (defined($l)) {
my @list = @$l;
my @rl = ();
unless ($self->keywordscase) {
@rl = grep { (lc($match) eq lc($_)) } @list;
} else {
@rl = grep { ($match eq $_) } @list;
}
if (@rl) {
return $self->parseResult($text, $match, @_);
}
} else {
$self->logwarning("list '$list' is not defined, failing test");
}
}
return ''
}
sub testLineContinue {
my $self = shift;
my $text = shift;
my $lahead = shift;
if ($lahead) {
if ($$text =~ /^\\\n/) {
$self->parseResult($text, "\\", $lahead, @_);
return 1;
}
} else {
if ($$text =~ s/^(\\)(\n)/$2/) {
return $self->parseResult($text, "\\", $lahead, @_);
}
}
return ''
}
sub testRangeDetect {
my $self = shift;
my $text = shift;
my $char = shift;
my $char1 = shift;
my $insensitive = shift;
my $string = "$char\[^$char1\]+$char1";
return $self->testRegExpr($text, $string, $insensitive, 0, @_);
}
sub testRegExpr {
my $self = shift;
my $text = shift;
my $reg = shift;
my $insensitive = shift;
my $dynamic = shift;
if ($dynamic) {
$reg = $self->capturedParse($reg);
}
my $eng = $self->engine;
if ($reg =~ s/^\^//) {
unless ($eng->linestart) {
return '';
}
} elsif ($reg =~ s/^\\(b)//i) {
my $lastchar = $self->engine->lastchar;
if ($1 eq 'b') {
if ($lastchar =~ /\w/) { return '' }
} else {
if ($lastchar =~ /\W/) { return '' }
}
}
# $reg = "^($reg)";
$reg = "^$reg";
my $pos;
# my @cap = ();
my $sample = $$text;
# emergency measurements to avoid exception (szabgab)
$reg = eval { qr/$reg/ };
if ($@) {
warn $@;
return '';
}
if ($insensitive) {
if ($sample =~ /$reg/ig) {
$pos = pos($sample);
# @cap = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
# my @cap = ();
if ($#-) {
no strict 'refs';
my @cap = map {$$_} 1 .. $#-;
$self->captured(\@cap)
}
# my $r = 1;
# my $c = 1;
# my @cap = ();
# while ($r) {
# eval "if (defined\$$c) { push \@cap, \$$c } else { \$r = 0 }";
# $c ++;
# }
# if (@cap) { $self->captured(\@cap) };
}
} else {
if ($sample =~ /$reg/g) {
$pos = pos($sample);
# @cap = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
# my @cap = ();
if ($#-) {
no strict 'refs';
my @cap = map {$$_} 1 .. $#-;
$self->captured(\@cap);
}
# my $r = 1;
# my $c = 1;
# my @cap = ();
# while ($r) {
# eval "if (defined\$$c) { push \@cap, \$$c } else { \$r = 0 }";
# $c ++;
# }
# if (@cap) { $self->captured(\@cap) };
}
}
if (defined($pos) and ($pos > 0)) {
my $string = substr($$text, 0, $pos);
return $self->parseResult($text, $string, @_);
}
return ''
}
sub testStringDetect {
my $self = shift;
my $text = shift;
my $string = shift;
my $insensitive = shift;
my $dynamic = shift;
if ($dynamic) {
$string = $self->capturedParse($string);
}
my $test = substr($$text, 0, length($string));
my $bck = $test;
if ($insensitive) {
$string = lc($string);
$test = lc($test);
}
if ($string eq $test) {
return $self->parseResult($text, $bck, @_);
}
return ''
}
1;
__END__
=head1 NAME
Syntax::Highlight::Engine::Kate::Template - a template for syntax highlighting plugins
=head1 DESCRIPTION
Syntax::Highlight::Engine::Kate::Template is a framework to assist authors of plugin modules.
All methods to provide highlighting to the Syntax::Highlight::Engine::Kate module are there, Just
no syntax definitions and callbacks. An instance of Syntax::Highlight::Engine::Kate::Template
should never be created, it's meant to be sub classed only.
=head1 METHODS
=over 4
=item B(I$attributesref?>);
Sets and returns a reference to the attributes hash.
=item B(I$context?>);
Sets and returns the basecontext instance variable. This is the context that is used when highlighting starts.
=item B(I<$cap>);
Puts $cap in the first element of the stack, the current context. Used when the context is dynamic.
=item B(I<$num>);
Returns the $num'th element that was captured in the current context.
=item B(I<$string>, I<$mode>);
If B<$mode> is specified, B<$string> should only be one character long and numeric.
B will return the Nth captured element of the current context.
If B<$mode> is not specified, all occurences of %[1-9] will be replaced by the captured
element of the current context.
=item B
returns the column position in the line that is currently highlighted.
=item B(I<\%data>);
Sets and returns a reference to the contextdata hash.
=item B(I<$context>, I<$item>);
returns the value of several context options. B<$item> can be B, B, B,
B, B.
=item B(I<$plugin>, I<$context>);
Called by the plugins after a test succeeds. if B<$context> has following values:
#pop returns to the previous context, removes to top item in the stack. Can
also be specified as #pop#pop etc.
#stay does nothing.
##.... Switches to the plugin specified in .... and assumes it's basecontext.
.... Swtiches to the context specified in ....
=item B(I$delim?>);
Sets and returns a string that is a regular expression for detecting deliminators.
=item B
Returns a reference to the Syntax::Highlight::Engine::Kate module that created this plugin.
=item B(I<$string>);
returns true if the current line did not contain a non-spatial character so far and the first
character in B<$string> is also a spatial character.
=item B
sets and returns the instance variable B. See also the option B
=item B(I<$text>);
highlights I<$text>. It does so by selecting the proper callback
from the B hash and invoke it. It will do so untill
$text has been reduced to an empty string. returns a paired list
of snippets of text and the attribute with which they should be
highlighted.
=item B(I<$text>);
highlights I<$text> and reformats it using the B and B
=item B(I<$language>, I<\$text>);
Includes the plugin for B<$language> in the highlighting.
=item B(I<$language>, I<\$text>);
Includes the plugin for B<$language> in the highlighting.
=item B
Sets and returns the keywordscase instance variable.
=item B
return the last character that was processed.
=item B
returns true if the last character processed was a deliminator.
=item B
returns the string of text in the current line that has been processed so far,
=item B
returns true if processing is currently at the beginning of a line.
=item B(I<'listname'>, I<$item1>, I<$item2> ...);
Adds a list to the 'lists' hash.
=item B(I\%lists?>);
sets and returns the instance variable 'lists'.
=item B(I\@highlightedlist?>);
sets and returns the instance variable 'out'.
=item B(I<\$text>, I<$match>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
Called by every one of the test methods below. If the test matches, it will do a couple of subtests.
If B<$column> is a defined numerical value it will test if the process is at the requested column.
If B<$firnonspace> is true, it will test this also.
Ig it is not a look ahead and all tests are passed, B<$match> is then parsed and removed from B<$$text>.
=item B(I<$language>);
Returns a reference to a plugin object for the specified language. Creating an
instance if needed.
=item B
Resets the highlight engine to a fresh state, does not change the syntx.
=item B
Contains the current snippet of text that will have one attribute. The moment the attribute
changes it will be parsed.
=item B(I<$string>)
appends I<$string> to the current snippet.
=item B(I<$attribute>)
Sets and returns the used attribute.
=item B
Forces the current snippet to be parsed.
=item B(I<$text>, I$attribute?>)
If attribute is defined and differs from the current attribute it does a snippetForce and
sets the current attribute to B<$attribute>. Then it does a snippetAppend of B<$text>
=item B
sets and returns the instance variable 'stack', a reference to an array
=item B
retrieves the element that is on top of the stack, decrements stacksize by 1.
=item B(I<$tagname>);
puts I<$tagname> on top of the stack, increments stacksize by 1
=item B
Retrieves the element that is on top of the stack.
=item B(I<\@state>)
Compares two lists, \@state and the stack. returns true if they
match.
=item B
Returns a list containing the entire stack.
=item B(I<@list>)
Accepts I<@list> as the current stack.
=item B
sets and returns a reference to the substitutions hash.
=back
The methods below all return a boolean value.
=over 4
=item B(I<\$text>, I<$string>, I<$insensitive>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$char>, I<$insensitive>, I<$dynamic>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$char1>, I<$char2>, I<$insensitive>, I<$dynamic>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$list>, I<$insensitive>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$char1>, I<$char2>, I<$insensitive>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$reg>, I<$insensitive>, I<$dynamic>, I<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=item B(I<\$text>, I<$string>, I<$insensitive>, I<$dynamic>, II<$lookahaed>, I<$column>, I<$firstnonspace>, I<$context>, I<$attribute>);
=back
=head1 ACKNOWLEDGEMENTS
All the people who wrote Kate and the syntax highlight xml files.
=head1 AUTHOR AND COPYRIGHT
This module is written and maintained by:
Hans Jeuken < haje at toneel dot demon dot nl >
Copyright (c) 2006 by Hans Jeuken, all rights reserved.
You may freely distribute and/or modify this module under same terms as
Perl itself
=head1 SEE ALSO
Synax::Highlight::Engine::Kate http:://www.kate-editor.org Syntax-Highlight-Engine-Kate-0.14/t/perl/highlighted/ 0000755 0001750 0001750 00000000000 13226471445 021747 5 ustar manwar manwar Syntax-Highlight-Engine-Kate-0.14/t/perl/highlighted/maze.pl 0000644 0001750 0001750 00000035553 13032300413 023230 0 ustar manwar manwar #!perl
use strict;
use warnings;
use diagnostics;
use List::Util 'shuffle';
# The size of the maze. Take the arguments from the command line or from the
# default.
my ( $HEIGHT, $WIDTH ) = @ARGV ? @ARGV : ( 20, 20 );
# Time::HiRes was officially released with Perl 5.8.0, though Module::Corelist
# reports that it was actually released as early as v5.7.3. If you don't have
# this module, your version of Perl is probably over a decade old
use Time::HiRes 'usleep';
# In Perl, $^O is the name of your operating system. On Windows (as of this
# writing), it always 'MSWin32'.
use constant IS_WIN32 => 'MSWin32' eq $^O;
# On Windows, we assume that the command to clear the screen is 'cls'. On all
# other systems, we assume it's 'clear'. You may need to adjust this.
use constant CLEAR => IS_WIN32 ? 'cls' : 'clear';
# We will only redraw the screen (and thus show the recursive maze generation)
# if and only if the system is capable of clearing the screen. The system()
# command returns 0 upon success. See perldoc -f system.
# The following line works because $x == $y returns a boolean value.
#use constant CAN_REDRAW => 0 == system(CLEAR);
use constant CAN_REDRAW => 0;
# Time in microseconds between screen redraws. See Time::HiRes and the usleep
# function
use constant DELAY => 10_000;
use constant OPPOSITE_OF => {
north => 'south',
south => 'north',
west => 'east',
east => 'west',
};
my @maze;
tunnel( 0, 0, \@maze );
my $num = 10_000;
system(CLEAR) if CAN_REDRAW;
print render_maze( \@maze );
exit;
sub tunnel {
my ( $x, $y, $maze ) = @_;
if (CAN_REDRAW) {
my $render = render_maze($maze);
system(CLEAR);
print $render;
usleep DELAY;
}
# Here we need to use a unary plus in front of OPPOSITE_OF so that
# Perl understands that this is a constant and that we're not trying
# to access the %OPPOSITE_OF variable.
my @directions = shuffle keys %{ +OPPOSITE_OF };
foreach my $direction (@directions) {
my ( $new_x, $new_y ) = ( $x, $y );
if ( 'east' eq $direction ) { $new_x += 1; }
elsif ( 'west' eq $direction ) { $new_x -= 1; }
elsif ( 'south' eq $direction ) { $new_y += 1; }
else { $new_y -= 1; }
if ( have_not_visited( $new_x, $new_y, $maze ) ) {
$maze->[$y][$x]{$direction} = 1;
$maze->[$new_y][$new_x]{ OPPOSITE_OF->{$direction} } = 1;
# This program will often recurse more than one hundred levels
# deep and this is Perl's default recursion depth level prior to
# issuing warnings. In this case, we're telling Perl that we know
# that we'll exceed the recursion depth and to now warn us about
# it
no warnings 'recursion';
tunnel( $new_x, $new_y, $maze );
}
}
}
sub have_not_visited {
my ( $x, $y, $maze ) = @_;
# the first two lines return false if we're out of bounds
return if $x < 0 or $y < 0;
return if $x > $WIDTH - 1 or $y > $HEIGHT - 1;
# this returns false if we've already visited this cell
return if $maze->[$y][$x];
# return true
return 1;
}
sub render_maze {
my $maze = shift;
my $as_string = "_" x ( 1 + $WIDTH * 2 );
$as_string .= "\n";
for my $y ( 0 .. $HEIGHT - 1 ) {
$as_string .= "|";
for my $x ( 0 .. $WIDTH - 1 ) {
my $cell = $maze->[$y][$x];
$as_string .= $cell->{south} ? " " : "_";
$as_string .= $cell->{east} ? " " : "|";
}
$as_string .= "\n";
}
return $as_string;
}