Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Syntax / Highlight / Engine / Kate.pm
1
2 # Copyright (c) 2006 Hans Jeuken. All rights reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the same terms as Perl itself.
5
6 package Syntax::Highlight::Engine::Kate;
7
8 use 5.006;
9 our $VERSION = '0.06';
10 use strict;
11 use warnings;
12 use Carp;
13 use Data::Dumper;
14 use File::Basename;
15
16 use base('Syntax::Highlight::Engine::Kate::Template');
17
18 sub new {
19         my $proto = shift;
20         my $class = ref($proto) || $proto;
21         my %args = (@_);
22         
23         my $add = delete $args{'plugins'};
24         unless (defined($add)) { $add = [] };
25         my $language = delete $args{'language'};
26         unless (defined($language)) { $language = 'Off' };
27         
28         my $self = $class->SUPER::new(%args);
29
30         $self->{'plugins'} = {};
31         #begin autoinsert
32         $self->{'extensions'} = {
33                 ' *.cls' => ['LaTeX', ],
34                 ' *.dtx' => ['LaTeX', ],
35                 ' *.ltx' => ['LaTeX', ],
36                 ' *.sty' => ['LaTeX', ],
37                 '*.4GL' => ['4GL', ],
38                 '*.4gl' => ['4GL', ],
39                 '*.ABC' => ['ABC', ],
40                 '*.ASM' => ['AVR Assembler', 'PicAsm', ],
41                 '*.BAS' => ['FreeBASIC', ],
42                 '*.BI' => ['FreeBASIC', ],
43                 '*.C' => ['C++', 'C', 'ANSI C89', ],
44                 '*.D' => ['D', ],
45                 '*.F' => ['Fortran', ],
46                 '*.F90' => ['Fortran', ],
47                 '*.F95' => ['Fortran', ],
48                 '*.FOR' => ['Fortran', ],
49                 '*.FPP' => ['Fortran', ],
50                 '*.GDL' => ['GDL', ],
51                 '*.H' => ['C++', ],
52                 '*.JSP' => ['JSP', ],
53                 '*.LOGO' => ['de_DE', 'en_US', 'nl', ],
54                 '*.LY' => ['LilyPond', ],
55                 '*.Logo' => ['de_DE', 'en_US', 'nl', ],
56                 '*.M' => ['Matlab', 'Octave', ],
57                 '*.MAB' => ['MAB-DB', ],
58                 '*.Mab' => ['MAB-DB', ],
59                 '*.PER' => ['4GL-PER', ],
60                 '*.PIC' => ['PicAsm', ],
61                 '*.PRG' => ['xHarbour', 'Clipper', ],
62                 '*.R' => ['R Script', ],
63                 '*.S' => ['GNU Assembler', ],
64                 '*.SQL' => ['SQL', 'SQL (MySQL)', 'SQL (PostgreSQL)', ],
65                 '*.SRC' => ['PicAsm', ],
66                 '*.V' => ['Verilog', ],
67                 '*.VCG' => ['GDL', ],
68                 '*.a' => ['Ada', ],
69                 '*.abc' => ['ABC', ],
70                 '*.ada' => ['Ada', ],
71                 '*.adb' => ['Ada', ],
72                 '*.ado' => ['Stata', ],
73                 '*.ads' => ['Ada', ],
74                 '*.ahdl' => ['AHDL', ],
75                 '*.ai' => ['PostScript', ],
76                 '*.ans' => ['Ansys', ],
77                 '*.asm' => ['AVR Assembler', 'Asm6502', 'Intel x86 (NASM)', 'PicAsm', ],
78                 '*.asm-avr' => ['AVR Assembler', ],
79                 '*.asp' => ['ASP', ],
80                 '*.awk' => ['AWK', ],
81                 '*.bas' => ['FreeBASIC', ],
82                 '*.basetest' => ['BaseTest', ],
83                 '*.bash' => ['Bash', ],
84                 '*.bi' => ['FreeBASIC', ],
85                 '*.bib' => ['BibTeX', ],
86                 '*.bro' => ['Component-Pascal', ],
87                 '*.c' => ['C', 'ANSI C89', 'LPC', ],
88                 '*.c++' => ['C++', ],
89                 '*.cc' => ['C++', ],
90                 '*.cfc' => ['ColdFusion', ],
91                 '*.cfg' => ['Quake Script', ],
92                 '*.cfm' => ['ColdFusion', ],
93                 '*.cfml' => ['ColdFusion', ],
94                 '*.cg' => ['Cg', ],
95                 '*.cgis' => ['CGiS', ],
96                 '*.ch' => ['xHarbour', 'Clipper', ],
97                 '*.cis' => ['Cisco', ],
98                 '*.cl' => ['Common Lisp', ],
99                 '*.cmake' => ['CMake', ],
100                 '*.config' => ['Logtalk', ],
101                 '*.cp' => ['Component-Pascal', ],
102                 '*.cpp' => ['C++', ],
103                 '*.cs' => ['C#', ],
104                 '*.css' => ['CSS', ],
105                 '*.cue' => ['CUE Sheet', ],
106                 '*.cxx' => ['C++', ],
107                 '*.d' => ['D', ],
108                 '*.daml' => ['XML', ],
109                 '*.dbm' => ['ColdFusion', ],
110                 '*.def' => ['Modula-2', ],
111                 '*.desktop' => ['.desktop', ],
112                 '*.diff' => ['Diff', ],
113                 '*.do' => ['Stata', ],
114                 '*.docbook' => ['XML', ],
115                 '*.dox' => ['Doxygen', ],
116                 '*.doxygen' => ['Doxygen', ],
117                 '*.e' => ['E Language', 'Eiffel', 'Euphoria', ],
118                 '*.ebuild' => ['Bash', ],
119                 '*.eclass' => ['Bash', ],
120                 '*.eml' => ['Email', ],
121                 '*.eps' => ['PostScript', ],
122                 '*.err' => ['4GL', ],
123                 '*.ex' => ['Euphoria', ],
124                 '*.exu' => ['Euphoria', ],
125                 '*.exw' => ['Euphoria', ],
126                 '*.f' => ['Fortran', ],
127                 '*.f90' => ['Fortran', ],
128                 '*.f95' => ['Fortran', ],
129                 '*.fe' => ['ferite', ],
130                 '*.feh' => ['ferite', ],
131                 '*.flex' => ['Lex/Flex', ],
132                 '*.for' => ['Fortran', ],
133                 '*.fpp' => ['Fortran', ],
134                 '*.frag' => ['GLSL', ],
135                 '*.gdl' => ['GDL', ],
136                 '*.glsl' => ['GLSL', ],
137                 '*.guile' => ['Scheme', ],
138                 '*.h' => ['C++', 'C', 'ANSI C89', 'Inform', 'LPC', 'Objective-C', ],
139                 '*.h++' => ['C++', ],
140                 '*.hcc' => ['C++', ],
141                 '*.hpp' => ['C++', ],
142                 '*.hs' => ['Haskell', ],
143                 '*.hsp' => ['Spice', ],
144                 '*.ht' => ['Apache Configuration', ],
145                 '*.htm' => ['HTML', ],
146                 '*.html' => ['HTML', 'Mason', ],
147                 '*.hxx' => ['C++', ],
148                 '*.i' => ['progress', ],
149                 '*.idl' => ['IDL', ],
150                 '*.inc' => ['POV-Ray', 'PHP (HTML)', 'LPC', ],
151                 '*.inf' => ['Inform', ],
152                 '*.ini' => ['INI Files', ],
153                 '*.java' => ['Java', ],
154                 '*.js' => ['JavaScript', ],
155                 '*.jsp' => ['JSP', ],
156                 '*.katetemplate' => ['Kate File Template', ],
157                 '*.kbasic' => ['KBasic', ],
158                 '*.kdelnk' => ['.desktop', ],
159                 '*.l' => ['Lex/Flex', ],
160                 '*.ldif' => ['LDIF', ],
161                 '*.lex' => ['Lex/Flex', ],
162                 '*.lgo' => ['de_DE', 'en_US', 'nl', ],
163                 '*.lgt' => ['Logtalk', ],
164                 '*.lhs' => ['Literate Haskell', ],
165                 '*.lisp' => ['Common Lisp', ],
166                 '*.logo' => ['de_DE', 'en_US', 'nl', ],
167                 '*.lsp' => ['Common Lisp', ],
168                 '*.lua' => ['Lua', ],
169                 '*.ly' => ['LilyPond', ],
170                 '*.m' => ['Matlab', 'Objective-C', 'Octave', ],
171                 '*.m3u' => ['M3U', ],
172                 '*.mab' => ['MAB-DB', ],
173                 '*.md' => ['Modula-2', ],
174                 '*.mi' => ['Modula-2', ],
175                 '*.ml' => ['Objective Caml', 'SML', ],
176                 '*.mli' => ['Objective Caml', ],
177                 '*.moc' => ['C++', ],
178                 '*.mod' => ['Modula-2', ],
179                 '*.mup' => ['Music Publisher', ],
180                 '*.not' => ['Music Publisher', ],
181                 '*.o' => ['LPC', ],
182                 '*.octave' => ['Octave', ],
183                 '*.p' => ['Pascal', 'progress', ],
184                 '*.pas' => ['Pascal', ],
185                 '*.pb' => ['PureBasic', ],
186                 '*.per' => ['4GL-PER', ],
187                 '*.per.err' => ['4GL-PER', ],
188                 '*.php' => ['PHP (HTML)', ],
189                 '*.php3' => ['PHP (HTML)', ],
190                 '*.phtm' => ['PHP (HTML)', ],
191                 '*.phtml' => ['PHP (HTML)', ],
192                 '*.pic' => ['PicAsm', ],
193                 '*.pike' => ['Pike', ],
194                 '*.pl' => ['Perl', ],
195                 '*.pls' => ['INI Files', ],
196                 '*.pm' => ['Perl', ],
197                 '*.po' => ['GNU Gettext', ],
198                 '*.pot' => ['GNU Gettext', ],
199                 '*.pov' => ['POV-Ray', ],
200                 '*.pp' => ['Pascal', ],
201                 '*.prg' => ['xHarbour', 'Clipper', ],
202                 '*.pro' => ['RSI IDL', ],
203                 '*.prolog' => ['Prolog', ],
204                 '*.ps' => ['PostScript', ],
205                 '*.py' => ['Python', ],
206                 '*.pyw' => ['Python', ],
207                 '*.rb' => ['Ruby', ],
208                 '*.rc' => ['XML', ],
209                 '*.rdf' => ['XML', ],
210                 '*.reg' => ['WINE Config', ],
211                 '*.rex' => ['REXX', ],
212                 '*.rib' => ['RenderMan RIB', ],
213                 '*.s' => ['GNU Assembler', 'MIPS Assembler', ],
214                 '*.sa' => ['Sather', ],
215                 '*.sce' => ['scilab', ],
216                 '*.scheme' => ['Scheme', ],
217                 '*.sci' => ['scilab', ],
218                 '*.scm' => ['Scheme', ],
219                 '*.sgml' => ['SGML', ],
220                 '*.sh' => ['Bash', ],
221                 '*.shtm' => ['HTML', ],
222                 '*.shtml' => ['HTML', ],
223                 '*.siv' => ['Sieve', ],
224                 '*.sml' => ['SML', ],
225                 '*.sp' => ['Spice', ],
226                 '*.spec' => ['RPM Spec', ],
227                 '*.sql' => ['SQL', 'SQL (MySQL)', 'SQL (PostgreSQL)', ],
228                 '*.src' => ['PicAsm', ],
229                 '*.ss' => ['Scheme', ],
230                 '*.t2t' => ['txt2tags', ],
231                 '*.tcl' => ['Tcl/Tk', ],
232                 '*.tdf' => ['AHDL', ],
233                 '*.tex' => ['LaTeX', ],
234                 '*.tji' => ['TaskJuggler', ],
235                 '*.tjp' => ['TaskJuggler', ],
236                 '*.tk' => ['Tcl/Tk', ],
237                 '*.tst' => ['BaseTestchild', ],
238                 '*.uc' => ['UnrealScript', ],
239                 '*.v' => ['Verilog', ],
240                 '*.vcg' => ['GDL', ],
241                 '*.vert' => ['GLSL', ],
242                 '*.vhd' => ['VHDL', ],
243                 '*.vhdl' => ['VHDL', ],
244                 '*.vl' => ['Verilog', ],
245                 '*.vm' => ['Velocity', ],
246                 '*.w' => ['progress', ],
247                 '*.wml' => ['PHP (HTML)', ],
248                 '*.wrl' => ['VRML', ],
249                 '*.xml' => ['XML', ],
250                 '*.xsl' => ['xslt', ],
251                 '*.xslt' => ['xslt', ],
252                 '*.y' => ['Yacc/Bison', ],
253                 '*.ys' => ['yacas', ],
254                 '*Makefile*' => ['Makefile', ],
255                 '*makefile*' => ['Makefile', ],
256                 '*patch' => ['Diff', ],
257                 'CMakeLists.txt' => ['CMake', ],
258                 'ChangeLog' => ['ChangeLog', ],
259                 'QRPGLESRC.*' => ['ILERPG', ],
260                 'apache.conf' => ['Apache Configuration', ],
261                 'apache2.conf' => ['Apache Configuration', ],
262                 'httpd.conf' => ['Apache Configuration', ],
263                 'httpd2.conf' => ['Apache Configuration', ],
264                 'xorg.conf' => ['x.org Configuration', ],
265         };
266         $self->{'sections'} = {
267                 'Assembler' => [
268                         'AVR Assembler',
269                         'Asm6502',
270                         'GNU Assembler',
271                         'Intel x86 (NASM)',
272                         'MIPS Assembler',
273                         'PicAsm',
274                 ],
275                 'Configuration' => [
276                         '.desktop',
277                         'Apache Configuration',
278                         'Cisco',
279                         'INI Files',
280                         'WINE Config',
281                         'x.org Configuration',
282                 ],
283                 'Database' => [
284                         '4GL',
285                         '4GL-PER',
286                         'LDIF',
287                         'SQL',
288                         'SQL (MySQL)',
289                         'SQL (PostgreSQL)',
290                         'progress',
291                 ],
292                 'Hardware' => [
293                         'AHDL',
294                         'Spice',
295                         'VHDL',
296                         'Verilog',
297                 ],
298                 'Logo' => [
299                         'de_DE',
300                         'en_US',
301                         'nl',
302                 ],
303                 'Markup' => [
304                         'ASP',
305                         'BibTeX',
306                         'CSS',
307                         'ColdFusion',
308                         'Doxygen',
309                         'GNU Gettext',
310                         'HTML',
311                         'JSP',
312                         'Javadoc',
313                         'Kate File Template',
314                         'LaTeX',
315                         'MAB-DB',
316                         'PostScript',
317                         'SGML',
318                         'VRML',
319                         'Wikimedia',
320                         'XML',
321                         'txt2tags',
322                         'xslt',
323                 ],
324                 'Other' => [
325                         'ABC',
326                         'Alerts',
327                         'CMake',
328                         'CSS/PHP',
329                         'CUE Sheet',
330                         'ChangeLog',
331                         'Debian Changelog',
332                         'Debian Control',
333                         'Diff',
334                         'Email',
335                         'JavaScript/PHP',
336                         'LilyPond',
337                         'M3U',
338                         'Makefile',
339                         'Music Publisher',
340                         'POV-Ray',
341                         'RPM Spec',
342                         'RenderMan RIB',
343                 ],
344                 'Scientific' => [
345                         'GDL',
346                         'Matlab',
347                         'Octave',
348                         'TI Basic',
349                         'scilab',
350                 ],
351                 'Script' => [
352                         'Ansys',
353                 ],
354                 'Scripts' => [
355                         'AWK',
356                         'Bash',
357                         'Common Lisp',
358                         'Euphoria',
359                         'JavaScript',
360                         'Lua',
361                         'Mason',
362                         'PHP (HTML)',
363                         'PHP/PHP',
364                         'Perl',
365                         'Pike',
366                         'Python',
367                         'Quake Script',
368                         'R Script',
369                         'REXX',
370                         'Ruby',
371                         'Scheme',
372                         'Sieve',
373                         'TaskJuggler',
374                         'Tcl/Tk',
375                         'UnrealScript',
376                         'Velocity',
377                         'ferite',
378                 ],
379                 'Sources' => [
380                         'ANSI C89',
381                         'Ada',
382                         'C',
383                         'C#',
384                         'C++',
385                         'CGiS',
386                         'Cg',
387                         'Clipper',
388                         'Component-Pascal',
389                         'D',
390                         'E Language',
391                         'Eiffel',
392                         'Fortran',
393                         'FreeBASIC',
394                         'GLSL',
395                         'Haskell',
396                         'IDL',
397                         'ILERPG',
398                         'Inform',
399                         'Java',
400                         'KBasic',
401                         'LPC',
402                         'Lex/Flex',
403                         'Literate Haskell',
404                         'Logtalk',
405                         'Modula-2',
406                         'Objective Caml',
407                         'Objective-C',
408                         'Pascal',
409                         'Prolog',
410                         'PureBasic',
411                         'RSI IDL',
412                         'SML',
413                         'Sather',
414                         'Stata',
415                         'Yacc/Bison',
416                         'xHarbour',
417                         'yacas',
418                 ],
419                 'Test' => [
420                         'BaseTest',
421                         'BaseTestchild',
422                 ],
423         };
424         $self->{'syntaxes'} = {
425                 '.desktop' => 'Desktop',
426                 '4GL' => 'FourGL',
427                 '4GL-PER' => 'FourGLminusPER',
428                 'ABC' => 'ABC',
429                 'AHDL' => 'AHDL',
430                 'ANSI C89' => 'ANSI_C89',
431                 'ASP' => 'ASP',
432                 'AVR Assembler' => 'AVR_Assembler',
433                 'AWK' => 'AWK',
434                 'Ada' => 'Ada',
435                 'Alerts' => 'Alerts',
436                 'Ansys' => 'Ansys',
437                 'Apache Configuration' => 'Apache_Configuration',
438                 'Asm6502' => 'Asm6502',
439                 'BaseTest' => 'BaseTest',
440                 'BaseTestchild' => 'BaseTestchild',
441                 'Bash' => 'Bash',
442                 'BibTeX' => 'BibTeX',
443                 'C' => 'C',
444                 'C#' => 'Cdash',
445                 'C++' => 'Cplusplus',
446                 'CGiS' => 'CGiS',
447                 'CMake' => 'CMake',
448                 'CSS' => 'CSS',
449                 'CSS/PHP' => 'CSS_PHP',
450                 'CUE Sheet' => 'CUE_Sheet',
451                 'Cg' => 'Cg',
452                 'ChangeLog' => 'ChangeLog',
453                 'Cisco' => 'Cisco',
454                 'Clipper' => 'Clipper',
455                 'ColdFusion' => 'ColdFusion',
456                 'Common Lisp' => 'Common_Lisp',
457                 'Component-Pascal' => 'ComponentminusPascal',
458                 'D' => 'D',
459                 'Debian Changelog' => 'Debian_Changelog',
460                 'Debian Control' => 'Debian_Control',
461                 'Diff' => 'Diff',
462                 'Doxygen' => 'Doxygen',
463                 'E Language' => 'E_Language',
464                 'Eiffel' => 'Eiffel',
465                 'Email' => 'Email',
466                 'Euphoria' => 'Euphoria',
467                 'Fortran' => 'Fortran',
468                 'FreeBASIC' => 'FreeBASIC',
469                 'GDL' => 'GDL',
470                 'GLSL' => 'GLSL',
471                 'GNU Assembler' => 'GNU_Assembler',
472                 'GNU Gettext' => 'GNU_Gettext',
473                 'HTML' => 'HTML',
474                 'Haskell' => 'Haskell',
475                 'IDL' => 'IDL',
476                 'ILERPG' => 'ILERPG',
477                 'INI Files' => 'INI_Files',
478                 'Inform' => 'Inform',
479                 'Intel x86 (NASM)' => 'Intel_x86_NASM',
480                 'JSP' => 'JSP',
481                 'Java' => 'Java',
482                 'JavaScript' => 'JavaScript',
483                 'JavaScript/PHP' => 'JavaScript_PHP',
484                 'Javadoc' => 'Javadoc',
485                 'KBasic' => 'KBasic',
486                 'Kate File Template' => 'Kate_File_Template',
487                 'LDIF' => 'LDIF',
488                 'LPC' => 'LPC',
489                 'LaTeX' => 'LaTeX',
490                 'Lex/Flex' => 'Lex_Flex',
491                 'LilyPond' => 'LilyPond',
492                 'Literate Haskell' => 'Literate_Haskell',
493                 'Logtalk' => 'Logtalk',
494                 'Lua' => 'Lua',
495                 'M3U' => 'M3U',
496                 'MAB-DB' => 'MABminusDB',
497                 'MIPS Assembler' => 'MIPS_Assembler',
498                 'Makefile' => 'Makefile',
499                 'Mason' => 'Mason',
500                 'Matlab' => 'Matlab',
501                 'Modula-2' => 'Modulaminus2',
502                 'Music Publisher' => 'Music_Publisher',
503                 'Objective Caml' => 'Objective_Caml',
504                 'Objective-C' => 'ObjectiveminusC',
505                 'Octave' => 'Octave',
506                 'PHP (HTML)' => 'PHP_HTML',
507                 'PHP/PHP' => 'PHP_PHP',
508                 'POV-Ray' => 'POVminusRay',
509                 'Pascal' => 'Pascal',
510                 'Perl' => 'Perl',
511                 'PicAsm' => 'PicAsm',
512                 'Pike' => 'Pike',
513                 'PostScript' => 'PostScript',
514                 'Prolog' => 'Prolog',
515                 'PureBasic' => 'PureBasic',
516                 'Python' => 'Python',
517                 'Quake Script' => 'Quake_Script',
518                 'R Script' => 'R_Script',
519                 'REXX' => 'REXX',
520                 'RPM Spec' => 'RPM_Spec',
521                 'RSI IDL' => 'RSI_IDL',
522                 'RenderMan RIB' => 'RenderMan_RIB',
523                 'Ruby' => 'Ruby',
524                 'SGML' => 'SGML',
525                 'SML' => 'SML',
526                 'SQL' => 'SQL',
527                 'SQL (MySQL)' => 'SQL_MySQL',
528                 'SQL (PostgreSQL)' => 'SQL_PostgreSQL',
529                 'Sather' => 'Sather',
530                 'Scheme' => 'Scheme',
531                 'Sieve' => 'Sieve',
532                 'Spice' => 'Spice',
533                 'Stata' => 'Stata',
534                 'TI Basic' => 'TI_Basic',
535                 'TaskJuggler' => 'TaskJuggler',
536                 'Tcl/Tk' => 'Tcl_Tk',
537                 'UnrealScript' => 'UnrealScript',
538                 'VHDL' => 'VHDL',
539                 'VRML' => 'VRML',
540                 'Velocity' => 'Velocity',
541                 'Verilog' => 'Verilog',
542                 'WINE Config' => 'WINE_Config',
543                 'Wikimedia' => 'Wikimedia',
544                 'XML' => 'XML',
545                 'Yacc/Bison' => 'Yacc_Bison',
546                 'de_DE' => 'De_DE',
547                 'en_US' => 'En_US',
548                 'ferite' => 'Ferite',
549                 'nl' => 'Nl',
550                 'progress' => 'Progress',
551                 'scilab' => 'Scilab',
552                 'txt2tags' => 'Txt2tags',
553                 'x.org Configuration' => 'Xorg_Configuration',
554                 'xHarbour' => 'XHarbour',
555                 'xslt' => 'Xslt',
556                 'yacas' => 'Yacas',
557         };
558         #end autoinsert
559         $self->{'language '} = '';
560         bless ($self, $class);
561         if ($language ne '') {
562                 $self->language($language);
563         }
564         return $self;
565 }
566
567 sub extensions {
568         my $self = shift;
569         return $self->{'extensions'};
570 }
571
572 #overriding Template's initialize method. now it should not do anything.
573 sub initialize {
574         my $cw = shift;
575 }
576
577 sub language {
578         my $self = shift;
579         if (@_) {
580                 $self->{'language'} = shift;
581                 $self->reset;
582         }
583         return $self->{'language'};
584 }
585
586 sub languageAutoSet {
587         my ($self, $file) = @_;
588         my $lang = $self->languagePropose($file);
589         if (defined $lang) {
590                 $self->language($lang)
591         } else {
592                 $self->language('Off')
593         }
594 }
595
596 sub languageList {
597         my $self = shift;
598         my $l = $self->{'syntaxes'};
599         return sort {uc($a) cmp uc($b)} keys %$l;
600 }
601
602 sub languagePropose {
603         my ($self, $file) = @_;
604         my $hsh = $self->extensions;
605         foreach my $key (keys %$hsh) {
606                 my $reg = $key;
607                 $reg =~ s/\./\\./g;
608                 $reg =~ s/\+/\\+/g;
609                 $reg =~ s/\*/.*/g;
610                 $reg = "$reg\$";
611                 if ($file =~ /$reg/) {
612                         return $hsh->{$key}->[0]
613                 }
614         }
615         return undef;
616 }
617
618 sub languagePlug {
619         my ($self, $req) = @_;
620         unless (exists($self->{'syntaxes'}->{$req})) {
621                 warn "undefined language: $req";
622                 return undef;
623         }
624         return $self->{'syntaxes'}->{$req};
625 }
626
627 sub reset {
628         my $self = shift;
629         my $lang = $self->language;
630         if ($lang eq 'Off') {
631                 $self->stack([]);
632         } else {
633                 my $plug        = $self->pluginGet($lang);
634                 my $basecontext = $plug->basecontext;
635                 $self->stack([
636                         [$plug, $basecontext]
637                 ]);
638         }
639         $self->out([]);
640         $self->snippet('');
641 }
642
643 sub sections {
644         my $self = shift;
645         return $self->{'sections'};
646 }
647
648 sub syntaxes {
649         my $self = shift;
650         return $self->{'syntaxes'}
651 }
652
653
654 1;
655
656 __END__
657
658 =head1 NAME
659
660 Syntax::Highlight::Engine::Kate - a port to Perl of the syntax highlight engine of the Kate texteditor.
661
662 =head1 SYNOPSIS
663
664  #if you want to create a compiled executable, you may want to do this:
665  use Syntax::Highlight::Engine::Kate::All;
666  
667  use Syntax::Highlight::Engine::Kate;
668  my $hl = new Syntax::Highlight::Engine::Kate(
669     language => 'Perl',
670     substitutions => {
671        "<" => "&lt;",
672        ">" => "&gt;",
673        "&" => "&amp;",
674        " " => "&nbsp;",
675        "\t" => "&nbsp;&nbsp;&nbsp;",
676        "\n" => "<BR>\n",
677     },
678     format_table => {
679        Alert => ["<font color=\"#0000ff\">", "</font>"],
680        BaseN => ["<font color=\"#007f00\">", "</font>"],
681        BString => ["<font color=\"#c9a7ff\">", "</font>"],
682        Char => ["<font color=\"#ff00ff\">", "</font>"],
683        Comment => ["<font color=\"#7f7f7f\"><i>", "</i></font>"],
684        DataType => ["<font color=\"#0000ff\">", "</font>"],
685        DecVal => ["<font color=\"#00007f\">", "</font>"],
686        Error => ["<font color=\"#ff0000\"><b><i>", "</i></b></font>"],
687        Float => ["<font color=\"#00007f\">", "</font>"],
688        Function => ["<font color=\"#007f00\">", "</font>"],
689        IString => ["<font color=\"#ff0000\">", ""],
690        Keyword => ["<b>", "</b>"],
691        Normal => ["", ""],
692        Operator => ["<font color=\"#ffa500\">", "</font>"],
693        Others => ["<font color=\"#b03060\">", "</font>"],
694        RegionMarker => ["<font color=\"#96b9ff\"><i>", "</i></font>"],
695        Reserved => ["<font color=\"#9b30ff\"><b>", "</b></font>"],
696        String => ["<font color=\"#ff0000\">", "</font>"],
697        Variable => ["<font color=\"#0000ff\"><b>", "</b></font>"],
698        Warning => ["<font color=\"#0000ff\"><b><i>", "</b></i></font>"],
699     },
700  );
701  
702  #or
703  
704  my $hl = new Syntax::Highlight::Engine::Kate::Perl(
705     substitutions => {
706        "<" => "&lt;",
707        ">" => "&gt;",
708        "&" => "&amp;",
709        " " => "&nbsp;",
710        "\t" => "&nbsp;&nbsp;&nbsp;",
711        "\n" => "<BR>\n",
712     },
713     format_table => {
714        Alert => ["<font color=\"#0000ff\">", "</font>"],
715        BaseN => ["<font color=\"#007f00\">", "</font>"],
716        BString => ["<font color=\"#c9a7ff\">", "</font>"],
717        Char => ["<font color=\"#ff00ff\">", "</font>"],
718        Comment => ["<font color=\"#7f7f7f\"><i>", "</i></font>"],
719        DataType => ["<font color=\"#0000ff\">", "</font>"],
720        DecVal => ["<font color=\"#00007f\">", "</font>"],
721        Error => ["<font color=\"#ff0000\"><b><i>", "</i></b></font>"],
722        Float => ["<font color=\"#00007f\">", "</font>"],
723        Function => ["<font color=\"#007f00\">", "</font>"],
724        IString => ["<font color=\"#ff0000\">", ""],
725        Keyword => ["<b>", "</b>"],
726        Normal => ["", ""],
727        Operator => ["<font color=\"#ffa500\">", "</font>"],
728        Others => ["<font color=\"#b03060\">", "</font>"],
729        RegionMarker => ["<font color=\"#96b9ff\"><i>", "</i></font>"],
730        Reserved => ["<font color=\"#9b30ff\"><b>", "</b></font>"],
731        String => ["<font color=\"#ff0000\">", "</font>"],
732        Variable => ["<font color=\"#0000ff\"><b>", "</b></font>"],
733        Warning => ["<font color=\"#0000ff\"><b><i>", "</b></i></font>"],
734     },
735  );
736  
737  
738  print "<html>\n<head>\n</head>\n<body>\n";
739  while (my $in = <>) {
740     print $hl->highlightText($in);
741  }
742  print "</body>\n</html>\n";
743
744 =head1 DESCRIPTION
745
746 Syntax::Highlight::Engine::Kate is a port to perl of the syntax highlight engine of the 
747 Kate text editor.
748
749 The language xml files of kate have been rewritten to perl modules using a script. These modules 
750 function as plugins to this module.
751
752 Syntax::Highlight::Engine::Kate inherits Syntax::Highlight::Engine::Kate::Template.
753
754 =head1 OPTIONS
755
756 =over 4
757
758 =item B<language>
759
760 Specify the language you want highlighted.
761 look in the B<PLUGINS> section for supported languages.
762
763
764
765 =item B<plugins>
766
767 If you created your own language plugins you may specify a list of them with this option.
768
769  plugins => [
770    ["MyModuleName", "MyLanguageName", "*,ext1;*.ext2", "Section"],
771    ....
772  ]
773
774 =item B<format_table>
775
776 This option must be specified if the B<highlightText> method needs to do anything usefull for you.
777 All mentioned keys in the synopsis must be specified.
778
779
780 =item B<substitutions>
781
782 With this option you can specify additional formatting options.
783
784
785 =back
786
787 =head1 METHODS
788
789 =over 4
790
791 =item B<extensions>
792
793 returns a reference to the extensions hash,
794
795 =item B<language>(I<?$language?>)
796
797 Sets and returns the current language that is highlighted. when setting the language a reset is also done.
798
799 =item B<languageAutoSet>(I<$filename>);
800
801 Suggests language name for the fiven file B<$filename>
802
803 =item B<languageList>
804
805 returns a list of languages for which plugins have been defined.
806
807 =item B<languagePlug>(I<$language>);
808
809 returns the module name of the plugin for B<$language>
810
811 =item B<languagePropose>(I<$filename>);
812
813 Suggests language name for the fiven file B<$filename>
814
815 =item B<sections>
816
817 Returns a reference to the sections hash.
818
819 =back
820
821 =head1 ATTRIBUTES
822
823 In the kate XML syntax files you find under the section B<<itemDatas>> entries like 
824 <itemData name="Unknown Property"  defStyleNum="dsError" italic="1"/>. Kate is an editor
825 so it is ok to have definitions for forground and background colors and so on. However, 
826 since this Module is supposed to be a more universal highlight engine, the attributes need
827 to be fully abstract. In which case, Kate does not have enough default attributes defined
828 to fullfill all needs. Kate defines the following standard attributes: B<dsNormal>, B<dsKeyword>, 
829 B<dsDataType>, B<dsDecVal>, B<dsBaseN>, B<dsFloat>, B<dsChar>, B<dsString>, B<dsComment>, B<dsOthers>, 
830 B<dsAlert>, B<dsFunction>, B<dsRegionMarker>, B<dsError>. This module leaves out the "ds" part and uses 
831 following additional attributes: B<BString>, B<IString>, B<Operator>, B<Reserved>, B<Variable>. I have 
832 modified the XML files so that each highlight mode would get it's own attribute. In quite a few cases
833 still not enough attributes were defined. So in some languages different modes have the same attribute.
834
835 =head1 PLUGINS
836
837 Below an overview of existing plugins. All have been tested on use and can be created. The ones for which no samplefile
838 is available are marked. Those marked OK have highlighted the testfile without appearant mistakes. This does
839 not mean that all bugs are shaken out. 
840
841  LANGUAGE             MODULE                   COMMENT
842  ********             ******                   ******
843  .desktop             Desktop                  OK
844  4GL                  FourGL                   No sample file
845  4GL-PER              FourGLminusPER           No sample file
846  ABC                  ABC                      OK
847  AHDL                 AHDL                     OK
848  ANSI C89             ANSI_C89                 No sample file
849  ASP                  ASP                      OK
850  AVR Assembler        AVR_Assembler            OK
851  AWK                  AWK                      OK
852  Ada                  Ada                      No sample file
853                       Alerts                   OK hidden module
854  Ansys                Ansys                    No sample file
855  Apache Configuration Apache_Configuration     No sample file
856  Asm6502              Asm6502                  No sample file
857  Bash                 Bash                     OK
858  BibTeX               BibTex                   OK
859  C                    C                        No sample file
860  C#                   Cdash                    No sample file
861  C++                  Cplusplus                OK
862  CGiS                 CGiS                     No sample file
863  CMake                CMake                    OK
864  CSS                  CSS                      OK
865  CUE Sheet            CUE_Sheet                No sample file
866  Cg                   Cg                       No sample file
867  ChangeLog            ChangeLog                No sample file
868  Cisco                Cisco                    No sample file
869  Clipper              Clipper                  OK
870  ColdFusion           ColdFusion               No sample file
871  Common Lisp          Common_Lisp              OK
872  Component-Pascal     ComponentminusPascal     No sample file
873  D                    D                        No sample file
874  Debian Changelog     Debian_Changelog         No sample file
875  Debian Control       Debian_Control           No sample file
876  Diff                 Diff                     No sample file
877  Doxygen              Doxygen                  OK
878  E Language           E_Language               OK
879  Eiffel               Eiffel                   No sample file
880  Email                Email                    OK
881  Euphoria             Euphoria                 OK
882  Fortran              Fortran                  OK
883  FreeBASIC            FreeBASIC                No sample file
884  GDL                  GDL                      No sample file
885  GLSL                 GLSL                     OK
886  GNU Assembler        GNU_Assembler            No sample file
887  GNU Gettext          GNU_Gettext              No sample file
888  HTML                 HTML                     OK
889  Haskell              Haskell                  OK
890  IDL                  IDL                      No sample file
891  ILERPG               ILERPG                   No sample file
892  INI Files            INI_Files                No sample file
893  Inform               Inform                   No sample file
894  Intel x86 (NASM)     Intel_X86_NASM           seems to have issues
895  JSP                  JSP                      OK
896  Java                 Java                     OK
897  JavaScript           JavaScript               OK
898  Javadoc              Javadoc                  No sample file
899  KBasic               KBasic                   No sample file
900  Kate File Template   Kate_File_Template       No sample file
901  LDIF                 LDIF                     No sample file
902  LPC                  LPC                      No sample file
903  LaTeX                LaTex                    OK
904  Lex/Flex             Lex_Flex                 OK
905  LilyPond             LilyPond                 OK
906  Literate Haskell     Literate_Haskell         OK
907  Lua                  Lua                      No sample file
908  M3U                  M3U                      OK
909  MAB-DB               MABminusDB               No sample file
910  MIPS Assembler       MIPS_Assembler           No sample file
911  Makefile             Makefile                 No sample file
912  Mason                Mason                    No sample file
913  Matlab               Matlab                   has issues
914  Modula-2             Modulaminus2             No sample file
915  Music Publisher      Music_Publisher          No sample file
916  Octave               Octave                   OK
917  PHP (HTML)           PHP_HTML                 OK
918                       PHP_PHP                  OK hidden module
919  POV-Ray              POV_Ray                  OK
920  Pascal               Pascal                   No sample file
921  Perl                 Perl                     OK
922  PicAsm               PicAsm                   OK
923  Pike                 Pike                     OK
924  PostScript           PostScript               OK
925  Prolog               Prolog                   No sample file
926  PureBasic            PureBasic                OK
927  Python               Python                   OK
928  Quake Script         Quake_Script             No sample file
929  R Script             R_Script                 No sample file
930  REXX                 REXX                     No sample file
931  RPM Spec             RPM_Spec                 No sample file
932  RSI IDL              RSI_IDL                  No sample file
933  RenderMan RIB        RenderMan_RIB            OK
934  Ruby                 Ruby                     OK
935  SGML                 SGML                     No sample file
936  SML                  SML                      No sample file
937  SQL                  SQL                      No sample file
938  SQL (MySQL)          SQL_MySQL                No sample file
939  SQL (PostgreSQL)     SQL_PostgreSQL           No sample file
940  Sather               Sather                   No sample file
941  Scheme               Scheme                   OK
942  Sieve                Sieve                    No sample file
943  Spice                Spice                    OK
944  Stata                Stata                    OK
945  TI Basic             TI_Basic                 No sample file
946  TaskJuggler          TaskJuggler              No sample file
947  Tcl/Tk               TCL_Tk                   OK
948  UnrealScript         UnrealScript             OK
949  VHDL                 VHDL                     No sample file
950  VRML                 VRML                     OK
951  Velocity             Velocity                 No sample file
952  Verilog              Verilog                  No sample file
953  WINE Config          WINE_Config              No sample file
954  Wikimedia            Wikimedia                No sample file
955  XML                  XML                      OK
956  XML (Debug)          XML_Debug                No sample file
957  Yacc/Bison           Yacc_Bison               OK
958  de_DE                De_DE                    No sample file
959  en_EN                En_EN                    No sample file
960  ferite               Ferite                   No sample file
961  nl                   Nl                       No sample file
962  progress             Progress                 No sample file
963  scilab               Scilab                   No sample file
964  txt2tags             Txt2tags                 No sample file
965  x.org Configuration  X_org_Configuration      OK
966  xHarbour             XHarbour                 OK
967  xslt                 Xslt                     No sample file
968  yacas                Yacas                    No sample file
969
970
971 =head1 BUGS
972
973 Float is detected differently than in the Kate editor.
974
975 The regular expression engine of the Kate editor, qregexp, appears to be more tolerant to mistakes
976 in regular expressions than perl. This might lead to error messages and differences in behaviour. 
977 Most of the problems were sorted out while developing, because error messages appeared. For as far
978 as differences in behaviour is concerned, testing is the only way to find out, so i hope the users
979 out there will be able to tell me more.
980
981 This module is mimicking the behaviour of the syntax highlight engine of the Kate editor. If you find
982 a bug/mistake in the highlighting, please check if Kate behaves in the same way. If yes, the cause is
983 likely to be found there.
984
985 =head1 TO DO
986
987 Rebuild the scripts i am using to generate the modules from xml files so they are more pro-actively tracking
988 flaws in the build of the xml files like missing lists. Also regular expressions in the xml can be tested better 
989 before used in plugins.
990
991 Refine the testmethods in Syntax::Highlight::Engine::Kate::Template, so that choices for casesensitivity, 
992 dynamic behaviour and lookahead can be determined at generate time of the plugin, might increase throughput.
993
994 Implement codefolding.
995
996 =head1 ACKNOWLEDGEMENTS
997
998 All the people who wrote Kate and the syntax highlight xml files.
999
1000 =head1 AUTHOR AND COPYRIGHT
1001
1002 This module is written and maintained by:
1003
1004 Hans Jeuken < haje at toneel dot demon dot nl >
1005
1006 Copyright (c) 2006 by Hans Jeuken, all rights reserved.
1007
1008 You may freely distribute and/or modify this module under the same terms 
1009 as Perl itself. 
1010
1011 =head1 SEE ALSO
1012
1013 Synax::Highlight::Engine::Kate::Template http:://www.kate-editor.org
1014
1015 =cut
1016