NAME
Syntax::Highlight::Engine::Kate - a port to Perl of the syntax highlight engine of the Kate text editor.
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 = Syntax::Highlight::Engine::Kate->new(language => 'Perl',substitutions => {"<" => "<",">" => ">","&" => "&"," " => " ","\t" => " ","\n" => "<BR>\n",},format_table => {Alert => [ "<font color=\"#0000ff\">", "</font>" ],BaseN => [ "<font color=\"#007f00\">", "</font>" ],BString => [ "<font color=\"#c9a7ff\">", "</font>" ],Char => [ "<font color=\"#ff00ff\">", "</font>" ],Comment => [ "<font color=\"#7f7f7f\"><i>", "</i></font>" ],DataType => [ "<font color=\"#0000ff\">", "</font>" ],DecVal => [ "<font color=\"#00007f\">", "</font>" ],Error => [ "<font color=\"#ff0000\"><b><i>", "</i></b></font>" ],Float => [ "<font color=\"#00007f\">", "</font>" ],Function => [ "<font color=\"#007f00\">", "</font>" ],IString => [ "<font color=\"#ff0000\">", "" ],Keyword => [ "<b>", "</b>" ],Normal => [ "", "" ],Operator => [ "<font color=\"#ffa500\">", "</font>" ],Others => [ "<font color=\"#b03060\">", "</font>" ],RegionMarker => [ "<font color=\"#96b9ff\"><i>", "</i></font>" ],Reserved => [ "<font color=\"#9b30ff\"><b>", "</b></font>" ],String => [ "<font color=\"#ff0000\">", "</font>" ],Variable => [ "<font color=\"#0000ff\"><b>", "</b></font>" ],Warning => [ "<font color=\"#0000ff\"><b><i>", "</b></i></font>" ],},);#ormy $hl = Syntax::Highlight::Engine::Kate::Perl->new(substitutions => {# ...},format_table => {# ...},);print "<html>\n<head>\n</head>\n<body>\n";while ( my $in = <> ) {print $hl->highlightText($in);}print "</body>\n</html>\n";
DESCRIPTION
This module is now deprecated.
It is superseded and replaced by Syntax::Kamelon. Best use Syntax::Kamelon for new projects.
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.
OPTIONS
- language
-
Specify the language you want highlighted. Look in the PLUGINS section for supported languages.
- plugins
-
If you created your own language plugins you may specify a list of them with this option.
plugins => [["MyModuleName", "MyLanguageName", "*,ext1;*.ext2", "Section"],....]
- format_table
-
This option must be specified if the highlightText method needs to do anything useful for you. All mentioned keys in the synopsis must be specified.
- substitutions
-
With this option you can specify additional formatting options.
METHODS
- extensions
-
Returns a reference to the extensions hash.
- language(?$language?)
-
Sets and returns the current language that is highlighted. When setting the language a reset is also done.
- languageAutoSet($filename)
-
Suggests language name for the given file $filename.
- languageList
-
Returns a list of languages for which plugins have been defined.
- languagePlug($language, ?$insensitive?)
-
Returns the module name of the plugin for $language.
If $insensitive is set it will also try to match names ignoring case and return the correct module name of the plugin.
e.g.
"$highlighter->languagePlug('HtMl', 1);"will return"HTML".
- languagePropose($filename)
-
Suggests language name for the given file $filename.
- sections
-
Returns a reference to the sections hash.
ATTRIBUTES
In the Kate XML syntax files you find under the section <itemDatas> entries like "<itemData name="Unknown Property" defStyleNum="dsError" italic="1"/>". Kate is an editor so it is ok to have definitions for foreground 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 fulfill all needs. Kate defines the following standard attributes:
- •
-
dsNormal
- •
-
dsKeyword
- •
-
dsDataType
- •
-
dsDecVal
- •
-
dsBaseN
- •
-
dsFloat
- •
-
dsChar
- •
-
dsString
- •
-
dsComment
- •
-
dsOthers
- •
-
dsAlert
- •
-
dsFunction
- •
-
dsRegionMarker
- •
-
dsError
This module leaves out the <ds> part and uses following additional attributes:
- •
-
BString
- •
-
IString
- •
-
Operator
- •
-
Reserved
- •
-
Variable
I have modified the XML files so that each highlight mode would get its own attribute. In quite a few cases still not enough attributes were defined. So in some languages different modes have the same attribute.
PLUGINS
Below is an overview of existing plugins. All have been tested on use and can be created. The ones for which no sample file is available are marked. Those marked OK have highlighted the test file without apparent mistakes. This does not mean that all bugs are shaken out.
LANGUAGE MODULE COMMENT******** ****** ******.desktop Desktop OK4GL FourGL No sample file4GL-PER FourGLminusPER No sample fileABC ABC OKAHDL AHDL OKANSI C89 ANSI_C89 No sample fileASP ASP OKAVR Assembler AVR_Assembler OKAWK AWK OKAda Ada No sample fileAlerts OK hidden moduleAnsys Ansys No sample fileApache Configuration Apache_Configuration No sample fileAsm6502 Asm6502 No sample fileBash Bash OKBibTeX BibTeX OKC C No sample fileC# Cdash No sample fileC++ Cplusplus OKCGiS CGiS No sample fileCMake CMake OKCSS CSS OKCUE Sheet CUE_Sheet No sample fileCg Cg No sample fileChangeLog ChangeLog No sample fileCisco Cisco No sample fileClipper Clipper OKColdFusion ColdFusion No sample fileCommon Lisp Common_Lisp OKComponent-Pascal ComponentminusPascal No sample fileD D No sample fileDebian Changelog Debian_Changelog No sample fileDebian Control Debian_Control No sample fileDiff Diff No sample fileDoxygen Doxygen OKE Language E_Language OKEiffel Eiffel No sample fileEmail Email OKEuphoria Euphoria OKFortran Fortran OKFreeBASIC FreeBASIC No sample fileGDL GDL No sample fileGLSL GLSL OKGNU Assembler GNU_Assembler No sample fileGNU Gettext GNU_Gettext No sample fileHTML HTML OKHaskell Haskell OKIDL IDL No sample fileILERPG ILERPG No sample fileINI Files INI_Files No sample fileInform Inform No sample fileIntel x86 (NASM) Intel_X86_NASM seems to have issuesJSP JSP OKJava Java OKJavaScript JavaScript OKJavadoc Javadoc No sample fileKBasic KBasic No sample fileKate File Template Kate_File_Template No sample fileLDIF LDIF No sample fileLPC LPC No sample fileLaTeX LaTex OKLex/Flex Lex_Flex OKLilyPond LilyPond OKLiterate Haskell Literate_Haskell OKLua Lua No sample fileM3U M3U OKMAB-DB MABminusDB No sample fileMIPS Assembler MIPS_Assembler No sample fileMakefile Makefile No sample fileMason Mason No sample fileMatlab Matlab has issuesModula-2 Modulaminus2 No sample fileMusic Publisher Music_Publisher No sample fileOctave Octave OKPHP (HTML) PHP_HTML OKPHP_PHP OK hidden modulePOV-Ray POV_Ray OKPascal Pascal No sample filePerl Perl OKPicAsm PicAsm OKPike Pike OKPostScript PostScript OKProlog Prolog No sample filePureBasic PureBasic OKPython Python OKQuake Script Quake_Script No sample fileR Script R_Script No sample fileREXX REXX No sample fileRPM Spec RPM_Spec No sample fileRSI IDL RSI_IDL No sample fileRenderMan RIB RenderMan_RIB OKRuby Ruby OKSGML SGML No sample fileSML SML No sample fileSQL SQL No sample fileSQL (MySQL) SQL_MySQL No sample fileSQL (PostgreSQL) SQL_PostgreSQL No sample fileSather Sather No sample fileScheme Scheme OKSieve Sieve No sample fileSpice Spice OKStata Stata OKTI Basic TI_Basic No sample fileTaskJuggler TaskJuggler No sample fileTcl/Tk TCL_Tk OKUnrealScript UnrealScript OKVHDL VHDL No sample fileVRML VRML OKVelocity Velocity No sample fileVerilog Verilog No sample fileWINE Config WINE_Config No sample fileWikimedia Wikimedia No sample fileXML XML OKXML (Debug) XML_Debug No sample fileYacc/Bison Yacc_Bison OKde_DE De_DE No sample fileen_EN En_EN No sample fileferite Ferite No sample filenl Nl No sample fileprogress Progress No sample filescilab Scilab No sample filetxt2tags Txt2tags No sample filex.org Configuration X_org_Configuration OKxHarbour XHarbour OKxslt Xslt No sample fileyacas Yacas No sample file
Module Syntax::Highlight::Engine::Kate::Convert::ToolKit and script hl-kate-convert can be used to convert existing Kate/KTextEditor Syntax Highlighting file from XML format to Perl.
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.
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 they are used in plugins.
Refine the test methods in Syntax::Highlight::Engine::Kate::Template, so that choices for case sensitivity, dynamic behaviour and lookahead can be determined at generate time of the plugin, might increase throughput.
Implement code folding.
ACKNOWLEDGEMENTS
All the people who wrote Kate and the syntax highlight XML files.
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.
SEE ALSO
- •
-
Syntax::Highlight::Engine::Kate::Template
- •
-
<http://www.kate-editor.org>
- •
-
KTextEditor Syntax Highlighting Repository <https://quickgit.kde.org/?p=ktexteditor.git&a=tree&f=src%2Fsyntax%2Fdata>