![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/share/doc/source-highlight/ |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- This manual is for GNU Source-highlight (version 3.1.8, 30 March 2015), which given a source file, produces a document with syntax highlighting. Copyright (C) 2005-2008 Lorenzo Bettini, http://www.lorenzobettini.it. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License." --> <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> <head> <title>GNU Source-highlight 3.1.8</title> <meta name="description" content="GNU Source-highlight 3.1.8"> <meta name="keywords" content="GNU Source-highlight 3.1.8"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="#Top" rel="start" title="Top"> <link href="#Concept-Index" rel="index" title="Concept Index"> <link href="#SEC_Contents" rel="contents" title="Table of Contents"> <link href="dir.html#Top" rel="up" title="(dir)"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.indentedblock {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smallindentedblock {margin-left: 3.2em; font-size: smaller} div.smalllisp {margin-left: 3.2em} kbd {font-style:oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nocodebreak {white-space:nowrap} span.nolinebreak {white-space:nowrap} span.roman {font-family:serif; font-weight:normal} span.sansserif {font-family:sans-serif; font-weight:normal} ul.no-bullet {list-style: none} --> </style> </head> <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> <h1 class="settitle" align="center">GNU Source-highlight 3.1.8</h1> <a name="SEC_Contents"></a> <h2 class="contents-heading">Table of Contents</h2> <div class="contents"> <ul class="no-bullet"> <li><a name="toc-Introduction-1" href="#Introduction">1 Introduction</a> <ul class="no-bullet"> <li><a name="toc-Supported-languages-1" href="#Supported-languages">1.1 Supported languages</a></li> <li><a name="toc-The-program-source_002dhighlight_002dsettings-1" href="#The-program-source_002dhighlight_002dsettings">1.2 The program <code>source-highlight-settings</code></a></li> <li><a name="toc-Notes-on-some-languages-1" href="#Notes-on-some-languages">1.3 Notes on some languages</a> <ul class="no-bullet"> <li><a name="toc-Fortran-1" href="#Fortran">1.3.1 Fortran</a></li> <li><a name="toc-Perl-1" href="#Perl">1.3.2 Perl</a></li> </ul></li> <li><a name="toc-Using-source_002dhighlight-as-a-simple-formatter-1" href="#Using-source_002dhighlight-as-a-simple-formatter">1.4 Using source-highlight as a simple formatter</a></li> <li><a name="toc-Related-Software-and-Links-1" href="#Related-Software-and-Links">1.5 Related Software and Links</a></li> </ul></li> <li><a name="toc-Installation-1" href="#Installation">2 Installation</a> <ul class="no-bullet"> <li><a name="toc-Building-with-qmake-1" href="#Building-with-qmake">2.1 Building with qmake</a></li> <li><a name="toc-Download-1" href="#Download">2.2 Download</a></li> <li><a name="toc-Anonymous-Git-Checkout-1" href="#Anonymous-Git-Checkout">2.3 Anonymous Git Checkout</a></li> <li><a name="toc-What-you-need-to-build-source_002dhighlight-1" href="#What-you-need-to-build-source_002dhighlight">2.4 What you need to build source-highlight</a></li> <li><a name="toc-Tips-on-installing-Boost-Regex-library-1" href="#Tips-on-installing-Boost-Regex-library">2.5 Tips on installing Boost Regex library</a></li> <li><a name="toc-Patching-from-a-previous-version-1" href="#Patching-from-a-previous-version">2.6 Patching from a previous version</a></li> <li><a name="toc-Using-source_002dhighlight-with-less-1" href="#Using-source_002dhighlight-with-less">2.7 Using source-highlight with less</a></li> <li><a name="toc-Using-source_002dhighlight-as-a-CGI-1" href="#Using-source_002dhighlight-as-a-CGI">2.8 Using source-highlight as a CGI</a></li> <li><a name="toc-Building-_002erpm-1" href="#Building-_002erpm">2.9 Building .rpm</a></li> </ul></li> <li><a name="toc-Copying-Conditions" href="#Copying">3 Copying Conditions</a></li> <li><a name="toc-Simple-Usage-1" href="#Simple-Usage">4 Simple Usage</a> <ul class="no-bullet"> <li><a name="toc-HTML-and-XHTML-output-1" href="#HTML-and-XHTML-output">4.1 HTML and XHTML output</a></li> <li><a name="toc-LaTeX-output-1" href="#LaTeX-output">4.2 LaTeX output</a></li> <li><a name="toc-Texinfo-output-1" href="#Texinfo-output">4.3 Texinfo output</a></li> <li><a name="toc-DocBook-output-1" href="#DocBook-output">4.4 DocBook output</a></li> <li><a name="toc-ANSI-color-escape-sequences-1" href="#ANSI-color-escape-sequences">4.5 ANSI color escape sequences</a></li> <li><a name="toc-Odf-output-1" href="#Odf-output">4.6 Odf output</a></li> <li><a name="toc-Groff-output-1" href="#Groff-output">4.7 Groff output</a></li> </ul></li> <li><a name="toc-Configuration-files-1" href="#Configuration-files">5 Configuration files</a> <ul class="no-bullet"> <li><a name="toc-Output-format-style-1" href="#Output-format-style">5.1 Output format style</a></li> <li><a name="toc-Output-format-style-using-CSS-1" href="#Output-format-style-using-CSS">5.2 Output format style using CSS</a></li> <li><a name="toc-Default-Styles-1" href="#Default-Styles">5.3 Default Styles</a></li> <li><a name="toc-Language-map-1" href="#Language-map">5.4 Language map</a></li> <li><a name="toc-Language-definition-files-1" href="#Language-definition-files">5.5 Language definition files</a></li> <li><a name="toc-Output-Language-map-1" href="#Output-Language-map">5.6 Output Language map</a></li> <li><a name="toc-Output-Language-definition-files-1" href="#Output-Language-definition-files">5.7 Output Language definition files</a></li> <li><a name="toc-Developing-your-own-definition-files-1" href="#Developing-your-own-definition-files">5.8 Developing your own definition files</a></li> </ul></li> <li><a name="toc-Invoking-source_002dhighlight-1" href="#Invoking-source_002dhighlight">6 Invoking <code>source-highlight</code></a> <ul class="no-bullet"> <li><a name="toc-How-the-input-language-is-discovered-1" href="#How-the-input-language-is-discovered">6.1 How the input language is discovered</a></li> </ul></li> <li><a name="toc-Language-Definitions-1" href="#Language-Definitions">7 Language Definitions</a> <ul class="no-bullet"> <li><a name="toc-Ways-of-specifying-regular-expressions-1" href="#Ways-of-specifying-regular-expressions">7.1 Ways of specifying regular expressions</a></li> <li><a name="toc-Simple-definitions-1" href="#Simple-definitions">7.2 Simple definitions</a></li> <li><a name="toc-Line-wide-definitions-1" href="#Line-wide-definitions">7.3 Line wide definitions</a></li> <li><a name="toc-Order-of-definitions-1" href="#Order-of-definitions">7.4 Order of definitions</a></li> <li><a name="toc-Delimited-definitions-1" href="#Delimited-definitions">7.5 Delimited definitions</a></li> <li><a name="toc-Variable-definitions-1" href="#Variable-definitions">7.6 Variable definitions</a></li> <li><a name="toc-Dynamic-Backreferences-1" href="#Dynamic-Backreferences">7.7 Dynamic Backreferences</a></li> <li><a name="toc-File-inclusion-1" href="#File-inclusion">7.8 File inclusion</a></li> <li><a name="toc-State_002fEnvironment-Definitions-1" href="#State_002fEnvironment-Definitions">7.9 State/Environment Definitions</a></li> <li><a name="toc-Explicit-subexpressions-with-names-1" href="#Explicit-subexpressions-with-names">7.10 Explicit subexpressions with names</a></li> <li><a name="toc-Redefinitions-and-Substitutions-1" href="#Redefinitions-and-Substitutions">7.11 Redefinitions and Substitutions</a></li> <li><a name="toc-How-source_002dhighlight-works-1" href="#How-source_002dhighlight-works">7.12 How source-highlight works</a></li> <li><a name="toc-Notes-on-regular-expressions-1" href="#Notes-on-regular-expressions">7.13 Notes on regular expressions</a></li> <li><a name="toc-The-program-check_002dregexp-1" href="#The-program-check_002dregexp">7.14 The program <code>check-regexp</code></a></li> <li><a name="toc-Listing-Language-Elements-1" href="#Listing-Language-Elements">7.15 Listing Language Elements</a></li> <li><a name="toc-Concluding-Remarks-1" href="#Concluding-Remarks">7.16 Concluding Remarks</a></li> <li><a name="toc-Debugging-1" href="#Debugging">7.17 Debugging</a></li> <li><a name="toc-Tutorials-on-Language-Definitions-1" href="#Tutorials-on-Language-Definitions">7.18 Tutorials on Language Definitions</a> <ul class="no-bullet"> <li><a name="toc-Highlighting-C_002fC_002b_002b-and-C_0023-1" href="#Highlighting-C_002fC_002b_002b-and-C_0023">7.18.1 Highlighting C/C++ and C#</a></li> <li><a name="toc-Highlighting-Diff-files-1" href="#Highlighting-Diff-files">7.18.2 Highlighting Diff files</a></li> <li><a name="toc-Pseudo-semantic-analysis-1" href="#Pseudo-semantic-analysis">7.18.3 Pseudo semantic analysis</a></li> </ul></li> </ul></li> <li><a name="toc-Output-Language-Definitions-1" href="#Output-Language-Definitions">8 Output Language Definitions</a> <ul class="no-bullet"> <li><a name="toc-File-extension-1" href="#File-extension">8.1 File extension</a></li> <li><a name="toc-Text-styles-1" href="#Text-styles">8.2 Text styles</a></li> <li><a name="toc-Colors-1" href="#Colors">8.3 Colors</a></li> <li><a name="toc-Anchors-and-References-1" href="#Anchors-and-References">8.4 Anchors and References</a></li> <li><a name="toc-One-style-1" href="#One-style">8.5 One style</a></li> <li><a name="toc-Style-template-1" href="#Style-template">8.6 Style template</a></li> <li><a name="toc-Line-prefix-1" href="#Line-prefix">8.7 Line prefix</a></li> <li><a name="toc-String-translation-1" href="#String-translation">8.8 String translation</a></li> <li><a name="toc-Document-template-1" href="#Document-template">8.9 Document template</a></li> <li><a name="toc-Generating-HTML-output-1" href="#Generating-HTML-output">8.10 Generating HTML output</a></li> </ul></li> <li><a name="toc-Generating-References-1" href="#Generating-References">9 Generating References</a></li> <li><a name="toc-Examples-1" href="#Examples">10 Examples</a> <ul class="no-bullet"> <li><a name="toc-Simple-example-1" href="#Simple-example">10.1 Simple example</a></li> <li><a name="toc-References-1" href="#References">10.2 References</a></li> <li><a name="toc-Line-ranges-1" href="#Line-ranges">10.3 Line ranges</a></li> <li><a name="toc-Line-ranges-_0028with-context_0029-1" href="#Line-ranges-_0028with-context_0029">10.4 Line ranges (with context)</a></li> <li><a name="toc-Regex-ranges-1" href="#Regex-ranges">10.5 Regex ranges</a></li> </ul></li> <li><a name="toc-Reporting-Bugs" href="#Problems">11 Reporting Bugs</a></li> <li><a name="toc-Mailing-Lists-1" href="#Mailing-Lists">12 Mailing Lists</a></li> <li><a name="toc-Concept-Index-1" href="#Concept-Index">Concept Index</a></li> </ul> </div> <a name="Top"></a> <div class="header"> <p> Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a>, Previous: <a href="dir.html#Top" accesskey="p" rel="prev">(dir)</a>, Up: <a href="dir.html#Top" accesskey="u" rel="up">(dir)</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="GNU-Source_002dhighlight"></a> <h1 class="top">GNU Source-highlight</h1> <p>GNU Source-highlight, given a source file, produces a document with syntax highlighting. </p> <p>This is Edition 3.1.8 of the Source-highlight manual. </p> <p>This file documents GNU Source-highlight version 3.1.8. </p> <p>This manual is for GNU Source-highlight (version 3.1.8, 30 March 2015), which given a source file, produces a document with syntax highlighting. </p> <p>Copyright © 2005-2008 Lorenzo Bettini, <a href="http://www.lorenzobettini.it">http://www.lorenzobettini.it</a>. </p> <blockquote> <p>Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License.” </p></blockquote> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Introduction" accesskey="1">Introduction</a>:</td><td> </td><td align="left" valign="top">What’s it for? </td></tr> <tr><td align="left" valign="top">• <a href="#Installation" accesskey="2">Installation</a>:</td><td> </td><td align="left" valign="top">Download and installation </td></tr> <tr><td align="left" valign="top">• <a href="#Copying" accesskey="3">Copying</a>:</td><td> </td><td align="left" valign="top">Licence issues </td></tr> <tr><td align="left" valign="top">• <a href="#Simple-Usage" accesskey="4">Simple Usage</a>:</td><td> </td><td align="left" valign="top">Very basic usage </td></tr> <tr><td align="left" valign="top">• <a href="#Configuration-files" accesskey="5">Configuration files</a>:</td><td> </td><td align="left" valign="top">Files needed for execution </td></tr> <tr><td align="left" valign="top">• <a href="#Invoking-source_002dhighlight" accesskey="6">Invoking source-highlight</a>:</td><td> </td><td align="left" valign="top">How to run <code>source-highlight</code>. </td></tr> <tr><td align="left" valign="top">• <a href="#Language-Definitions" accesskey="7">Language Definitions</a>:</td><td> </td><td align="left" valign="top">How to define an input language </td></tr> <tr><td align="left" valign="top">• <a href="#Output-Language-Definitions" accesskey="8">Output Language Definitions</a>:</td><td> </td><td align="left" valign="top">How to define an output format </td></tr> <tr><td align="left" valign="top">• <a href="#Generating-References" accesskey="9">Generating References</a>:</td><td> </td><td align="left" valign="top">Anchors and cross references </td></tr> <tr><td align="left" valign="top">• <a href="#Examples">Examples</a>:</td><td> </td><td align="left" valign="top">Some output examples </td></tr> <tr><td align="left" valign="top">• <a href="#Problems">Problems</a>:</td><td> </td><td align="left" valign="top">Reporting bugs. </td></tr> <tr><td align="left" valign="top">• <a href="#Mailing-Lists">Mailing Lists</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Concept-Index">Concept Index</a>:</td><td> </td><td align="left" valign="top">Index of concepts. </td></tr> </table> <hr> <a name="Introduction"></a> <div class="header"> <p> Next: <a href="#Installation" accesskey="n" rel="next">Installation</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Introduction-1"></a> <h2 class="chapter">1 Introduction</h2> <a name="index-introduction"></a> <a name="index-features"></a> <p>GNU Source-highlight, given a source file, produces a document with syntax highlighting. The colors and the styles can be specified (bold, italics, underline) by means of a configuration file, and some other options can be specified at the command line. </p> <p>The program already recognizes many programming languages (e.g., C++, Java, Perl, etc.) and file formats (e.g., log files, ChangeLog, etc.), and some output formats (e.g., HTML, ANSI color escape sequences, LaTeX, etc.). Since version 2.0, it allows you to specify your own input source language via a simple syntax described later in this manual (<a href="#Language-Definitions">Language Definitions</a>). Since version 2.1, it allows you to specify your own output format language via a simple syntax described later in this manual (<a href="#Output-Language-Definitions">Output Language Definitions</a>). Since version 2.2, it is able to generate cross references (e.g., to variable names, field names, etc.) by relying on the program <em>ctags</em>, <a href="http://ctags.sourceforge.net">http://ctags.sourceforge.net</a> (<a href="#Generating-References">Generating References</a>). </p> <a name="index-library"></a> <p>Since version 3.0, GNU Source-highlight also provides a C++ library (which is used by the main program itself), that can be used by C++ programmers to add highlighting functionalities to their programs. See <a href="source-highlight-info.html#Introduction">(source-highlight-info)Introduction</a>. </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Supported-languages" accesskey="1">Supported languages</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#The-program-source_002dhighlight_002dsettings" accesskey="2">The program source-highlight-settings</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Notes-on-some-languages" accesskey="3">Notes on some languages</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Using-source_002dhighlight-as-a-simple-formatter" accesskey="4">Using source-highlight as a simple formatter</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Related-Software-and-Links" accesskey="5">Related Software and Links</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Supported-languages"></a> <div class="header"> <p> Next: <a href="#The-program-source_002dhighlight_002dsettings" accesskey="n" rel="next">The program source-highlight-settings</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Supported-languages-1"></a> <h3 class="section">1.1 Supported languages</h3> <p>The complete list of languages (indeed, file extensions) natively supported by this version of Source-highlight (3.1.8), as reported by <code>--lang-list</code>, is the following: </p> <div class="example"> <pre class="example">C = cpp.lang F77 = fortran.lang F90 = fortran.lang H = cpp.lang ac = m4.lang ada = ada.lang adb = ada.lang am = makefile.lang applescript = applescript.lang asm = asm.lang autoconf = m4.lang awk = awk.lang bash = sh.lang bat = bat.lang batch = bat.lang bib = bib.lang bison = bison.lang c = c.lang caml = caml.lang cbl = cobol.lang cc = cpp.lang changelog = changelog.lang clipper = clipper.lang cls = latex.lang cobol = cobol.lang coffee = coffeescript.lang coffeescript = coffeescript.lang conf = conf.lang cpp = cpp.lang cs = csharp.lang csh = sh.lang csharp = csharp.lang css = css.lang ctp = php.lang cxx = cpp.lang d = d.lang desktop = desktop.lang diff = diff.lang dmd = d.lang docbook = xml.lang dtx = latex.lang el = lisp.lang eps = postscript.lang erl = erlang.lang erlang = erlang.lang errors = errors.lang f = fortran.lang f77 = fortran.lang f90 = fortran.lang feature = feature.lang fixed-fortran = fixed-fortran.lang flex = flex.lang fortran = fortran.lang free-fortran = fortran.lang glsl = glsl.lang go = go.lang groovy = groovy.lang h = cpp.lang haskell = haskell.lang haxe = haxe.lang hh = cpp.lang hpp = cpp.lang hs = haskell.lang htm = html.lang html = html.lang hx = haxe.lang hxx = cpp.lang in = makefile.lang ini = desktop.lang islisp = islisp.lang java = java.lang javalog = javalog.lang javascript = javascript.lang js = javascript.lang json = json.lang kcfg = xml.lang kdevelop = xml.lang kidl = xml.lang ksh = sh.lang l = flex.lang lang = langdef.lang langdef = langdef.lang latex = latex.lang ldap = ldap.lang ldif = ldap.lang lex = flex.lang lgt = logtalk.lang lhs = haskell_literate.lang lilypond = lilypond.lang lisp = lisp.lang ll = flex.lang log = log.lang logtalk = logtalk.lang lsm = lsm.lang lua = lua.lang ly = lilypond.lang m4 = m4.lang makefile = makefile.lang manifest = manifest.lang mf = manifest.lang ml = caml.lang mli = caml.lang moc = cpp.lang opa = opa.lang outlang = outlang.lang oz = oz.lang pas = pascal.lang pascal = pascal.lang patch = diff.lang pc = pc.lang perl = perl.lang php = php.lang php3 = php.lang php4 = php.lang php5 = php.lang pkgconfig = pc.lang pl = prolog.lang pm = perl.lang po = po.lang postscript = postscript.lang pot = po.lang prg = clipper.lang prolog = prolog.lang properties = properties.lang proto = proto.lang protobuf = proto.lang ps = postscript.lang py = python.lang python = python.lang r = r.lang rb = ruby.lang rc = xml.lang ruby = ruby.lang s = s.lang scala = scala.lang scheme = scheme.lang scm = scheme.lang scpt = applescript.lang sh = sh.lang shell = sh.lang sig = sml.lang sl = slang.lang slang = slang.lang slsh = slang.lang sml = sml.lang spec = spec.lang sql = sql.lang sty = latex.lang style = style.lang syslog = log.lang tcl = tcl.lang tcsh = sh.lang tex = latex.lang texi = texinfo.lang texinfo = texinfo.lang tk = tcl.lang tml = tml.lang txt = nohilite.lang ui = xml.lang upc = upc.lang vala = vala.lang vbs = vbscript.lang vbscript = vbscript.lang xhtml = xml.lang xml = xml.lang xorg = xorg.lang y = bison.lang yacc = bison.lang yy = bison.lang zsh = zsh.lang </pre></div> <p>The complete list of output formats natively supported by this version of Source-highlight (3.1.8), as reported by <code>--outlang-list</code>, is the following: </p> <div class="example"> <pre class="example">docbook = docbook.outlang esc = esc.outlang esc256 = esc256.outlang groff_man = groff_man.outlang groff_mm = groff_mm.outlang groff_mm_color = groff_mm_color.outlang html = html.outlang html-css = htmlcss.outlang html5 = html5.outlang htmltable = htmltable.outlang javadoc = javadoc.outlang latex = latex.outlang latexcolor = latexcolor.outlang mediawiki = mediawiki.outlang odf = odf.outlang sexp = sexp.outlang texinfo = texinfo.outlang xhtml = xhtml.outlang xhtml-css = xhtmlcss.outlang xhtmltable = xhtmltable.outlang </pre></div> <p>The meaning of the suffix <code>-css</code> is explained in <a href="#Output-Language-map">Output Language map</a><a name="DOCF1" href="#FOOT1"><sup>1</sup></a>. </p> <p>Please, keep in mind, that I haven’t tested personally all these language definitions: I actually checked that the definition files are syntactically correct (with the command line option <code>--check-lang</code> and <code>--check-outlang</code>, <a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>), but I’m not sure their definition actually respects that language syntax (e.g., I’ve put up together some language definitions by searching for information in the Internet, but I’ve never programmed in that language). So, if you find that a language definition is not precise, please let me know. Moreover, if you have a program example in a language that’s not included in the <samp>tests</samp> directory, please send it to me so that I can include it in the test suite. </p> <hr> <a name="The-program-source_002dhighlight_002dsettings"></a> <div class="header"> <p> Next: <a href="#Notes-on-some-languages" accesskey="n" rel="next">Notes on some languages</a>, Previous: <a href="#Supported-languages" accesskey="p" rel="prev">Supported languages</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="The-program-source_002dhighlight_002dsettings-1"></a> <h3 class="section">1.2 The program <code>source-highlight-settings</code></h3> <a name="index-source_002dhighlight_002dsettings"></a> <p>Since version 3.0, GNU Source-highlight includes also the program <code>source-highlight-settings</code>, which can be used to check whether source-highlight will be able find its language definition files, and other configuration files, and in case, to store the correct settings in a configuration file, in the user home directory. </p> <a name="index-source_002dhighlight_002econf"></a> <p>In particular, the stored configuration file will be called <samp>source-highlight.conf</samp> and stored in <samp>$HOME/.source-highlight/</samp>. </p> <a name="index-_002d_002ddata_002ddir"></a> <p>For the moment, this file only stores the default value for the <code>--data-dir</code> option. </p> <p>The user can always override the contents of this configuration file, and the default hardcoded value, by using the environment variable <a name="index-SOURCE_005fHIGHLIGHT_005fDATADIR"></a> <code>SOURCE_HIGHLIGHT_DATADIR</code>. </p> <hr> <a name="Notes-on-some-languages"></a> <div class="header"> <p> Next: <a href="#Using-source_002dhighlight-as-a-simple-formatter" accesskey="n" rel="next">Using source-highlight as a simple formatter</a>, Previous: <a href="#The-program-source_002dhighlight_002dsettings" accesskey="p" rel="prev">The program source-highlight-settings</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Notes-on-some-languages-1"></a> <h3 class="section">1.3 Notes on some languages</h3> <p>In this section I’d like to go into details on the highlighting of some specific programming languages. These notes might be useful when the highlighted language has some “dialects” that might require some further specification at the command line (e.g., to select a specific dialect). </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Fortran" accesskey="1">Fortran</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Perl" accesskey="2">Perl</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Fortran"></a> <div class="header"> <p> Next: <a href="#Perl" accesskey="n" rel="next">Perl</a>, Previous: <a href="#Notes-on-some-languages" accesskey="p" rel="prev">Notes on some languages</a>, Up: <a href="#Notes-on-some-languages" accesskey="u" rel="up">Notes on some languages</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Fortran-1"></a> <h4 class="subsection">1.3.1 Fortran</h4> <a name="index-Fortran"></a> <p>As Toby White explained to me, Fortran comes into different “flavors”: a fixed-format, where some characters have a different semantics depending on their column position in the source file, and a free-format where this is not true. For instance, in the former, <code>*</code> and <code>c</code> start a command line, but only if they are specified in the first column (while this is not true in the free-format). </p> <p>By default, the free-format is assumed for Fortran files; if you want to use the fixed-format, you need to specify <code>fortran-fixed</code> at the <code>--src-lang</code> command line option. </p> <hr> <a name="Perl"></a> <div class="header"> <p> Previous: <a href="#Fortran" accesskey="p" rel="prev">Fortran</a>, Up: <a href="#Notes-on-some-languages" accesskey="u" rel="up">Notes on some languages</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Perl-1"></a> <h4 class="subsection">1.3.2 Perl</h4> <a name="index-Perl"></a> <p>Perl syntax forms, especially its regular expression specifications, are quite a nightmare ;-) I tried to specify as much as possible in the <samp>perl.lang</samp> but some particular regular expressions might not be highlighted correctly. Actually, I never programmed in Perl, so, if you see that some parts of your Perl programs are not highlighted correctly, please do not hesitate to contact me, so that I can improve Perl highlighting. </p> <a name="index-_002d_002dinfer_002dlang"></a> <p>Moreover, although the standard extension for Perl files is <code>.pl</code>, since the Prolog language definition was implemented in source-highlight before Perl, this extension is assigned, by default, to Prolog files. However, you can use <code>--infer-lang</code> command line option, so that source-highlight can try to detect the language by inspecting the first lines of the input file (<a href="#How-the-input-language-is-discovered">How the input language is discovered</a>); you can also use <code>--src-lang=perl</code> command line specification to explicitly require Perl highlighting. </p> <hr> <a name="Using-source_002dhighlight-as-a-simple-formatter"></a> <div class="header"> <p> Next: <a href="#Related-Software-and-Links" accesskey="n" rel="next">Related Software and Links</a>, Previous: <a href="#Notes-on-some-languages" accesskey="p" rel="prev">Notes on some languages</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Using-source_002dhighlight-as-a-simple-formatter-1"></a> <h3 class="section">1.4 Using source-highlight as a simple formatter</h3> <p>You can also use source-highlight as a simple formatter of input file, i.e., without performing any highlighting<a name="DOCF2" href="#FOOT2"><sup>2</sup></a>. </p> <a name="index-nohilite_002elang"></a> <p>You can achieve this by using, as the language definition file for input sources the file <samp>nohilite.lang</samp>, using the command line option <code>--lang-def</code> (<a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>). Since that language definition is empty, no highlighting will be performed; however, source-highlight will transform the input file in the output format. Note, in the input language associations in <a href="#Supported-languages">Supported languages</a>, that <samp>nohilite.lang</samp> is also associated to txt files. </p> <p>This, for instance, makes source-highlight useful in cases you want to transform a text file into HTML or LaTeX. During the output, in fact, source-highlight will correctly generate characters that have a specific meanings in the output format. </p> <p>For instance, in this Texinfo manual, if I want to insert a @ or a { I have to “escape” them to make them appear literally since they have a special meaning in Texinfo. The same holds, e.g., for <code><</code>, <code>></code> or <code>&</code> in HTML. If you use source-highlight, it will take care of this, automatically for you. </p> <p>This is the Texinfo source of the above sentence: </p> <div class="example"> <pre class="example">For instance, in this Texinfo manual, if I want to insert a @@ or a @{ I have to ``escape'' them to make them appear literally since they have a special meaning in Texinfo. The same holds, e.g., for @code{<}, @code{>} or @code{&} in HTML. If you use source-highlight, it will take care of this, automatically for you. </pre></div> <p>This was processed by source-highlight as a simple text file, without no highlighting; however since it was formatted in Texinfo, all the necessary escaping was automatically performed. This way, it is very easy to insert, in the same document, a code, and its result (as in this example). </p> <p>This is actually the formatting performed by source-highlight; except for the comment, this is basically what you should have written yourself to do all the escaping stuff manually: </p> <div class="example"> <pre class="example">@c Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite @example For instance, in this Texinfo manual, if I want to insert a @@@@ or a @@@{ I have to ``escape'' them to make them appear literally since they have a special meaning in Texinfo. The same holds, e.g., for @@code@{<@}, @@code@{>@} or @@code@{&@} in HTML. If you use source-highlight, it will take care of this, automatically for you. @end example </pre></div> <a name="index-failsafe"></a> <p>In case source-highlight does not handle a specific input language, you can still use the option <code>--failsafe</code> (<a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>) and also in that case no highlighting will be performed, but source-highlight will transform the input file in the output format. </p> <a name="index-default_002elang"></a> <p>Note, however, that if the input language cannot be established, the <samp>default.lang</samp> will be used: an empty language definition file which you might want to customize. </p> <hr> <a name="Related-Software-and-Links"></a> <div class="header"> <p> Previous: <a href="#Using-source_002dhighlight-as-a-simple-formatter" accesskey="p" rel="prev">Using source-highlight as a simple formatter</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Related-Software-and-Links-1"></a> <h3 class="section">1.5 Related Software and Links</h3> <p>Here we list some software related to source-highlight in the sense that it uses it as a backend (i.e., provides an interface to source-highlight) or it uses some of its features (e.g., definition files): </p> <ul> <li> <a name="index-Source_002dHighlight_002dQt"></a> <a name="index-Qt"></a> Source-highlight-qt is a library for performing syntax highlighting in Qt documents by relying on GNU Source-Highlight library. This library provides an implementation of the qt abstract class QSyntaxHighlighter class, and it deals both with Qt3 and Qt4. <p><a href="http://srchiliteqt.sourceforge.net">http://srchiliteqt.sourceforge.net</a>. </p> </li><li> <a name="index-QSource_002dHighlight"></a> <a name="index-Qt-1"></a> QSource-Highlight is a Qt4 front-end for GNU Source-Highlight (it relies on the library Source-Highlight-Qt). You can highlight your code on the fly, and have the highlighted output in all the formats supported by source-highlight (e.g., HTML, LaTeX, Texinfo, etc.). You can then copy the formatted output and paste it (e.g., in your blog), or save it to a file. A preview of the highlighted output is available for some output formats (e.g., HTML, XHTML, etc.). <p><a href="http://qsrchilite.sourceforge.net">http://qsrchilite.sourceforge.net</a>. </p> </li><li> <a name="index-SourceHighlightIDE"></a> <a name="index-KDE"></a> SourceHighlightIDE is a small IDE (based on Qt4 and Source-highlight-qt) I wrote for developing and debugging new language definitions for source-highlight: <p><a href="http://srchighliteide.sourceforge.net">http://srchighliteide.sourceforge.net</a>. </p> </li><li> <a name="index-Ksrc2highlight"></a> <a name="index-KDE-1"></a> Martin Gebert implemented a KDE interface to source-highlight programs (and he did a wonderful job!), and it is called <em>Ksrc2highlight</em>; if you want to test it: <p><a href="http://www.mgebert.de/Ksrc2highlight">http://www.mgebert.de/Ksrc2highlight</a>. </p> </li><li> <a name="index-java2html"></a> There’s also a Java version of java2html, you can find it at <p><a href="http://www.generationjava.com/projects/Java2Html.shtml">http://www.generationjava.com/projects/Java2Html.shtml</a>. </p> </li><li> This web site provides a web interface to source-highlight so that you can highlight your code on-line: <p><a href="http://www.alaide.com/outils_colorsyntaxe.php">http://www.alaide.com/outils_colorsyntaxe.php</a> </p> </li><li> <a name="index-SHJS"></a> SHJS is a JavaScript program that highlights source code passages in HTML documents. Documents using SHJS are highlighted on the client side by the web browser. SHJS uses language definitions from Source-highlight. <p><a href="http://shjs.sourceforge.net">http://shjs.sourceforge.net</a> </p> </li><li> <a name="index-code2blog"></a> Code2blog is a pyGTK front-end to source-highlight for easy conversion from source code to HTML. <p><a href="http://code.google.com/p/code2blog">http://code.google.com/p/code2blog</a> </p> </li><li> <a name="index-Apache"></a> Andy Buckley wrote a wrapper around source-highlight, which can be used as an Apache filter to highlight source code in Web pages on the fly. <p><a href="http://www.insectnation.org/projects/filter-src-highlight">http://www.insectnation.org/projects/filter-src-highlight</a> </p> </li><li> <a name="index-RapidWeaver"></a> Roger Nilsson wrote a frontend for source-highlight that is used in a popular webdesign app for OSX called RapidWeaver. The frontend is called High-Light and allows users to easily add syntax-colored code inside RapidWeaver. <p><a href="http://nilrogsplace.se/webdesign/rapidweaver/plugins/high-light/index_en.html">http://nilrogsplace.se/webdesign/rapidweaver/plugins/high-light/index_en.html</a> </p> </li><li> <a name="index-Firefox"></a> Mauricio Zepeda published in his blog an article with a script to automatically highlight a file and show it in Firefox: <p><a href="http://chillorb.com/?p=122">http://chillorb.com/?p=122</a> </p> </li><li> <a name="index-Wiki"></a> <a name="index-Ikiwiki"></a> Jason Blevins made a plugin for Ikiwiki that enables syntax highlighting of source code fragments and whole files via source-highlight. <p><a href="http://jblevins.org/projects/ikiwiki/code">http://jblevins.org/projects/ikiwiki/code</a> </p> </li><li> <a name="index-Wiki-1"></a> <a name="index-Php"></a> Pascal Bleser created a PHP extension that uses the GNU source-highlight library directly from PHP, instead of relying on spawning a process or using the source-highlight CGI. <p><a href="http://code.google.com/p/php-source-highlight/">http://code.google.com/p/php-source-highlight/</a> </p> </li><li> <a name="index-SIP"></a> <a name="index-Python"></a> <a name="index-PyQt"></a> Roberto Alsina made a partial python binding using SIP so that you can use Source-Highlight-Qt in PyQt programs. <p><a href="http://marave.googlecode.com/svn/trunk/marave/highlight/">http://marave.googlecode.com/svn/trunk/marave/highlight/</a> </p> </li><li> <a name="index-Perl-1"></a> A perl binding for source-highlight is available at CPAN: <p><a href="http://search.cpan.org/perldoc?Syntax::SourceHighlight">http://search.cpan.org/perldoc?Syntax::SourceHighlight</a> </p> </li><li> <a name="index-Pastebin"></a> Danijel Tasov wrote a pastebin service based on perl source-highlight binding: <p><a href="http://pb.rbfh.de">http://pb.rbfh.de</a> </p> </li></ul> <hr> <a name="Installation"></a> <div class="header"> <p> Next: <a href="#Copying" accesskey="n" rel="next">Copying</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Installation-1"></a> <h2 class="chapter">2 Installation</h2> <a name="index-installation"></a> <a name="index-compilation"></a> <p>See the file <samp>INSTALL</samp> for detailed building and installation instructions; anyway if you’re used to compiling Linux software that comes with sources you may simply follow the usual procedure, i.e., untar the file you downloaded in a directory and then: </p> <div class="example"> <pre class="example">cd <source code main directory> ./configure make make install </pre></div> <a name="index-shadow-build"></a> <p>We strongly suggest to use shadow builds, thus, create a build directory, say <samp>build</samp> and run configuration and make in that directory: </p> <div class="example"> <pre class="example">cd <source code main directory> mkdir build cd build ../configure make make install </pre></div> <p>However, before you do this, please check that you have everything that is needed to build source-highlight, <a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a>. </p> <p>Note: unless you specify a different install directory by <code>--prefix</code> option of configure (e.g. <code>./configure --prefix=<your home></code>), you must be root to run <code>make install</code>. </p> <p>You may want to run <code>./configure --help</code> to see all the possible options that can be passed to the configuration script. </p> <a name="index-directories"></a> <p>Files will be installed in the following directories: </p> <dl compact="compact"> <dt><code>Executables</code></dt> <dd><p><code>prefix/bin</code> </p></dd> <dt><code>docs and output examples</code></dt> <dd><p><code>prefix/share/doc/source-highlight</code> </p></dd> <dt><code>library examples</code></dt> <dd><p><code>prefix/share/doc/source-highlight/examples</code> </p></dd> <dt><code>library API documentation</code></dt> <dd><p><code>prefix/share/doc/source-highlight/api</code> </p></dd> <dt><code>conf files</code></dt> <dd><p><code>prefix/share/source-highlight</code> </p></dd> </dl> <p>Default value for prefix is <code>/usr/local</code> but you may change it with <code>--prefix</code> option to configure. For further <code>configure</code> options, you can run <code>configure --help</code>. </p> <a name="index-bash-completion"></a> <p>Tiziano Muller wrote a bash completion configuration file for source-highlight; this will be installed by default in the directory <code>sysconfdir/bash_completion.d</code>, where <code>sysconfdir</code> defaults to <code>prefix/etc</code>; however, typically, the directory where the bash completion script searches for configuration file is <code>/etc/bash_completion.d</code>. Thus, we suggest you explicitly specify this directory with the configuration script command line option <code>--with-bash-completion</code>. </p> <a name="index-library-1"></a> <a name="index-_002d_002dwith_002ddoxygen"></a> <a name="index-doxygen"></a> <p>If you want to build and install the API documentation of Source-highlight library, you need to run <code>configure</code> with the option <code>--with-doxygen</code>, but you need the program <em>Doxygen</em>, <a href="http://www.doxygen.org">http://www.doxygen.org</a>, to build the documentation. The documentation will be installed in the following directory: </p> <dl compact="compact"> <dt><code>Library API documentation</code></dt> <dd><p><code>prefix/share/doc/source-highlight/api</code> </p></dd> </dl> <a name="index-java2html-1"></a> <a name="index-cpp2html"></a> <p>NOTE: Originally, instead of Source-highlight, there were two separate programs, namely <em>GNU java2html</em> and <em>GNU cpp2html</em>. There are two shell scripts with the same name that will be installed together with Source-highlight in order to facilitate the migration (however their use is not advised and it is deprecated). </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Building-with-qmake" accesskey="1">Building with qmake</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Download" accesskey="2">Download</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Anonymous-Git-Checkout" accesskey="3">Anonymous Git Checkout</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#What-you-need-to-build-source_002dhighlight" accesskey="4">What you need to build source-highlight</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Tips-on-installing-Boost-Regex-library" accesskey="5">Tips on installing Boost Regex library</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Patching-from-a-previous-version" accesskey="6">Patching from a previous version</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Using-source_002dhighlight-with-less" accesskey="7">Using source-highlight with less</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Using-source_002dhighlight-as-a-CGI" accesskey="8">Using source-highlight as a CGI</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Building-_002erpm" accesskey="9">Building .rpm</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Building-with-qmake"></a> <div class="header"> <p> Next: <a href="#Download" accesskey="n" rel="next">Download</a>, Previous: <a href="#Installation" accesskey="p" rel="prev">Installation</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Building-with-qmake-1"></a> <h3 class="section">2.1 Building with qmake</h3> <a name="index-qmake"></a> <p>Since version 3.1.2, Source-highlight can be built also using <code>qmake</code>, the build tool from Qt libraries (<a href="http://qt.nokia.com">http://qt.nokia.com</a>). This was made available to build Source-highlight on Windows based systems without using a Unix shell, and in particular to build Source-highlight <a name="index-MSVC"></a> with Microsoft MSVC compiler. You should use this method only if you don’t have a Unix shell or if you really need to use the MSVC compiler (e.g., if you want to build Source-highlight library to be used in MSVC based programs). <a name="index-boost"></a> You still need the boost regex library, and if you use MSVC, you can find installation packages for this library at <a href="http://www.boostpro.com">http://www.boostpro.com</a>. </p> <p>This build mechanism is still experimental, and, when using MSVC, only a static version of Source-highlight library can be built (not a .dll). <a name="index-MinGW"></a> You can also use this method if you have the MinGW compiler, <a href="http://www.mingw.org">http://www.mingw.org</a>, (e.g., the one that comes with Qt Windows distribution) and you don’t have <a name="index-msys"></a> Msys (<a href="http://www.mingw.org/wiki/MSYS">http://www.mingw.org/wiki/MSYS</a>). Otherwise, you should still use the <code>configure</code> based mechanims. </p> <p>Using <code>qmake</code>, only a few options can be specified during the building (besides the ones you usually use with qmake), and these options can be specified only using environment variables: </p> <dl compact="compact"> <dt><code>BOOST_REGEX</code></dt> <dd><p>By default, <code>boost_regex</code> will be used to link the boost library (i.e., <code>-lboost_regex</code>); if your boost regex library has a different name you must specify this name using this environment variable; e.g., if the library file is called <code>libboost_regex-mt.lib</code> or <code>boost_regex-mt.dll</code> you must set this variable to <code>boost_regex-mt</code>. </p></dd> <dt><code>INCPATH</code></dt> <dd><p>Specify the path of the boost header files. </p></dd> <dt><code>LIBS</code></dt> <dd><p>Specify the path of the boost lib files. </p></dd> </dl> <p>Please, take into consideration that specifying the boost library include and library paths is completely up to you, using <code>INCPATH</code> and <code>LIBS</code>, if they’re not in the system path directories. </p> <p>Also remember to always use the option <code>-recursive</code> when running qmake. </p> <p>If you then want to run <code>make install</code>, you can use the variable <code>INSTALL_ROOT</code> to prefix the installation path, which, otherwise, is the root directory. </p> <hr> <a name="Download"></a> <div class="header"> <p> Next: <a href="#Anonymous-Git-Checkout" accesskey="n" rel="next">Anonymous Git Checkout</a>, Previous: <a href="#Building-with-qmake" accesskey="p" rel="prev">Building with qmake</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Download-1"></a> <h3 class="section">2.2 Download</h3> <a name="index-download"></a> <p>You can download it from GNU’s ftp site: <a href="ftp://ftp.gnu.org/gnu/src-highlite">ftp://ftp.gnu.org/gnu/src-highlite</a> or from one of its mirrors (see <a href="http://www.gnu.org/prep/ftp.html">http://www.gnu.org/prep/ftp.html</a>). </p> <p>I do not distribute Windows binaries anymore; since, they can be built by using Cygnus C/C++ compiler, available at <a href="http://www.cygwin.com">http://www.cygwin.com</a>. However, if you don’t feel like downloading such compiler or you experience problems with the Boost Regex library (see also <a href="#Tips-on-installing-Boost-Regex-library">Tips on installing Boost Regex library</a>; please also keep in mind that if you don’t have these libraries installed, and your C/C++ compiler distribution does not provide a prebuilt package, it might take some time, even hours, to build the Boost libraries from sources), you can request such binaries directly to me, by e-mail (find my e-mail at my home page) and I’ll be happy to send them to you. An MS-Windows port of Source-highlight is available from <a href="http://gnuwin32.sourceforge.net">http://gnuwin32.sourceforge.net</a>; however, I don’t maintain those binaries personally, and they might be out of date. </p> <p>Archives are digitally signed by me (Lorenzo Bettini) with GNU gpg (<a href="http://www.gnupg.org">http://www.gnupg.org</a>). My GPG public key can be found at my home page (<a href="http://www.lorenzobettini.it">http://www.lorenzobettini.it</a>). </p> <p>You can also get the patches, if they are available for a particular release (see below for patching from a previous version). </p> <hr> <a name="Anonymous-Git-Checkout"></a> <div class="header"> <p> Next: <a href="#What-you-need-to-build-source_002dhighlight" accesskey="n" rel="next">What you need to build source-highlight</a>, Previous: <a href="#Download" accesskey="p" rel="prev">Download</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Anonymous-Git-Checkout-1"></a> <h3 class="section">2.3 Anonymous Git Checkout</h3> <a name="index-Git"></a> <p>This project’s git repository can be checked out through the following clone instruction<a name="DOCF3" href="#FOOT3"><sup>3</sup></a>: </p> <div class="example"> <pre class="example">git clone git://git.savannah.gnu.org/src-highlite.git </pre></div> <p>Further instructions can be found at the address: </p> <p><a href="http://savannah.gnu.org/projects/src-highlite">http://savannah.gnu.org/projects/src-highlite</a>. </p> <p>And the git repository can also browsed on-line at </p> <p><a href="http://git.savannah.gnu.org/cgit/src-highlite.git">http://git.savannah.gnu.org/cgit/src-highlite.git</a>. </p> <p>Please note that this way you will get the latest development sources of Source-highlight, which may also be unstable. This solution is the best if you intend to correct/extend this program: you should send me patches against the latest git repository sources. </p> <p>If, on the contrary, you want to get the sources of a given release, through git, say, e.g., version X.Y.Z, you must specify the tag <code>rel_X_Y_Z</code>. </p> <p>When you compile the sources that you get from the git repository, before running the <code>configure</code> and <code>make</code> commands, for the first time, you must run the command: </p> <div class="example"> <pre class="example">autoreconf -i </pre></div> <p>This will run the autotools commands in the correct order, and also copy possibly missing files. You should have installed recent versions of <a name="index-automake"></a> <a name="index-autoconf"></a> <a name="index-libtool"></a> <code>automake</code>, <code>autoconf</code> and <code>libtool</code> in order for this to succeed. </p> <a name="index-shadow-build-1"></a> <p>We strongly suggest to use shadow builds, thus, create a build directory, say <samp>build</samp> and run configuration and make in that directory: </p> <div class="example"> <pre class="example">cd <source code main directory> mkdir build cd build ../configure make make install </pre></div> <p>To summarize, the steps to get the sources from git and make the first build are: </p> <div class="example"> <pre class="example">git clone git://git.savannah.gnu.org/src-highlite.git cd src-highlite autoreconf -i mkdir build cd build ../configure make </pre></div> <hr> <a name="What-you-need-to-build-source_002dhighlight"></a> <div class="header"> <p> Next: <a href="#Tips-on-installing-Boost-Regex-library" accesskey="n" rel="next">Tips on installing Boost Regex library</a>, Previous: <a href="#Anonymous-Git-Checkout" accesskey="p" rel="prev">Anonymous Git Checkout</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="What-you-need-to-build-source_002dhighlight-1"></a> <h3 class="section">2.4 What you need to build source-highlight</h3> <a name="index-compilation-requirements"></a> <a name="index-building-requirements"></a> <a name="index-boost-1"></a> <p>Since version 2.0 Source-highlight relies on regular expressions as provided by boost (<a href="http://www.boost.org">http://www.boost.org</a>), so you need to install at least the regex library from boost. </p> <p>Most GNU/Linux distributions provide this library already in a compiled form. If you use your distribution packages, please be sure to install also the development package of the boost libraries. </p> <p>If you experience problems in installing Boost Regex library, or in compiling source-highlight because of this library, please take a look at <a href="#Tips-on-installing-Boost-Regex-library">Tips on installing Boost Regex library</a>. </p> <p>If you want to use a specific version of the Boost regex library (because you have many versions of it), you can use the configure option <code>--with-boost-regex</code> to specify a particular suffix. For instance, </p> <div class="example"> <pre class="example">./configure --with-boost-regex=boost_regex-gcc-1_31 </pre></div> <p>Source-highlight has been developed under GNU/Linux, using gcc (C++), and bison (yacc) and flex (lex), and ported under Win32 with Cygwin C/C++compiler, available at <a href="http://www.cygwin.com">http://www.cygwin.com</a>. </p> <p>I use the excellent <a name="index-automake-1"></a> <a name="index-autoconf-1"></a> <a name="index-libtool-1"></a> GNU Autoconf<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>, GNU Automake<a name="DOCF5" href="#FOOT5"><sup>5</sup></a> and GNU Libtool<a name="DOCF6" href="#FOOT6"><sup>6</sup></a>. <a name="index-gnulib"></a> Since version 2.6 I also started to use Gnulib - The GNU Portability Library<a name="DOCF7" href="#FOOT7"><sup>7</sup></a>, “a central location for common GNU code, intended to be shared among GNU packages” (for instance, I rely on Gnulib for checking for the presence and correctness of <code>getopt_long</code> function). </p> <p>Finally I used <em>GNU gengetopt</em> (<a href="http://www.gnu.org/software/gengetopt">http://www.gnu.org/software/gengetopt</a>), for command line parsing. </p> <p>I started to use also <em>doublecpp</em> (<a href="http://doublecpp.sourceforge.net">http://doublecpp.sourceforge.net</a>) that permits achieving dynamic overloading. </p> <p>Actually, apart from the boost regex library, you don’t need the other tools above to build source-highlight (indeed I provide the output sources generated by the above mentioned tools), unless you want to develop source-highlight. </p> <p>However, if you obtained sources through Git, you need some other tools, see <a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a>. </p> <hr> <a name="Tips-on-installing-Boost-Regex-library"></a> <div class="header"> <p> Next: <a href="#Patching-from-a-previous-version" accesskey="n" rel="next">Patching from a previous version</a>, Previous: <a href="#What-you-need-to-build-source_002dhighlight" accesskey="p" rel="prev">What you need to build source-highlight</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Tips-on-installing-Boost-Regex-library-1"></a> <h3 class="section">2.5 Tips on installing Boost Regex library</h3> <a name="index-Boost-regex"></a> <p>If you experience no problem in compiling source-highlight, you can happily skip this section<a name="DOCF8" href="#FOOT8"><sup>8</sup></a> :-) </p> <p>I created this section because many users reported some problems after installing Boost Regex library from sources; other users had problems in compiling source-highlight even if this library was already correctly installed (especially windows users, using cygwin). I hope this section sheds some light in installing/using the Boost Regex library. Please, note that this section does not explain how to compile the Boost libraries (the documentation you’ll find on <a href="http://www.boost.org">http://www.boost.org</a> is well done); it explains how to tweak things if you have problems in compiling source-highlight even after a successful installation of Boost libraries. </p> <p>First of all, if your distribution provides packages for the Boost regex library, please be sure to install also the development package of the boost libraries, i.e., those providing also the header files needed to compile a program using these libraries. For instance, on my Debian system I had to install the package <code>libboost-regex-dev</code>, besides the package <code>libboost-regex</code>. </p> <p>If your distribution does not provide these packages then you have to download the sources of Boost libraries from <a href="http://www.boost.org">http://www.boost.org</a> and follow the instructions for compilation and installation. However, I suggest you specify <samp>/usr</samp> as prefix for installation, instead of relying on the default prefix <samp>/usr/local</samp> (unless <samp>/usr/local/include</samp> is already in the inclusion path of your C++ compiler), since this will make things easier when compiling source-highlight. I suggest this, since <samp>/usr/include</samp> is usually the place where C++ searches for header files during compilation. </p> <p>If you successfully compiled and installed the Boost Regex library, or you installed the package from your distribution, but you STILL experience problems in compiling source-highlight, then you simply have to adjust some things as described in the following. </p> <p>If the <code>./configure</code> command of source-highlight reports this error: </p> <div class="example"> <pre class="example">ERROR! Boost::regex library not installed. </pre></div> <p>then, the compiler cannot find the header files for this library. In this case, check that the directory <samp>/usr/include/boost</samp> actually exists; if it does not, then probably you’ll find a similar directory, e.g., <samp>/usr/include/boost-1_33/boost</samp>, depending on the version of the library you have installed. Then, all you have to do is to create a symbolic link as follows: </p> <div class="example"> <pre class="example">ln -s /usr/include/boost-1_33/boost /usr/include/boost </pre></div> <a name="index-CXXFLAGS"></a> <p>Alternatively, you might run source-highlight’s configure as follows: </p> <div class="example"> <pre class="example">./configure CXXFLAGS=-I/usr/include/boost-1_33/ </pre></div> <p>If you install (or build) the Boost Regex library in a non standard path, e.g., somewhere in your home directory, say <samp>/home/myhome/boost-1_33</samp>, you’ll have to update the <code>CXXFLAGS</code> variable accordingly on the <code>configure</code> command line; in this particular case, you might also have to specify the path of actual library files (<code>CXXFLAGS</code> will only specify the path of header files). In particular, you’ll have to know where the lib files are within the boost installation (or build directory); for instance, if they are in <samp>/home/myhome/boost-1_33/stage/lib</samp>, while the header files (i.e., the <samp>boost</samp> header files directory) are in <samp>/home/myhome/boost-1_33</samp>, the complete <code>configure</code> command should be </p> <a name="index-LDFLAGS"></a> <div class="example"> <pre class="example">./configure CXXFLAGS=-I/home/myhome/boost-1_33 \ LDFLAGS=-L/home/myhome/boost-1_33/stage/lib </pre></div> <p>If then <code>./configure</code> command of source-highlight reports this other error: </p> <div class="example"> <pre class="example">ERROR! Boost::regex library is installed, but you must specify the suffix with --with-boost-regex at configure for instance, --with-boost-regex=boost_regex-gcc-1_31 </pre></div> <p>then, there’s still another thing to fix: you must find out the exact names of the files of your installed Boost Regex libraries; you can do this by using the command: </p> <div class="example"> <pre class="example">$ ls -l /usr/lib/libboost_regex* </pre></div> <p>that, for instance, on one of my cygwin installation reports: </p> <div class="example"> <pre class="example">-rwxr-x---+ Nov 9 23:29 /usr/lib/libboost_regex-gcc-mt-s-1_33.a -rwxr-x---+ Nov 22 09:22 /usr/lib/libboost_regex-gcc-mt-s.a -rwxr-x---+ Nov 9 23:29 /usr/lib/libboost_regex-gcc-mt-s-1_33.so -rwxr-x---+ Nov 22 09:22 /usr/lib/libboost_regex-gcc-mt-s.so </pre></div> <p>Now, you have all the information to correctly run the source-highlight’s configure command: </p> <div class="example"> <pre class="example">./configure --with-boost-regex=boost_regex-gcc-mt-s-1_33 </pre></div> <p>or, if you solved the first problem in the second way<a name="DOCF9" href="#FOOT9"><sup>9</sup></a>, </p> <div class="example"> <pre class="example">./configure CXXFLAGS=-I/usr/include/boost-1_33/ \ --with-boost-regex=boost_regex-gcc-mt-s-1_33 </pre></div> <p>Of course, you have to modify this command according to the names of your Boost Regex library installed files. </p> <p>These instructions managed to let many users, who were experiencing problems, to compile source-highlight If you still have problems, please send me an e-mail. </p> <hr> <a name="Patching-from-a-previous-version"></a> <div class="header"> <p> Next: <a href="#Using-source_002dhighlight-with-less" accesskey="n" rel="next">Using source-highlight with less</a>, Previous: <a href="#Tips-on-installing-Boost-Regex-library" accesskey="p" rel="prev">Tips on installing Boost Regex library</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Patching-from-a-previous-version-1"></a> <h3 class="section">2.6 Patching from a previous version</h3> <a name="index-patching"></a> <p>If you downloaded a patch, say <samp>source-highlight-1.3-1.3.1-patch.gz</samp> (i.e., the patch to go from version 1.3 to version 1.3.1), cd to the directory with sources from the previous version (source-highlight-1.3) and type: </p> <div class="example"> <pre class="example">gunzip -cd ../source-highlight-1.3-1.3.1.patch.gz | patch -p1 </pre></div> <p>and restart the compilation process (if you had already run configure a simple make should do). </p> <hr> <a name="Using-source_002dhighlight-with-less"></a> <div class="header"> <p> Next: <a href="#Using-source_002dhighlight-as-a-CGI" accesskey="n" rel="next">Using source-highlight as a CGI</a>, Previous: <a href="#Patching-from-a-previous-version" accesskey="p" rel="prev">Patching from a previous version</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Using-source_002dhighlight-with-less-1"></a> <h3 class="section">2.7 Using source-highlight with less</h3> <a name="index-src_002dhilite_002dlesspipe_002esh"></a> <p>This was suggested by Konstantine Serebriany. The script <samp>src-hilite-lesspipe.sh</samp> will be installed together with source-highlight. You can use the following environment variables: </p> <div class="example"> <pre class="example">export LESSOPEN="| /path/to/src-hilite-lesspipe.sh %s" export LESS=' -R ' </pre></div> <p>This way, when you use less to browse a file, if it is a source file handled by source-highlight, it will be automatically highlighted. </p> <a name="index-source_002dhighlight_002desc_002esh"></a> <p>Xavier-Emmanuel Vincent recently provided an alternative version of ANSI color scheme, <samp>esc256.style</samp>: some terminals can handle 256 colors. Xavier also provided a script which checks how many colors your terminal can handle, and in case, uses the 256 variant. The script is called <samp>source-highlight-esc.sh</samp> and it will be installed together with the other binaries. </p> <hr> <a name="Using-source_002dhighlight-as-a-CGI"></a> <div class="header"> <p> Next: <a href="#Building-_002erpm" accesskey="n" rel="next">Building .rpm</a>, Previous: <a href="#Using-source_002dhighlight-with-less" accesskey="p" rel="prev">Using source-highlight with less</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Using-source_002dhighlight-as-a-CGI-1"></a> <h3 class="section">2.8 Using source-highlight as a CGI</h3> <a name="index-CGI"></a> <p>CGI support was enabled thanks to Robert Wetzel; I haven’t tested it personally. If you want to use source-highlight as a CGI program, you have to use the executable source-highlight-cgi. You can build such executable by issuing </p> <div class="example"> <pre class="example">make source-highlight-cgi </pre></div> <p>in the <samp>src</samp> directory. </p> <hr> <a name="Building-_002erpm"></a> <div class="header"> <p> Previous: <a href="#Using-source_002dhighlight-as-a-CGI" accesskey="p" rel="prev">Using source-highlight as a CGI</a>, Up: <a href="#Installation" accesskey="u" rel="up">Installation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Building-_002erpm-1"></a> <h3 class="section">2.9 Building .rpm</h3> <a name="index-rpm"></a> <p>Christian W. Zuckschwerdt added support for building an .rpm and an .rpm.src. You can issue the following command </p> <div class="example"> <pre class="example">rpmbuild -tb source-highlight-3.1.8.tar.gz </pre></div> <p>for building an .rpm with binaries and </p> <div class="example"> <pre class="example">rpmbuild -ts source-highlight-3.1.8.tar.gz </pre></div> <p>for building an .rpm.src with sources. </p> <hr> <a name="Copying"></a> <div class="header"> <p> Next: <a href="#Simple-Usage" accesskey="n" rel="next">Simple Usage</a>, Previous: <a href="#Installation" accesskey="p" rel="prev">Installation</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Copying-Conditions"></a> <h2 class="chapter">3 Copying Conditions</h2> <a name="index-Copying-conditions"></a> <p>GNU Source-highlight is free software; you are free to use, share and modify it under the terms of the GNU General Public License that accompanies this software (see <samp>COPYING</samp>). </p> <p>GNU <code>source-highlight</code> was written and maintained by Lorenzo Bettini <a href="http://www.lorenzobettini.it">http://www.lorenzobettini.it</a>. </p> <hr> <a name="Simple-Usage"></a> <div class="header"> <p> Next: <a href="#Configuration-files" accesskey="n" rel="next">Configuration files</a>, Previous: <a href="#Copying" accesskey="p" rel="prev">Copying</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Simple-Usage-1"></a> <h2 class="chapter">4 Simple Usage</h2> <a name="index-sample"></a> <p>Here are some realistic examples of running <code>source-highlight</code><a name="DOCF10" href="#FOOT10"><sup>10</sup></a>. </p> <p>Source-highlight only does a lexical analysis of the source code, so the program source is assumed to be correct! </p> <p>Here’s how to run source-highlight (for this example we will use C/C++ input files, but this is valid also for other source-highlight input languages): </p> <div class="example"> <pre class="example">source-highlight --src-lang cpp --out-format html \ --input <var><C++ file></var> \ --output <var><html file></var> \ --style-file <var><style file></var> \ <var>options</var> </pre></div> <p>For input files, apart from the <code>-i (--input)</code> option and the standard input redirection, you can simply specify some files at the command line and also use regular expressions (for instance <samp>*.java</samp>). In this case the name for the output files will be formed using the name of the source file with a .<ext> appended, where <ext> is the extension chosen according to the output format specified (in this example it would be .html). The style file (<a href="#Output-format-style">Output format style</a>) contains information on how to format specific language parts (e.g., keywords in blue and boldface, etc.). </p> <p>IMPORTANT: you must choose one of the above two invocation modes: either you use <code>-i (--input)</code>, <code>-o (--output)</code> (possibly replacing them with standard input/output redirection), or you specify one or many files without <code>-i (--input)</code>; if you try to mix them you’ll get an error: </p> <div class="example"> <pre class="example">source-highlight -o main.html main.cpp Please, use one of the two syntaxes for invocation: source-highlight [OPTIONS]... -i input_file -o output_file source-highlight [OPTIONS]... [FILES]... </pre></div> <p>If <code>STDOUT</code> string is passed as <code>-o (--output)</code> option, then the output is forced to the standard output anyway. </p> <p>If <code>-s (--src-lang)</code> is not specified, the source language is inferred by the extension of the input file or from the file name itself (possibly using also lower case versions); this, of course, does not work with standard input redirection. For further details, see <a href="#How-the-input-language-is-discovered">How the input language is discovered</a>. </p> <p>If <code>-f (--out-format)</code> is not specified, the output will be produced in HTML. </p> <p>If <code>--style-file</code> is not specified, the <samp>default.style</samp>, which is included in the distribution, will be used (see <a href="#Output-format-style">Output format style</a> for further information). </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#HTML-and-XHTML-output" accesskey="1">HTML and XHTML output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#LaTeX-output" accesskey="2">LaTeX output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Texinfo-output" accesskey="3">Texinfo output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#DocBook-output" accesskey="4">DocBook output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#ANSI-color-escape-sequences" accesskey="5">ANSI color escape sequences</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Odf-output" accesskey="6">Odf output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Groff-output" accesskey="7">Groff output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="HTML-and-XHTML-output"></a> <div class="header"> <p> Next: <a href="#LaTeX-output" accesskey="n" rel="next">LaTeX output</a>, Previous: <a href="#Simple-Usage" accesskey="p" rel="prev">Simple Usage</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="HTML-and-XHTML-output-1"></a> <h3 class="section">4.1 HTML and XHTML output</h3> <a name="index-HTML"></a> <a name="index-XHTML"></a> <p>The default output format for HTML and XHTML uses fixed width fonts by inserting all the formatted output between <code><tt></code> and <code></tt></code>. Thus, for instance, specification for fixed width and not fixed width (see <a href="#Output-format-style">Output format style</a>) will have no effect: every character will have fixed width. If you don’t like this default behavior and would like to have not fixed fonts by default (as it happens, e.g., with LaTeX output) you can use the file <samp>html_notfixed.outlang</samp> with the command line argument <code>--outlang-def</code>. For XHTML output, the corresponding file is <samp>xhtml_notfixed.outlang</samp> </p> <p>Furthermore, the file <samp>htmltable.outlang</samp> can be used to generate HTML output enclosed in an HTML table (which will use also a background color if specified in the style file). The file <samp>xhtmltable.outlang</samp> does the same but for XHTML output. </p> <hr> <a name="LaTeX-output"></a> <div class="header"> <p> Next: <a href="#Texinfo-output" accesskey="n" rel="next">Texinfo output</a>, Previous: <a href="#HTML-and-XHTML-output" accesskey="p" rel="prev">HTML and XHTML output</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="LaTeX-output-1"></a> <h3 class="section">4.2 LaTeX output</h3> <a name="index-LaTeX"></a> <p>When using LaTeX output format you can choose between monochromatic output (by using <code>-f latex</code>) or colored output (by using <code>-f latexcolor</code>). When using colored output, you need the <code>color</code> package (again this should be present in your system). Of course, you are free to define your own LaTeX output format, see <a href="#Output-Language-Definitions">Output Language Definitions</a>. </p> <hr> <a name="Texinfo-output"></a> <div class="header"> <p> Next: <a href="#DocBook-output" accesskey="n" rel="next">DocBook output</a>, Previous: <a href="#LaTeX-output" accesskey="p" rel="prev">LaTeX output</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Texinfo-output-1"></a> <h3 class="section">4.3 Texinfo output</h3> <a name="index-Texinfo"></a> <p>When using the Texinfo output format, you may want to use a dedicated style file, <samp>texinfo.style</samp>, which comes with the source-highlight distribution, with the option <code>--style-file</code>. For instance, the example in <a href="#Examples">Examples</a> is formatted with this style file. </p> <hr> <a name="DocBook-output"></a> <div class="header"> <p> Next: <a href="#ANSI-color-escape-sequences" accesskey="n" rel="next">ANSI color escape sequences</a>, Previous: <a href="#Texinfo-output" accesskey="p" rel="prev">Texinfo output</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="DocBook-output-1"></a> <h3 class="section">4.4 DocBook output</h3> <a name="index-DocBook"></a> <p>DocBook output is generated using the <code><programlisting></code> tag. If the <code>--doc</code> command line option is given, an <code><article></code> document is generated. </p> <hr> <a name="ANSI-color-escape-sequences"></a> <div class="header"> <p> Next: <a href="#Odf-output" accesskey="n" rel="next">Odf output</a>, Previous: <a href="#DocBook-output" accesskey="p" rel="prev">DocBook output</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="ANSI-color-escape-sequences-1"></a> <h3 class="section">4.5 ANSI color escape sequences</h3> <a name="index-ANSI-color"></a> <p>If you’re using this output format, for instance together with <code>less</code> (see <a href="#Using-source_002dhighlight-with-less">Using source-highlight with less</a>), you may want to use the <samp>esc.style</samp> (or <samp>esc256.style</samp> if your terminal can handle 256 colors), which comes with the source-highlight distribution, with the option <code>--style-file</code>. This should result in a more pleasant coloring output. </p> <hr> <a name="Odf-output"></a> <div class="header"> <p> Next: <a href="#Groff-output" accesskey="n" rel="next">Groff output</a>, Previous: <a href="#ANSI-color-escape-sequences" accesskey="p" rel="prev">ANSI color escape sequences</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Odf-output-1"></a> <h3 class="section">4.6 Odf output</h3> <p>The ODF language output for GNU source-highlight enables the user to generate color-highlighted ODF output of source code files. Or to generate ODF color-highlighted snippets to be used by ODF back-ends (like asciidoc-odf). We create an <code>.fodt</code> file, which is a Text document that newer versions of LibreOffice can open. </p> <hr> <a name="Groff-output"></a> <div class="header"> <p> Previous: <a href="#Odf-output" accesskey="p" rel="prev">Odf output</a>, Up: <a href="#Simple-Usage" accesskey="u" rel="up">Simple Usage</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Groff-output-1"></a> <h3 class="section">4.7 Groff output</h3> <p>The Groff language output for GNU source-highlight enables the user to generate black and white or color-highlighted Groff output using using groff’s Memorandum Macros (the output formats to specify on the command line are <code>groff_mm</code> and <code>groff_mm_color</code>, respectively) or for Man pages (output format to specify on the command line: <code>groff_man</code>). Such formats have been contributed by this project <a href="https://github.com/papoanaya/emacs_utils">https://github.com/papoanaya/emacs_utils</a>. </p> <hr> <a name="Configuration-files"></a> <div class="header"> <p> Next: <a href="#Invoking-source_002dhighlight" accesskey="n" rel="next">Invoking source-highlight</a>, Previous: <a href="#Simple-Usage" accesskey="p" rel="prev">Simple Usage</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Configuration-files-1"></a> <h2 class="chapter">5 Configuration files</h2> <a name="index-configuration-files"></a> <p>During execution, source-highlight needs some files where it finds directives on how to recognize the source language (if not specified explicitly with <code>--src-lang</code> or <code>--lang-def</code>), on which output format to use (if not specified explicitly with <code>--out-format</code> or <code>--outlang-def</code>), on how to format specific source elements (e.g., keywords, comments, etc.), and source and output language definitions. These files will be explained in the next sections. </p> <a name="index-_002d_002ddata_002ddir-1"></a> <p>If the directory for such files is not explicitly specified with the command line option <code>--data-dir</code>, these files are searched for in the following order: </p> <ul> <li> the current directory; </li><li> the installation directory for conf files, see <a href="#Installation">Installation</a> (please keep in mind that this directory is hard-coded into source-highlight during compilation). </li><li> if the source-highlight command is specified with an explicit path name, the installation directory name is still used, but relative to the explicit path name. </li></ul> <p>In particular, the user can set the value also with the environment variable <a name="index-SOURCE_005fHIGHLIGHT_005fDATADIR-1"></a> <code>SOURCE_HIGHLIGHT_DATADIR</code> (see also <a href="#The-program-source_002dhighlight_002dsettings">The program source-highlight-settings</a>). </p> <p>If you want to be sure about which file is used during the execution, you can use the command line option <code>--verbose</code>. </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Output-format-style" accesskey="1">Output format style</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Output-format-style-using-CSS" accesskey="2">Output format style using CSS</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Default-Styles" accesskey="3">Default Styles</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Language-map" accesskey="4">Language map</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Language-definition-files" accesskey="5">Language definition files</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Output-Language-map" accesskey="6">Output Language map</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Output-Language-definition-files" accesskey="7">Output Language definition files</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Developing-your-own-definition-files" accesskey="8">Developing your own definition files</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Output-format-style"></a> <div class="header"> <p> Next: <a href="#Output-format-style-using-CSS" accesskey="n" rel="next">Output format style using CSS</a>, Previous: <a href="#Configuration-files" accesskey="p" rel="prev">Configuration files</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Output-format-style-1"></a> <h3 class="section">5.1 Output format style</h3> <a name="index-output-style"></a> <a name="index-default_002estyle"></a> <p>You must specify your options for syntax highlighting in the file <samp>default.style</samp><a name="DOCF11" href="#FOOT11"><sup>11</sup></a>. You can specify formatting options for each element defined by a language definition file (you can get the list of such elements, <a name="index-_002d_002dshow_002dlang_002delements"></a> by using <code>--show-lang-elements</code>, see <a href="#Listing-Language-Elements">Listing Language Elements</a>). </p> <a name="index-bgcolor"></a> <a name="index-background-color"></a> <p>Since version 2.6, you can also specify the background color for the output document, using the keyword <code>bgcolor</code> (this might be visible only when the <code>--doc</code> command line option is used). </p> <p>If many elements share the same formatting options, you can specify these elements in the same line, separated by a comma<a name="DOCF12" href="#FOOT12"><sup>12</sup></a>. </p> <p>Here’s the <samp>default.style</samp> that comes with this distribution (this is formatted by using the <samp>style.lang</samp> that is shown in <a href="#Tutorials-on-Language-Definitions">Tutorials on Language Definitions</a>): </p> <div class="example"> <pre class="example"><b>bgcolor</b> <tt>"white"</tt>; <span class="roman"><i>// the background color for documents</i></span> <tt><i>context</i></tt> <b>gray</b>; <span class="roman"><i>// the color for context lines (when specified with line ranges)</i></span> <tt><i>keyword</i></tt> <b>blue</b> <b>b</b> ; <span class="roman"><i>// for language keywords</i></span> <tt><i>type</i></tt> <b>darkgreen</b> ; <span class="roman"><i>// for basic types</i></span> <tt><i>usertype</i></tt> <b>teal</b> ; <span class="roman"><i>// for user defined types</i></span> <tt><i>string</i></tt> <b>red</b> <b>f</b> ; <span class="roman"><i>// for strings and chars</i></span> <tt><i>regexp</i></tt> <b>orange</b> <b>f</b> ; <span class="roman"><i>// for strings and chars</i></span> <tt><i>specialchar</i></tt> <b>pink</b> <b>f</b> ; <span class="roman"><i>// for special chars, e.g., \n, \t, \\</i></span> <tt><i>comment</i></tt> <b>brown</b> <b>i</b>, <b>noref</b>; <span class="roman"><i>// for comments</i></span> <tt><i>number</i></tt> <b>purple</b> ; <span class="roman"><i>// for literal numbers</i></span> <tt><i>preproc</i></tt> <b>darkblue</b> <b>b</b> ; <span class="roman"><i>// for preproc directives (e.g. #include, import)</i></span> <tt><i>symbol</i></tt> <b>darkred</b> ; <span class="roman"><i>// for simbols (e.g. <, >, +)</i></span> <tt><i>function</i></tt> <b>black</b> <b>b</b>; <span class="roman"><i>// for function calls and declarations</i></span> <tt><i>cbracket</i></tt> <b>red</b>; <span class="roman"><i>// for block brackets (e.g. {, })</i></span> <tt><i>todo</i></tt> <b>bg:cyan</b> <b>b</b>; <span class="roman"><i>// for TODO and FIXME</i></span> <tt><i>code</i></tt> <b>bg:brightgreen</b> <b>b</b>; <span class="roman"><i>// for code snippets</i></span> <span class="roman"><i>//Predefined variables and functions (for instance glsl)</i></span> <tt><i>predef_var</i></tt> <b>darkblue</b> ; <tt><i>predef_func</i></tt> <b>darkblue</b> <b>b</b> ; <span class="roman"><i>// for OOP</i></span> <tt><i>classname</i></tt> <b>teal</b> ; <span class="roman"><i>// for class names, e.g., in Java and C++</i></span> <span class="roman"><i>// line numbers</i></span> <b>linenum</b> <b>black</b> <b>f</b>; <span class="roman"><i>// Internet related</i></span> <tt><i>url</i></tt> <b>blue</b> <b>u</b>, <b>f</b>; <span class="roman"><i>// other elements for ChangeLog and Log files</i></span> <tt><i>date</i></tt> <b>blue</b> <b>b</b> ; <tt><i>time</i></tt>, <tt><i>file</i></tt> <b>darkblue</b> <b>b</b> ; <tt><i>ip</i></tt>, <tt><i>name</i></tt> <b>darkgreen</b> ; <span class="roman"><i>// for Prolog, Perl...</i></span> <tt><i>variable</i></tt> <b>darkgreen</b> ; <span class="roman"><i>// explicit for Latex</i></span> <tt><i>italics</i></tt> <b>darkgreen</b> <b>i</b>; <tt><i>bold</i></tt> <b>darkgreen</b> <b>b</b>; <tt><i>underline</i></tt> <b>darkgreen</b> <b>u</b>; <tt><i>fixed</i></tt> <b>green</b> <b>f</b>; <tt><i>argument</i></tt> <b>darkgreen</b>; <tt><i>optionalargument</i></tt> <b>purple</b>; <tt><i>math</i></tt> <b>orange</b>; <tt><i>bibtex</i></tt> <b>blue</b>; <span class="roman"><i>// for diffs</i></span> <tt><i>oldfile</i></tt> <b>orange</b>; <tt><i>newfile</i></tt> <b>darkgreen</b>; <tt><i>difflines</i></tt> <b>blue</b>; <span class="roman"><i>// for css</i></span> <tt><i>selector</i></tt> <b>purple</b>; <tt><i>property</i></tt> <b>blue</b>; <tt><i>value</i></tt> <b>darkgreen</b> <b>i</b>; <span class="roman"><i>// for oz</i></span> <tt><i>atom</i></tt> <b>orange</b>; <tt><i>meta</i></tt> <b>i</b>; <span class="roman"><i>// for file system</i></span> <tt><i>path</i></tt> <b>orange</b>; <span class="roman"><i>// for C (or other language) labels</i></span> <tt><i>label</i></tt> <b>teal</b> <b>b</b>; <span class="roman"><i>// for errors</i></span> <tt><i>error</i></tt> <b>purple</b>; <tt><i>warning</i></tt> <b>darkgreen</b>; <span class="roman"><i>// for feature (Cucumber) files</i></span> <tt><i>cuketag</i></tt> <b>green</b> ; <tt><i>gherken</i></tt> <b>blue</b> ; <tt><i>given</i></tt> <b>red</b> ; <tt><i>when</i></tt> <b>cyan</b> ; <tt><i>then</i></tt> <b>yellow</b> ; <tt><i>and_but</i></tt> <b>pink</b> ; <tt><i>table</i></tt> <b>gray</b> ; </pre></div> <p>This file tries to define a style for most elements defined in the language definition files that comes with Source-highlight distribution. </p> <a name="index-_002d_002dstyle_002dfile"></a> <p>You can specify your own file (it doesn’t have to be named <samp>default.style</samp>) with the command line option <code>--style-file</code><a name="DOCF13" href="#FOOT13"><sup>13</sup></a>, see <a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>. </p> <p>You can also specify the color of normal text by adding this line </p> <div class="example"> <pre class="example">normal darkblue ; </pre></div> <a name="index-color"></a> <a name="index-background-color-1"></a> <p>As you might see the syntax of this file is quite straightforward: after the element (or elements, separated by commas) you can specify the color, and the background color<a name="DOCF14" href="#FOOT14"><sup>14</sup></a> by using the prefix <code>bg:</code> (for instance, in the <samp>default.style</samp> above the background color is specified for the <code>todo</code> element). </p> <p>Note that the background color might not be available for all output formats: it is available for XHTML and LaTeX but not for HTML<a name="DOCF15" href="#FOOT15"><sup>15</sup></a>. </p> <a name="index-bold"></a> <a name="index-italics"></a> <a name="index-underline"></a> <a name="index-fixed"></a> <a name="index-notfixed"></a> <p>Then, you can specify further formatting options such as bold, italics, etc.; these are the keywords that can be used: </p> <div class="example"> <pre class="example">b = bold i = italics u = underline f = fixed nf = not fixed noref = no reference information is generated for these elements </pre></div> <a name="index-color-1"></a> <p>Since version 2.2, the color specification is not required. For instance, the <samp>texinfo.style</samp> is as follows (we avoid colors for Texinfo outputs): </p> <div class="example"> <pre class="example"><tt><i>keyword</i></tt>, <tt><i>type</i></tt> <b>b</b> ; <tt><i>variable</i></tt> <b>f</b>, <b>i</b> ; <tt><i>string</i></tt> <b>f</b> ; <tt><i>regexp</i></tt> <b>f</b> ; <tt><i>comment</i></tt> <b>nf</b>, <b>i</b>, <b>noref</b> ; <tt><i>preproc</i></tt> <b>b</b> ; <span class="roman"><i>// line numbers</i></span> <b>linenum</b> <b>f</b>; <span class="roman"><i>// Internet related</i></span> <tt><i>url</i></tt> <b>f</b>; <span class="roman"><i>// for diffs</i></span> <tt><i>oldfile</i></tt>, <tt><i>newfile</i></tt> <b>i</b>; <tt><i>difflines</i></tt> <b>b</b>; <span class="roman"><i>// for css</i></span> <tt><i>selector</i></tt>, <tt><i>property</i></tt> <b>b</b>; <tt><i>value</i></tt> <b>i</b>; </pre></div> <p>You may also specify more than on of these options separated by commas, e.g. </p> <div class="example"> <pre class="example">keyword blue u, b ; </pre></div> <p>Please keep in mind that in this case the order of these specified options is kept during the generation of the output; for instance, depending on the specific output format, the sequences <code>u, b</code> and <code>b, u</code> may lead to different results. In particular, the style that comes first is used after the ones that follow. For instance, in the case of HTML, the sequence <code>u, b</code> will lead to the following formatting: <code><u><b>...</b></u></code>. </p> <a name="index-noref"></a> <p>The <code>noref</code> option specifies that for this element reference information are not generated (see <a href="#Generating-References">Generating References</a>). For instance, this is used for the <code>comment</code> element, since we do not want that elements in a comment are searched for cross-references. </p> <p>These are all possible color logical names handled by source-highlight<a name="DOCF16" href="#FOOT16"><sup>16</sup></a>: </p> <div class="example"> <pre class="example">black red darkred brown yellow cyan blue pink purple orange brightorange green brightgreen darkgreen teal gray darkblue white </pre></div> <a name="index-direct-color-scheme"></a> <p>You can also use the direct color scheme for the specific output format, by using double quotes, such as, e.g., <code>"#00FF00"</code> in HTML<a name="DOCF17" href="#FOOT17"><sup>17</sup></a> or even string colors in double quotes<a name="DOCF18" href="#FOOT18"><sup>18</sup></a>, such as <code>"lightblue"</code>. Of course, the double quotes will be discarded during the generation. </p> <p>For instance, this is the <samp>syslog.style</samp> used in the <samp>tests</samp> directory. This uses direct color schemes. </p> <div class="example"> <pre class="example"><tt><i>date</i></tt>, <tt><i>keyword</i></tt> <b>yellow</b> <b>b</b> ; <tt><i>time</i></tt> <tt>"#9999FF"</tt> ; <tt><i>ip</i></tt> <tt>"lightblue"</tt> <b>b</b> ; <tt><i>type</i></tt> <b>cyan</b> <b>b</b> ; <tt><i>string</i></tt> <tt>"brown"</tt> <b>b</b> ; <tt><i>comment</i></tt> <b>teal</b> ; <tt><i>number</i></tt> <b>red</b> ; <tt><i>preproc</i></tt> <b>cyan</b> ; <tt><i>symbol</i></tt> <b>green</b> ; <tt><i>function</i></tt> <tt>"#CC66CC"</tt> <b>b</b> ; <tt><i>cbracket</i></tt> <b>green</b> <b>b</b> ; <tt><i>twonumbers</i></tt> <b>green</b> <b>b</b> ; <tt><i>port</i></tt> <b>green</b> <b>b</b> ; <tt><i>webmethod</i></tt> <b>teal</b> ; <span class="roman"><i>// foo option</i></span> <tt><i>foo</i></tt> <b>red</b> <b>b</b> ; <span class="roman"><i>// foo entry</i></span> </pre></div> <p>Note that, if you use direct color schemes, source-highlight will perform no transformation, and will output exactly the color scheme you specified. For instance, the specification <code>"brown"</code> is different from <code>brown</code>: the former will be output as it is, while the latter will be translated in the corresponding color of the output format (for HTML the visible result is likely to be the same). </p> <p>It is up to you to specify a color scheme string that is handled by the specific output format. Thus, direct color schemes might not be portable in different output formats; for instance, <code>"#00FF00"</code> is valid in HTML but not in LaTeX. </p> <hr> <a name="Output-format-style-using-CSS"></a> <div class="header"> <p> Next: <a href="#Default-Styles" accesskey="n" rel="next">Default Styles</a>, Previous: <a href="#Output-format-style" accesskey="p" rel="prev">Output format style</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Output-format-style-using-CSS-1"></a> <h3 class="section">5.2 Output format style using CSS</h3> <a name="index-CSS"></a> <p>Since version 2.6 you can specify the output format style also using a limited CSS syntax. Please, note that this has nothing to do with output produced by source-highlight using the <code>--css</code> option. </p> <a name="index-_002d_002dstyle_002dcss_002dfile"></a> <p>By using a CSS file as the style file (i.e., passing it to the <code>--style-css-file</code> command line option) you will only specify the output format style using the same syntax of CSS. This means that you can use a css syntax for specifying the output format style independently from the actual output (this is what the output format style is for). Thus, you can use a css file as the output format style also for LaTeX output (just like you would do with a source-highlight output format style, <a href="#Output-format-style">Output format style</a>). </p> <p>This feature is provided basically for code re-use: you can specify the output format style using a css file, and then re-use the same css file as the actual style sheet of other HTML pages (or even output files produced by source-highlight using the <code>--css</code> option). </p> <p>Note that this feature is quite primordial, so only a limited subset of CSS syntax is recognized. In particular, selectors are always intended as CSS class selectors, so they must start with a dot. <code>/* */</code> comments are handled. Properties (and their values) not handled by source-highlight are simply (and silently) discarded). </p> <p>This is an example of CSS specification handled correctly by source-highlight as a style format specification: </p> <div class="example"> <pre class="example">body { <b>background-color:</b> <<i>color</i> <i>specification</i>>; } <b>.selector</b> { <b>color:</b> <<i>color</i> <i>specification</i>>; <b>background-color:</b> <<i>color</i> <i>specification</i>>; <b>font-weight:</b> <i>bold</i>; <span class="roman"><i>/* this is a comment */</i></span> <b>font-family:</b> <i>monospace</i>; <b>font-style:</b> <i>italic</i>; <b>text-decoration:</b> <i>underline</i>; } </pre></div> <p>Finally, this is the <samp>default.css</samp> that corresponds to <samp>default.style</samp> presented in <a href="#Output-format-style">Output format style</a>: </p> <div class="example"> <pre class="example">body { <b>background-color:</b> <i>white</i>; } <span class="roman"><i>/* the color for context lines (when specified with line ranges) */</i></span> <b>.context</b> { <b>color:</b> <i>gray</i>; } <b>.keyword</b> { <b>color:</b> <i>blue</i>; <b>font-weight:</b> <i>bold</i>; } <b>.type</b> { <b>color:</b> <i>darkgreen</i>; } <b>.usertype</b>, <b>.classname</b> { <b>color:</b> <i>teal</i>; } <b>.string</b> { <b>color:</b> <i>red</i>; <b>font-family:</b> <i>monospace</i>; } <b>.regexp</b> { <b>color:</b> <i>orange</i>; } <b>.specialchar</b> { <b>color:</b> <i>pink</i>; <b>font-family:</b> <i>monospace</i>; } <b>.comment</b> { <b>color:</b> <i>brown</i>; <b>font-style:</b> <i>italic</i>; } <b>.number</b> { <b>color:</b> <i>purple</i>; } <b>.preproc</b> { <b>color:</b> <i>darkblue</i>; <b>font-weight:</b> <i>bold</i>; } <b>.symbol</b> { <b>color:</b> <i>darkred</i>; } <b>.function</b> { <b>color:</b> <i>black</i>; <b>font-weight:</b> <i>bold</i>; } <b>.cbracket</b> { <b>color:</b> <i>red</i>; } <b>.todo</b> { <b>font-weight:</b> <i>bold</i>; <b>background-color:</b> <i>cyan</i>; } <span class="roman"><i>/* line numbers */</i></span> <b>.linenum</b> { <b>color:</b> <i>black</i>; <b>font-family:</b> <i>monospace</i>; } <span class="roman"><i>/* Internet related */</i></span> <b>.url</b> { <b>color:</b> <i>blue</i>; <b>text-decoration:</b> <i>underline</i>; <b>font-family:</b> <i>monospace</i>; } <span class="roman"><i>/* other elements for ChangeLog and Log files */</i></span> <b>.date</b> { <b>color:</b> <i>blue</i>; <b>font-weight:</b> <i>bold</i>; } <b>.time</b>, <b>.file</b> { <b>color:</b> <i>darkblue</i>; <b>font-weight:</b> <i>bold</i>; } <b>.ip</b>, <b>.name</b> { <b>color:</b> <i>darkgreen</i>; } <span class="roman"><i>/* for Prolog, Perl */</i></span> <b>.variable</b> { <b>color:</b> <i>darkgreen</i>; } <b>.italics</b> { <b>color:</b> <i>darkgreen</i>; <b>font-style:</b> <i>italic</i>; } <b>.bold</b> { <b>color:</b> <i>darkgreen</i>; <b>font-weight:</b> <i>bold</i>; } <span class="roman"><i>/* for LaTeX */</i></span> <b>.underline</b> { <b>color:</b> <i>darkgreen</i>; <b>text-decoration:</b> <i>underline</i>; } <b>.fixed</b> { <b>color:</b> <i>green</i>; <b>font-family:</b> <i>monospace</i>; } <b>.argument</b>, <b>.optionalargument</b> { <b>color:</b> <i>darkgreen</i>; } <b>.math</b> { <b>color:</b> <i>orange</i>; } <b>.bibtex</b> { <b>color:</b> <i>blue</i>; } <span class="roman"><i>/* for diffs */</i></span> <b>.oldfile</b> { <b>color:</b> <i>orange</i>; } <b>.newfile</b> { <b>color:</b> <i>darkgreen</i>; } <b>.difflines</b> { <b>color:</b> <i>blue</i>; } <span class="roman"><i>/* for css */</i></span> <b>.selector</b> { <b>color:</b> <i>purple</i>; } <b>.property</b> { <b>color:</b> <i>blue</i>; } <b>.value</b> { <b>color:</b> <i>darkgreen</i>; <b>font-style:</b> <i>italic</i>; } <span class="roman"><i>/* for Oz */</i></span> <b>.atom</b> { <b>color:</b> <i>orange</i>; } <b>.meta</b> { <b>font-style:</b> <i>italic</i>; } <span class="roman"><i>/* for feature/cucumber files */</i></span> <b>.cuketag</b> { <b>color:</b> <i>green</i>; } <b>.gherken</b> { <b>color:</b> <i>blue</i>; } <b>.given</b> { <b>color:</b> <i>red</i>; } <b>.when</b> { <b>color:</b> <i>cyan</i>; } <b>.then</b> { <b>color:</b> <i>yellow</i>; } <b>.and_but</b> { <b>color:</b> <i>pink</i>; } <b>.table</b> { <b>color:</b> <i>gray</i>; } </pre></div> <p>If you pass this file to the <code>--style-css-file</code> command line option and you produce an output file, you will get the same result of using <samp>default.style</samp>. </p> <p>Source-highlight comes with a lot of CSS files that can be used either as standard CSS files for HTML documents, or as style files to pass to <code>--style-css-file</code>. In the documentation installation directory (see <a href="#Installation">Installation</a>) you will find the file <samp>style_examples.html</samp> which shows many output examples, each one with a different CSS style. </p> <hr> <a name="Default-Styles"></a> <div class="header"> <p> Next: <a href="#Language-map" accesskey="n" rel="next">Language map</a>, Previous: <a href="#Output-format-style-using-CSS" accesskey="p" rel="prev">Output format style using CSS</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Default-Styles-1"></a> <h3 class="section">5.3 Default Styles</h3> <p>This file<a name="DOCF19" href="#FOOT19"><sup>19</sup></a> (the default file is <samp>style.defaults</samp>) lists the default style for a language element whose output style is not specified in the style file; in particular the following line (comment lines start with <code>#</code>): </p> <div class="example"> <pre class="example">elem1 = elem2 </pre></div> <p>tells that, if the style for an element, say elem1, is not specified in the style file, then elem1 will have the same style of elem2. </p> <a name="index-style_002edefaults"></a> <p>For instance, this is the <samp>style.defaults</samp> that comes with Source-highlight: </p> <div class="example"> <pre class="example"># defaults for styles # the format is: # elem1 = elem2 # meaning that if the style for elem1 is not specified, # then it will have the same style as elem2 classname = normal usertype = normal preproc = keyword section = function paren = cbracket attribute = type value = string predef_var = type predef_func = function atom = regexp meta = function path = regexp label = preproc error = string warning = type code = preproc </pre></div> <p>In this case the style for the element <code>preproc</code> will default to the style of the element <code>keyword</code>. </p> <p>This file is useful when you want to create your own style file and you don’t want to specify styles for all the elements that will have the same output style in your style (e.g., the default style formats <code>preproc</code> elements differently from keywords, but if in your style you don’t specify a style for it, a <code>preproc</code> element will still be formatted as a <code>keyword</code>). </p> <hr> <a name="Language-map"></a> <div class="header"> <p> Next: <a href="#Language-definition-files" accesskey="n" rel="next">Language definition files</a>, Previous: <a href="#Default-Styles" accesskey="p" rel="prev">Default Styles</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Language-map-1"></a> <h3 class="section">5.4 Language map</h3> <a name="index-language-map"></a> <p>This configuration file associates a file extension to a specific language definition file. You can also use such file extension to specify the <code>--src-lang</code> option (see <a href="#Simple-Usage">Simple Usage</a>). Source-highlight comes with such a file, called <samp>lang.map</samp>. </p> <p>Of course, you can override the settings of this file by writing your own language map file and specify such file with the command line option <code>--lang-map</code>). Moreover, as explained above, if a file <samp>lang.map</samp> is present in the current directory, such version will be used. The format of such file is quite simple (comment lines start with <code>#</code>): </p> <div class="example"> <pre class="example">extension = language definition file </pre></div> <p>The default language definition file is shown in <a href="#Introduction">Introduction</a>. </p> <hr> <a name="Language-definition-files"></a> <div class="header"> <p> Next: <a href="#Output-Language-map" accesskey="n" rel="next">Output Language map</a>, Previous: <a href="#Language-map" accesskey="p" rel="prev">Language map</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Language-definition-files-1"></a> <h3 class="section">5.5 Language definition files</h3> <p>These files are crucial for source-highlight since they specify the source elements that have to be highlighted. These files also allow to specify your own language definitions in order to deal with a language that is not handled by source-highlight<a name="DOCF20" href="#FOOT20"><sup>20</sup></a>. The syntax for these files is explained in <a href="#Language-Definitions">Language Definitions</a>. </p> <hr> <a name="Output-Language-map"></a> <div class="header"> <p> Next: <a href="#Output-Language-definition-files" accesskey="n" rel="next">Output Language definition files</a>, Previous: <a href="#Language-definition-files" accesskey="p" rel="prev">Language definition files</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Output-Language-map-1"></a> <h3 class="section">5.6 Output Language map</h3> <a name="index-output-language-map"></a> <p>This configuration file associates an output format to a specific output language definition file. You can use the name of that output format to specify the <code>--out-format</code> option (see <a href="#Simple-Usage">Simple Usage</a>). Source-highlight comes with such a file, called <samp>outlang.map</samp>. </p> <p>Of course, you can override the settings of this file by writing your own output language map file and specify such file with the command line option <code>--outlang-map</code>). Moreover, as explained above, if a file <samp>outlang.map</samp> is present in the current directory, such version will be used. The format of such file is quite simple: </p> <div class="example"> <pre class="example">output format name = language definition file </pre></div> <p>The default language definition file is shown in <a href="#Introduction">Introduction</a>. </p> <p>In particular, there is a convention for the output format name in the output language map: the one with <code>-css</code> suffix is the one used when <code>--css</code> command line option is given </p> <hr> <a name="Output-Language-definition-files"></a> <div class="header"> <p> Next: <a href="#Developing-your-own-definition-files" accesskey="n" rel="next">Developing your own definition files</a>, Previous: <a href="#Output-Language-map" accesskey="p" rel="prev">Output Language map</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Output-Language-definition-files-1"></a> <h3 class="section">5.7 Output Language definition files</h3> <p>These files are crucial for source-highlight since they specify how the source elements are highlighted. These files also allow to specify your own output format definitions in order to deal with an output format that is not handled by source-highlight<a name="DOCF21" href="#FOOT21"><sup>21</sup></a>. The syntax for these files is explained in <a href="#Output-Language-Definitions">Output Language Definitions</a>. </p> <p>These files are part of source-highlight distribution, but they can also be downloaded, independently, from here: </p> <p><a href="http://www.gnu.org/software/src-highlite/outlang_files/">http://www.gnu.org/software/src-highlite/outlang_files/</a> </p> <hr> <a name="Developing-your-own-definition-files"></a> <div class="header"> <p> Previous: <a href="#Output-Language-definition-files" accesskey="p" rel="prev">Output Language definition files</a>, Up: <a href="#Configuration-files" accesskey="u" rel="up">Configuration files</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Developing-your-own-definition-files-1"></a> <h3 class="section">5.8 Developing your own definition files</h3> <p>I encourage those who write new language definitions or correct/modify existing language definitions to send them to me so that they can be added to the source-highlight distribution! </p> <p>Since these files require more explanations (that, however, are not necessary to the standard usage of source-highlight), they are carefully explained in separate parts: <a href="#Language-Definitions">Language Definitions</a> and <a href="#Output-Language-Definitions">Output Language Definitions</a>. </p> <p>These files are part of source-highlight distribution, but they can also be downloaded, independently, from here: </p> <p><a href="http://www.gnu.org/software/src-highlite/lang_files/">http://www.gnu.org/software/src-highlite/lang_files/</a> </p> <hr> <a name="Invoking-source_002dhighlight"></a> <div class="header"> <p> Next: <a href="#Language-Definitions" accesskey="n" rel="next">Language Definitions</a>, Previous: <a href="#Configuration-files" accesskey="p" rel="prev">Configuration files</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Invoking-source_002dhighlight-1"></a> <h2 class="chapter">6 Invoking <code>source-highlight</code></h2> <a name="index-invoking"></a> <a name="index-version"></a> <a name="index-options"></a> <a name="index-usage"></a> <a name="index-help"></a> <a name="index-getting-help"></a> <p>The format for running the <code>source-highlight</code> program is: </p> <div class="example"> <pre class="example">source-highlight <var>option</var> … </pre></div> <p><code>source-highlight</code> supports the following options, shown by the output of <code>source-highlight --detailed-help</code>: </p> <div class="smallexample"> <pre class="smallexample">source-highlight Highlight the syntax of a source file (e.g. Java) into a specific format (e.g. HTML) Usage: [OPTIONS]... < input_file > output_file source-highlight [OPTIONS]... -i input_file -o output_file source-highlight [OPTIONS]... [FILES]... -h, --help Print help and exit --detailed-help Print help, including all details and hidden options, and exit -V, --version Print version and exit -i, --input=filename input file. default std input -o, --output=filename output file. default std output (when the third invocation form is used). If STDOUT is specified, the output is directed to standard output you can simply specify some files at the command line and also use regular expressions (for instance *.java). In this case the name for the output files will be formed using the name of the source file with a .<ext> appended, where <ext> is the extension chosen according to the output format specified (for instance .html). -s, --src-lang=STRING source language (use --lang-list to get the complete list). If not specified, the source language will be guessed from the file extension. --lang-list list all the supported language and associated language definition file --outlang-list list all the supported output language and associated language definition file -f, --out-format=STRING output format (use --outlang-list to get the complete list) (default=`html') -d, --doc create an output file that can be used as a stand alone document (e.g., not to be included in another one) --no-doc cancel the --doc option even if it is implied (e.g., when css is given) -c, --css=filename the external style sheet filename. Implies --doc -T, --title=STRING give a title to the output document. Implies --doc -t, --tab=INT specify tab length. (default=`8') -H, --header=filename file to insert as header -F, --footer=filename file to insert as footer --style-file=filename specify the file containing format options (default=`default.style') --style-css-file=filename specify the file containing format options (in css syntax) --style-defaults=filename specify the file containing defaults for format options (default=`style.defaults') --outlang-def=filename output language definition file --outlang-map=filename output language map file (default=`outlang.map') --data-dir=path directory where language definition files and language maps are searched for. If not specified these files are searched for in the current directory and in the data dir installation directory --output-dir=path output directory --lang-def=filename language definition file --lang-map=filename language map file (default=`lang.map') --show-lang-elements=filename prints the language elements that are defined in the language definition file --infer-lang force to infer source script language (overriding given language specification) Lines: -n, --line-number[=padding] number all output lines, using the specified padding character (default=`0') --line-number-ref[=prefix] number all output lines and generate an anchor, made of the specified prefix + the line number (default=`line') Filtering output: Mode: linerange specifying line ranges --line-range=STRING generate only the lines in the specified range(s) each range can be of the shape: single line (e.g., --line-range=50) full range (e.g., --line-range=2-10) partial range (e.g., --line-range=-30, first 30 lines, --line-range=40- from line 40 to the end --range-separator=STRING the optional separator to be printed among ranges (e.g., "...") --range-context=INT number of (context) lines generated even if not in range The optional --range-context specifies the number of lines that are not in range that will be printed anyway (before and after the lines in range); These lines will be formatted according to the "context" style. Mode: regexrange specifying regular expression delimited ranges --regex-range=STRING generate only the lines within the specified regular expressions when a line containing the specified regular expression is found, then the lines after this one are actually generated, until another line, containing the same regular expression is found (this last line is not generated). More than one regular expression can be specified. reference generation: --gen-references=STRING generate references (possible values="inline", "postline", "postdoc" default=`inline') --ctags-file=filename specify the file generated by ctags that will be used to generate references (default=`tags') --ctags=cmd how to run the ctags command. If this option is not specified, ctags will be executed with the default value. If it is specified with an empty string, ctags will not be executed at all (default=`ctags --excmd=n --tag-relative=yes') testing: -v, --verbose verbose mode on -q, --quiet print no progress information --binary-output write output files in binary mode This is useful for testing purposes, since you may want to make sure that output files are always generated with a final newline character only --statistics print some statistics (i.e., elapsed time) --gen-version put source-highlight version in the generated file (default=on) --check-lang=filename only check the correctness of a language definition file --check-outlang=filename only check the correctness of an output language definition file --failsafe if no language definition is found for the input, it is simply copied to the output -g, --debug-langdef[=type] debug a language definition. In dump mode just dumps all the steps; in interactive, at each step, waits for some input (press ENTER to step) (possible values="interactive", "dump" default=`dump') --show-regex=filename show the regular expression automaton corresponding to a language definition file </pre></div> <p>Let us explain some options in details (apart from those that should be clear from the <code>--help</code> output itself, and those already explained in <a href="#Simple-Usage">Simple Usage</a>). </p> <dl compact="compact"> <dt><code>--data-dir</code></dt> <dd><a name="index-_002d_002ddata_002ddir-2"></a> <p>Source-highlight, during the execution, will need some files, such as, e.g., language definition files, output format definition files, etc. These files are installed in <code>prefix/share/source-highlight</code> where <code>prefix</code> is chosen at compilation time (see See <a href="#Installation">Installation</a>). Thus, source-highlight should be able to find all the files it needs independently. However, if you want to override this setting, e.g., because you have your own language definition files, or simply because you installed a possible source-highlight binary in a different directory from the one used during the compilation, you can use the command line option <code>--data-dir</code>. </p> </dd> <dt><code>--doc</code></dt> <dt><code>-d</code></dt> <dd><p>If you want a stand alone output document (i.e., an output file that is not thought to be included in another document), specify this option (otherwise you just get some text that you can paste into another document). If you choose this option and do not provide a <code>--title</code>, the your source file name will be used as the title. </p> </dd> <dt><code>--no-doc</code></dt> <dd><p>The <code>--doc</code> option above is actually implied by other command line options (e.g., <code>--css</code>). If you do not want this (e.g., you want to include the output in an existing document containing the global style sheet), you can disable this by using <code>--no-doc</code>. </p> </dd> <dt><code>--css</code></dt> <dt><code>-c</code></dt> <dd><p>Specify the style sheet file (e.g., a <samp>.css</samp> for HTML<a name="DOCF22" href="#FOOT22"><sup>22</sup></a>) for the output document. Note that source-highlight will not use this file: it will simply use this file name when generating the output file, so to specify that the output file uses this file as the style sheet (e.g., if the generated HTML relies on this file as the CSS file). </p> </dd> <dt><code>--tab</code></dt> <dt><code>-t</code></dt> <dd><p>With this options, tab characters will be converted into specified number of space characters (tabulation points will be preserved). This option is automatically selected when generating line numbers. </p> </dd> <dt><code>--style-file</code></dt> <dt><code>--style-css-file</code></dt> <dd><p>Specify the file that source-highlight will use to produce (i.e., format) the output (e.g., colors and other styles for each language element). The formats of these files are detailed in <a href="#Output-format-style">Output format style</a> and in <a href="#Output-format-style-using-CSS">Output format style using CSS</a>, respectively. </p> </dd> <dt><code>--style-defaults</code></dt> <dd><p>Specify the file that contains the default styles for elements whose styles are not found in the style file (see <a href="#Default-Styles">Default Styles</a> for further details). </p> </dd> <dt><code>--output-dir</code></dt> <dd><p>You can pass to source-highlight more than one input file (see <a href="#Simple-Usage">Simple Usage</a>). In this case you cannot specify the output file name. In such cases the output files will be automatically generated into the directory where you invoked the command from; if you want the output files to be generated into a different directory you can use this option. </p> </dd> <dt><code>--infer-lang</code></dt> <dd><a name="index-language-inference"></a> <a name="index-_002d_002dinfer_002dlang-1"></a> <p>Force the inference mechanism for detecting the input language. This is detailed in <a href="#How-the-input-language-is-discovered">How the input language is discovered</a>. </p> </dd> <dt><code>--line-number</code></dt> <dd><p>Line numbers will be generated in the output, using the (optional) specified padding character<a name="DOCF23" href="#FOOT23"><sup>23</sup></a> (the default padding character is <code>0</code>). </p> </dd> <dt><code>--line-number-ref</code></dt> <dd><p>As <code>--line-number</code>, this option numbers all the output lines, and, additionally, generates an anchor for each line. The anchor consists of the specified prefix (default is <code>line</code>) and the line number (e.g., <code>line25</code>). For instance, as prefix, if you deal with many files, you can use the file name. Note that some output languages might not support this feature (e.g., <code>esc</code>, since it makes no sense in such case). See <a href="#Anchors-and-References">Anchors and References</a> for defining how to generate an anchor in a specific output language. </p> <a name="index-line-ranges"></a> <a name="index-range-context"></a> <a name="index-range-separator"></a> </dd> <dt><code>--line-range</code></dt> <dt><code>--range-context</code></dt> <dt><code>--range-separator</code></dt> <dd><p>Since version 2.11, you can specify multiple line ranges: only the lines in the source that are in these ranges will be output. For instance, by specifying </p> <div class="example"> <pre class="example">--line-range="-5","10","20-25","50-" </pre></div> <p>Only the following lines will be output: the first 5 lines, line 10, lines 20 to 25 and from line 50 to the end of input. (See also the examples in <a href="#Line-ranges">Line ranges</a>). </p> <p>Together with <code>--line-range</code>, you can also specify <code>--range-context</code>: this is the number of lines that will be printed before and after the lines of a range (i.e., the surrounding “context”). These lines will not be highlighted: they will be printed according to the style <code>context</code>. For instance, extending the previous example, </p> <div class="example"> <pre class="example">--line-range="-5","10","20-25","50-" --range-context=1 </pre></div> <p>Also the following lines will be output: 6, 9, 11, 19, 26, 49. (See also the examples in <a href="#Line-ranges-_0028with-context_0029">Line ranges (with context)</a>). </p> <p>Finally, you can specify a range separator line string with <code>--range-separator</code> that will be printed between ranges (See also the examples in <a href="#Line-ranges-_0028with-context_0029">Line ranges (with context)</a>). The separator string is preformatted automatically, so, e.g., you don’t have to escape special output characters, such as the { } in texinfo output. </p> <a name="index-regex-ranges"></a> </dd> <dt><code>--regex-range</code></dt> <dd> <p>Ranges can be expressed also using regular expressions, with the command line option <code>--regex-range</code>. In this case the beginning of the range will be detected by a line containing (in any point) a string matching the specified regular expression; the end will be detected by a line containing a string matching the same regular expression that started the range. This feature is very useful when we want to document some code (e.g., in this very manual) by showing only specific parts, that are delimited in a ad-hoc way in the source code (e.g., with specific comment patterns). You can see some usage examples in See <a href="#Regex-ranges">Regex ranges</a>. </p> <p>The specified strings (this option accepts multiple occurrences) must be valid regular expressions (thus you must escape special characters accordingly), otherwise you will get an error. </p> <p>Furthermore, <code>--line-range</code> and <code>--regex-range</code> cannot coexist in the same command line. </p> </dd> <dt><code>--failsafe</code></dt> <dd><a name="index-failsafe-1"></a> <p>If no language specification is found, an error will be printed and the program exits. With this option, instead, in such situations, the input is simply formatted in the output format. This is useful when <code>source-highlight</code> is used with many input files, and it is also used in the <samp>src-hilite-lesspipe.sh</samp> script. Actually I failed to find a good reason why one should not always use this option. So my suggestion is to always use it when you run source-highlight (and indeed, in the future, this option might become the default one). See also <a href="#Using-source_002dhighlight-with-less">Using source-highlight with less</a>, <a href="#Using-source_002dhighlight-as-a-simple-formatter">Using source-highlight as a simple formatter</a>. </p> <a name="index-default_002elang-1"></a> <p>When using <code>--failsafe</code>, if no input language can be established, source-highlight will use the input language definition file <samp>default.lang</samp>, which is an empty file. You might want to customize such file, though. </p> </dd> <dt><code>--debug-lang</code></dt> <dt><code>--show-regex</code></dt> <dd><p>Allows to debug a language definition file, <a href="#Debugging">Debugging</a>. </p> </dd> </dl> <p>The other command line options dealing with references are explained in more details in <a href="#Generating-References">Generating References</a>. </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#How-the-input-language-is-discovered" accesskey="1">How the input language is discovered</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="How-the-input-language-is-discovered"></a> <div class="header"> <p> Previous: <a href="#Invoking-source_002dhighlight" accesskey="p" rel="prev">Invoking source-highlight</a>, Up: <a href="#Invoking-source_002dhighlight" accesskey="u" rel="up">Invoking source-highlight</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="How-the-input-language-is-discovered-1"></a> <h3 class="section">6.1 How the input language is discovered</h3> <p>As already explained, <a href="#Simple-Usage">Simple Usage</a>, source-highlight uses a language definition file according the language specified with the option <code>--src-lang</code>, or <code>--lang-def</code>, or by using the input file extension. </p> <p>Since version 2.5, source-highlight can use an inference mechanism to deduce the input language. For the moment, it can detect script languages based on the “sha-bang” mechanism, i.e., when the first line of a script contains a line such as, e.g., </p> <div class="example"> <pre class="example">#!/bin/sh </pre></div> <p>It detects script languages specified by using the <code>env</code> program<a name="DOCF24" href="#FOOT24"><sup>24</sup></a>: </p> <div class="example"> <pre class="example">#!/usr/bin/env perl </pre></div> <p>It recognizes the Emacs convention, of declaring the Emacs major mode using the format <code>-*- lang -*-</code>. </p> <p>For instance, a script starting as the following one: </p> <div class="example"> <pre class="example">#!/bin/bash # -*- Tcl -*- </pre></div> <p>will be interpreted as a Tcl script, and not as bash script. </p> <p>Finally, it recognizes <code><?</code> specifications (e.g., <code><?php</code> and <code><?xml</code>) and <code><!doctype</code> (in that case, it infers it is an xml file)<a name="DOCF25" href="#FOOT25"><sup>25</sup></a>. </p> <p>This inference mechanism is performed, by default, in case the input language is neither explicitly specified nor found in the language map file by using the input file extension or the filename itself, possibly also the lowercase version (the input file may also have no extension at all, but, for instance, a <samp>ChangeLog</samp> input file will be highlighted using <samp>changelog.lang</samp>). </p> <a name="index-_002d_002dinfer_002dlang-2"></a> <p>Furthermore, this mechanism can be given priority with the command line option <code>--infer-lang</code>. For instance, this is used in the script <samp>src-hilite-lesspipe.sh</samp> (<a href="#Using-source_002dhighlight-with-less">Using source-highlight with less</a>) when running source-highlight, in order to avoid the problem of formatting a Perl script as a Prolog program (since the extension <samp>.pl</samp> is associated to Prolog programs in the language map file, <a href="#Perl">Perl</a>). </p> <hr> <a name="Language-Definitions"></a> <div class="header"> <p> Next: <a href="#Output-Language-Definitions" accesskey="n" rel="next">Output Language Definitions</a>, Previous: <a href="#Invoking-source_002dhighlight" accesskey="p" rel="prev">Invoking source-highlight</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Language-Definitions-1"></a> <h2 class="chapter">7 Language Definitions</h2> <a name="index-language-definition"></a> <p>Since version 2.0 source-highlight uses a specific syntax to specify source language elements (e.g., keywords, strings, comments, etc.). Before version 2.0, language elements were scanned through Flex. This had the drawback of writing a new flex file to deal with a new language; even worse, a new language could not be added “dynamically”: you had to recompile the whole source-highlight program. </p> <p>Instead, now, language elements are specified in a file, loaded dynamically, through a (hopefully) simple syntax. Then, these definitions are used internally to create, on-the-fly, regular expressions that are used to highlight the elements (see also <a href="#How-source_002dhighlight-works">How source-highlight works</a>). In particular, we use the regular expressions provided by the Boost library (see <a href="#Installation">Installation</a>). Thus, when writing a language definition file you will surely have to deal with regular expressions. Don’t be scared: for most of the languages you may never have to deal with difficult regular expressions, and you can also specify language keywords (such as, e.g., “if”, “while”, etc., see <a href="#Simple-definitions">Simple definitions</a>); moreover, for defining delimited language elements you will not have to write a regular expression, but just the delimiters (see <a href="#Delimited-definitions">Delimited definitions</a>). However, there might be some language definitions that may require heavy use of more involved regular expressions (e.g., Perl, just to mention one). </p> <p>Of course, we use the Boost regex library regular expression syntax. We refer to Boost documentation for such syntax, <a href="http://www.boost.org/libs/regex/doc/syntax.html">http://www.boost.org/libs/regex/doc/syntax.html</a>, however, in <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>, we provide some notes on regular expressions that might be helpful for those who never dealt with them. By default, Boost regex library uses Perl regular expression syntax, and, at the moment, this is the only syntax supported by source-highlight. </p> <p>Here, we see such syntax in details, by relying on many examples. This allows a user to easily modify an existing language definition and create a new one. These files have, typically, extension <samp>.lang</samp>. </p> <p>Each definition basically associates a regular expression to a language element and defines a name for the language element. Such name will be used to associate a particular style (e.g., bold face, color, etc.) when highlighting such elements. You cannot use names that are the same of keywords used in the language definition syntax (e.g., <code>start</code>, as shown later, is a reserved word). </p> <p>Comments can be given by using <code>#</code>; the rest of the line is considered as a comment. </p> <p>Source-highlight will scan each line of the input file separately. So a regular expression that tries to match new line characters is destined to fail. However, the language definition syntax provides means to deal with multiple lines (see <a href="#Delimited-definitions">Delimited definitions</a> and <a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a>). </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Ways-of-specifying-regular-expressions" accesskey="1">Ways of specifying regular expressions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Simple-definitions" accesskey="2">Simple definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Line-wide-definitions" accesskey="3">Line wide definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Order-of-definitions" accesskey="4">Order of definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Delimited-definitions" accesskey="5">Delimited definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Variable-definitions" accesskey="6">Variable definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Dynamic-Backreferences" accesskey="7">Dynamic Backreferences</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#File-inclusion" accesskey="8">File inclusion</a>:</td><td> </td><td align="left" valign="top">Include the contents of another file </td></tr> <tr><td align="left" valign="top">• <a href="#State_002fEnvironment-Definitions" accesskey="9">State/Environment Definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Redefinitions-and-Substitutions">Redefinitions and Substitutions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#How-source_002dhighlight-works">How source-highlight works</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#The-program-check_002dregexp">The program check-regexp</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Listing-Language-Elements">Listing Language Elements</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Concluding-Remarks">Concluding Remarks</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Debugging">Debugging</a>:</td><td> </td><td align="left" valign="top">Debug a language definition file </td></tr> <tr><td align="left" valign="top">• <a href="#Tutorials-on-Language-Definitions">Tutorials on Language Definitions</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Ways-of-specifying-regular-expressions"></a> <div class="header"> <p> Next: <a href="#Simple-definitions" accesskey="n" rel="next">Simple definitions</a>, Previous: <a href="#Language-Definitions" accesskey="p" rel="prev">Language Definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Ways-of-specifying-regular-expressions-1"></a> <h3 class="section">7.1 Ways of specifying regular expressions</h3> <p>Before getting into details of language definition syntax, it is crucial to describe the 3 possible ways of specifying a regular expression string. These 3 different ways, basically differ in the way they handle regular expression special characters, such, e.g., parenthesis. For this reason, one mechanism can be more powerful than another one, but it could also require more attention; furthermore, there can be situations where you’re forced to use only one mechanism, since the other ones cannot accomplish the required goal. </p> <dl compact="compact"> <dd><a name="index-_0022expression_0022"></a> </dd> <dt><code>"expression"</code></dt> <dd> <p>If you use double quotes (note, <code>"</code> and not <code>``</code> or <code>''</code>) to specify a regular expression, then basically all the characters, but the alternation symbol, i.e., the pipe symbol <code>|</code>, are considered literally, and thus will be automatically escaped (e.g., a dot <code>.</code> is interpreted as the character <code>.</code> not as the regular expression wild card). Thus, for instance, if you specify </p> <div class="example"> <pre class="example">"my(regular)ex.pre$$ion{*}" </pre></div> <p>source-highlight will automatically transform it into </p> <div class="example"> <pre class="example">my\(regular\)ex\.pre\$\$ion\{\*\} </pre></div> <p>The special character <code>|</code>, unless it is meant to separate two alternatives (<a href="#Simple-definitions">Simple definitions</a>), must be escaped with the character <code>\</code>, e.g., <code>\|</code>. Also the character <code>\</code>, if it is intended literally, must be escaped, e.g., <code>\\</code>. </p> <a name="index-_0027expression_0027"></a> </dd> <dt><code>'expression'</code></dt> <dd> <p>If you want to enjoy (almost) the full power of regular expressions, you need to use single quoted strings (<code>'</code>), instead of double quoted strings. This way, you can specify special characters with their intended meaning. </p> <p>However, marked subexpressions are automatically transformed in non marked subexpressions, i.e., the parts in the expression of the shape <code>(...)</code> will be transformed into <code>(?:...)</code> (as explained in <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>, <code>(?:...)</code> lexically groups part of a regular expression, without generating a marked sub-expression). </p> <p>Thus, for instance, if you specify </p> <div class="example"> <pre class="example">'my(regular)ex.pre$ion*' </pre></div> <p>source-highlight will automatically transform it into </p> <div class="example"> <pre class="example">my(?:regular)ex.pre$ion* </pre></div> <p>Since marked subexpressions cannot be specified with this syntax, then <em>backreferences</em> (see <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>) are not allowed. </p> <a name="index-_0060expression_0060"></a> </dd> <dt><code>`expression`</code></dt> <dd> <a name="index-marked-subexpressions"></a> <a name="index-backreference"></a> <a name="index-backtick"></a> <p>This syntax<a name="DOCF26" href="#FOOT26"><sup>26</sup></a> (note the difference, this one uses the <em>backtick</em> <code>`</code> while the previous one uses <code>'</code>) for specifying a regular expression was introduced to overcome the limitations of the other two syntaxes. With this syntax, the marked subexpressions are not transformed, and so you can use regular expressions mechanisms that rely on marked subexpressions, such as <em>backreferences</em> and <em>conditionals</em> (see <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>). </p> <p>This syntax is also crucial for highlighting specific program parts of some programming languages, such as, e.g., Perl regular expressions (e.g., in substitution expressions) that can be expressed in many forms, in particular, separators for the part to be replaced and the part to replace which can be any non alphanumerical characters<a name="DOCF27" href="#FOOT27"><sup>27</sup></a>, for instance, </p> <div class="example"> <pre class="example">s/foo/bar/g s|foo|bar|g s#foo#bar#g s@foo@bar@g </pre></div> <p>Using this syntax, and backreferences, we can easily define a single language element to deal with these expressions (without specifying all the cases for each possible non alphanumerical character): </p> <div class="example"> <pre class="example">regexp = `s([^[:alnum:][:blank:]]).*\1.*\1[ixsmogce]*` </pre></div> </dd> </dl> <p>Since version 2.11, in all kinds of regular expression specification, you can insert newline characters, which will simply be ignored. Thus, e.g., the file: </p> <div class="example"> <pre class="example"><span class="roman"><i># test_newlines.lang</i></span> <span class="roman"><i># test that newlines in expressions are simply discarded</i></span> <tt><i>keyword</i></tt> = <tt>"foo</tt> <tt>|</tt> <tt>lang"</tt> (<tt><i>keyword</i></tt>,<tt><i>normal</i></tt>,<tt><i>classname</i></tt>) = <tt>`(\<struct)</tt> <tt>([[:blank:]]+)</tt> <tt>([[:alnum:]_]+)`</tt> <tt><i>preproc</i></tt> = <tt>'^[[:blank:]]*</tt> <tt>#([[:blank:]]*</tt> <tt>[[:word:]]*)'</tt> </pre></div> <p>and the file: </p> <div class="example"> <pre class="example"><span class="roman"><i># test_nonewlines.lang</i></span> <span class="roman"><i># test that newlines in expressions are simply discarded</i></span> <span class="roman"><i># see the corresponding test_newlines.lang</i></span> <tt><i>keyword</i></tt> = <tt>"foo|lang"</tt> (<tt><i>keyword</i></tt>,<tt><i>normal</i></tt>,<tt><i>classname</i></tt>) = <tt>`(\<struct)([[:blank:]]+)([[:alnum:]_]+)`</tt> <tt><i>preproc</i></tt> = <tt>'^[[:blank:]]*#([[:blank:]]*[[:word:]]*)'</tt> </pre></div> <p>are equivalent. However, the former is surely more readable. </p> <p>Note however, that space characters are NOT ignored in regular expression definitions. </p> <hr> <a name="Simple-definitions"></a> <div class="header"> <p> Next: <a href="#Line-wide-definitions" accesskey="n" rel="next">Line wide definitions</a>, Previous: <a href="#Ways-of-specifying-regular-expressions" accesskey="p" rel="prev">Ways of specifying regular expressions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Simple-definitions-1"></a> <h3 class="section">7.2 Simple definitions</h3> <a name="index-simple-language-definition"></a> <p>The simplest way to specify language elements is to list the possible alternatives. This is the case, for instance, for keywords. For instance, in <samp>java.lang</samp> you have: </p> <div class="example"> <pre class="example">keyword = "abstract|assert|break|case|catch|class|const", "continue|default|do|else|extends|false|final", "finally|for|goto|if|implements|instanceof|interface" keyword = "native|new|null|private|protected|public|return", "static|strictfp|super|switch|synchronized|throw", "throws|true|this|transient|try|volatile|while" </pre></div> <p>You can separate quoted definitions with commas. Alternatively, within a quoted definition, alternatives can be separated with the pipe symbol <code>|</code>. The above definition defines the language element <code>keyword</code>. Each time an element is found in the source file, it is highlighted with the style for the element with the same name in the output format style file (note that all elements shown in the example are taken from the language definition files that come with source-highlight and there is a style for each of such elements, see <a href="#Configuration-files">Configuration files</a>). If such an element is not specified in the output format style file, it is simply not highlighted (actually, it is highlighted with style <code>normal</code>, <a href="#Configuration-files">Configuration files</a>) (so pay attention to typos :-). </p> <p>From the above example you may have noted that language element definitions are cumulative, so the second <code>keyword</code> definition does not replace the first one. (Indeed, in some cases you may want to actually redefine a language element; this is possible as explained in <a href="#Redefinitions-and-Substitutions">Redefinitions and Substitutions</a>). </p> <p>Note that words specified in double quotes have to match exactly in a source file, and they must be isolated (not surrounded by anything but spaces). Thus for instance <code>class</code> is matched as a keyword, but in <code>my_class</code> the substring <code>class</code> is not matched as keyword. From the point of view of regular expressions a string such as <code>class</code> in a double quote simple definition is intended as <code>\<(class)\></code>. </p> <p>Special characters have to be escaped with the character <code>\</code>. So for instance if you want to specify the character <code>|</code>, which is normally used to separate alternatives in double quoted strings, you have to specify <code>\|</code>. </p> <p>As explained in <a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a>, definitions in double quotes are interpreted literally (thus, e.g., a dot <code>.</code> is interpreted as the character <code>.</code> not as the regular expression wild card). If you want to enjoy the full power of regular expressions to specify a language alternative, you have to use single quoted strings (<code>'</code>), instead of double quoted strings, or strings quoted with backticks (<code>`</code>). </p> <p>For instance, the following is the definition for a preprocessor directive in C/C++: </p> <div class="example"> <pre class="example">preproc = '^[[:blank:]]*#([[:blank:]]*[[:word:]]*)' </pre></div> <p>Note that the definition <code>'class'</code> is different from <code>"class"</code>, as explained above. Thus, for instance <code>'class'</code> matches also the sub-expression <code>class</code> inside <code>my_class</code>. </p> <p>Furthermore, you are not allowed to specify, in the same list, double quoted strings and single quoted strings: you need to split such list definitions. Thus, for instance, the following definition is wrong: </p> <div class="example"> <pre class="example">preproc = "#define",'^[[:blank:]]*#([[:blank:]]*[[:word:]]*)' </pre></div> <p>while the following one is correct: </p> <div class="example"> <pre class="example">preproc = "#define" preproc = '^[[:blank:]]*#([[:blank:]]*[[:word:]]*)' </pre></div> <a name="index-nonsensitive"></a> <p>Finally, at the end of a list of definitions, one can specify the keyword <code>nonsensitive</code>; in that case, the specified strings will be interpreted in a non case sensitive way. For instance, we use this feature in Pascal language definition, <samp>pascal.lang</samp> where keywords are parsed in a non sensitive way: </p> <div class="example"> <pre class="example">keyword = "alfa|and|array|begin|case|const|div", "do|downto|else|end|false|file|for|function|get|goto|if|in", "label|mod|new|not|of|or|pack|packed|page|program", "put|procedure|read|readln|record|repeat|reset|rewrite|set", "text|then|to|true|type|unpack|until|var|while|with|writeln|write" nonsensitive </pre></div> <hr> <a name="Line-wide-definitions"></a> <div class="header"> <p> Next: <a href="#Order-of-definitions" accesskey="n" rel="next">Order of definitions</a>, Previous: <a href="#Simple-definitions" accesskey="p" rel="prev">Simple definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Line-wide-definitions-1"></a> <h3 class="section">7.3 Line wide definitions</h3> <a name="index-lines"></a> <p>It is often useful to define a language element that affects all the remaining characters up to the end of the line. For such definitions, instead of the <code>=</code> you must use the keyword <code>start</code>. For instance, the following is the definition of a single line comment in C++: </p> <div class="example"> <pre class="example">comment start "//" </pre></div> <p>This means that when the two characters <code>//</code> are encountered in the source file, everything from these characters on, up to the end of the line, will be highlighted according to the style <code>comment</code>. </p> <hr> <a name="Order-of-definitions"></a> <div class="header"> <p> Next: <a href="#Delimited-definitions" accesskey="n" rel="next">Delimited definitions</a>, Previous: <a href="#Line-wide-definitions" accesskey="p" rel="prev">Line wide definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Order-of-definitions-1"></a> <h3 class="section">7.4 Order of definitions</h3> <a name="index-definition-order"></a> <p>It is important to observe that the order of language definitions is important since it will be used during regular expression matching (this will be detailed in <a href="#How-source_002dhighlight-works">How source-highlight works</a>). You then have to make sure that, if there are definitions that start with same characters, the longest expression is specified first in the file. For instance if you write </p> <div class="example"> <pre class="example">symbol = "/" comment start "//" </pre></div> <p>The first expression will always be matched first, and the second expression will never be matched. The right order is </p> <div class="example"> <pre class="example">comment start "//" symbol = "/" </pre></div> <hr> <a name="Delimited-definitions"></a> <div class="header"> <p> Next: <a href="#Variable-definitions" accesskey="n" rel="next">Variable definitions</a>, Previous: <a href="#Order-of-definitions" accesskey="p" rel="prev">Order of definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Delimited-definitions-1"></a> <h3 class="section">7.5 Delimited definitions</h3> <a name="index-delimited-definitions"></a> <p>Many elements are delimited by specific character sequences. For instance, strings and multiline comments. The syntax for such an element definition is </p> <div class="example"> <pre class="example"><name> delim <left delimited> <right delimiter> \ {escape <escape character>} \ {multiline} {nested} </pre></div> <p>The <code>escape</code> statement specifies the escape character that may precede one of the delimiters inside the element. This is optional. </p> <p>For instance, this is the definition of C-like strings: </p> <div class="example"> <pre class="example">string delim "\"" "\"" escape "\\" </pre></div> <p>Note that <code>\</code> is a special characters in definitions so it has to be escaped. If the <code>escape</code> specification was omitted, the C string <code>"write \"hello\" string"</code> would have been highlight incorrectly (it would have been highlighted as the string <code>"write \"</code>, the normal character sequence <code>hello\</code> and the string <code>" string"</code>). </p> <p>The option <code>multiline</code> specifies that the element can spawn multiple lines. For instance, PHP strings are defined as follows: </p> <div class="example"> <pre class="example">string delim "\"" "\"" escape "\\" multiline </pre></div> <p>The option <code>nested</code> instructs to count possible multiple occurrences of delimited characters and to match relative multiple occurrences (using a stack). For instance, if we wanted to highlight C-like multiline comments in a nested way<a name="DOCF28" href="#FOOT28"><sup>28</sup></a>, we could use the following definition: </p> <div class="example"> <pre class="example">comment delim "/*" "*/" multiline nested </pre></div> <p>If <code>nested</code> was not used, then the closing <code>*/</code> of the following nested comment would conclude the comment (and the second <code>*/</code> would not be highlighted as a comment): </p> <div class="example"> <pre class="example">/* This is a /* nested comment */ */ </pre></div> <p>Note that, in order for a delimited language element to be nested, its starting and ending elements must be different; thus, for instance, the following definition is not correct: </p> <div class="example"> <pre class="example">string delim "\"" "\"" nested # WRONG! </pre></div> <p>As said above, definitions are cumulative, and they are also cumulative even when using different syntactic forms. Thus, for instance, the complete definition for C++-style comments are the following (actually, the definition of C-style comment is more involved, see the file <samp>c_comment.lang</samp>): </p> <div class="example"> <pre class="example">comment start "//" comment delim "/*" "*/" multiline </pre></div> <hr> <a name="Variable-definitions"></a> <div class="header"> <p> Next: <a href="#Dynamic-Backreferences" accesskey="n" rel="next">Dynamic Backreferences</a>, Previous: <a href="#Delimited-definitions" accesskey="p" rel="prev">Delimited definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Variable-definitions-1"></a> <h3 class="section">7.6 Variable definitions</h3> <a name="index-variables"></a> <p>It is possible to define variables to be re-used in many parts in a language definition file. A variable is defined by using </p> <p><code>vardef</code> <name of the variable> <code>=</code> <list of definitions> </p> <p>Once defined, a variable can be used by prepending the symbol <code>$</code> to its name. For instance, </p> <div class="example"> <pre class="example">vardef FUNCTION = '(?:[[:alpha:]]|_)[[:word:]]*(?=[[:blank:]]*\()' function = $FUNCTION </pre></div> <p>The capital letters are used only for readability. </p> <p>It is also possible to concatenate variables and expressions, and reuse variables inside further variable definitions: </p> <div class="example"> <pre class="example">vardef basic_time = '[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}' vardef time = '\<' + $basic_time + '\>' </pre></div> <hr> <a name="Dynamic-Backreferences"></a> <div class="header"> <p> Next: <a href="#File-inclusion" accesskey="n" rel="next">File inclusion</a>, Previous: <a href="#Variable-definitions" accesskey="p" rel="prev">Variable definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Dynamic-Backreferences-1"></a> <h3 class="section">7.7 Dynamic Backreferences</h3> <a name="index-dynamic-backreference"></a> <p>With <em>dynamic backreferences</em> you can refer to a string matched by the regular expression of the first element of a <code>delim</code> specification<a name="DOCF29" href="#FOOT29"><sup>29</sup></a>. I called these backreferences dynamic in order to distinguish them by the backreferences of regular expression syntax, <a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a>. This is crucial in cases when the right delimiter depends on a subexpression matched by the left delimiter; for instance, Lua comments can be of the shape <code>--[[ comment ]]</code> or <code>--[=[ comment ]=]</code>, but not <code>--[=[ comment ]]</code> neither <code>--[[ comment ]=]</code> (furthermore, they can be nested)<a name="DOCF30" href="#FOOT30"><sup>30</sup></a>. Thus, the regular expression of the right element depends on the one of the left element. </p> <p>A dynamic backreference is similar to a variable (<a href="#Variable-definitions">Variable definitions</a>), but there’s no declaration, and have the shape of </p> <div class="example"> <pre class="example">@{number} </pre></div> <p>where <code>number</code> is the number of the marked subexpression in the left delimiter (source-highlight will actually check that such a marked subexpression exists in the left delimiter). </p> <p>For instance, this is the definition of Lua comments (see also <samp>lua.lang</samp>): </p> <div class="example"> <pre class="example">environment comment delim `--\[(=*)\[` "]" + @{1} + "]" multiline nested begin include "url.lang" ... end </pre></div> <p>Note how the left delimiter can match an optional <code>=</code>, as a marked subexpression, and the right delimiter refers to that with @{1}. </p> <p>Source-highlight will take care of escaping possible special characters during dynamic backreference substitutions. For instance, suppose that you must substitute <code>|</code> for @{1}, because we matched <code>|</code> with the subexpression <code>[^[:alnum:]]</code> in a delim element like the following one: </p> <div class="example"> <pre class="example">comment delim `([^[:alnum:]])` @{1} </pre></div> <p>Since <code>|</code> is a special character in regular expression syntax source-highlight will actually replace <code>@{1}</code> with <code>\|</code>. </p> <p>IMPORTANT: the right delimiter can only refer to subexpressions of its left delimiter; thus, in case of nested delim element definitions (e.g., in states or environment, <a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a>), the left delimiter acts as a binder and hides possible subexpressions defined in outer delim elements. </p> <p>This is crucial to correctly match nested delimited elements with backreferences: source-highlight will correctly recognize this nested (and syntactically correct) Lua comment: </p> <div class="example"> <pre class="example">--[[ first level comment --[=[ second level --[[ third level ]] ]=] ]] </pre></div> <hr> <a name="File-inclusion"></a> <div class="header"> <p> Next: <a href="#State_002fEnvironment-Definitions" accesskey="n" rel="next">State/Environment Definitions</a>, Previous: <a href="#Dynamic-Backreferences" accesskey="p" rel="prev">Dynamic Backreferences</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="File-inclusion-1"></a> <h3 class="section">7.8 File inclusion</h3> <a name="index-file-inclusion"></a> <p>It is possible to include other language definition files into another file. This is inclusion actually physically includes the contents of the included file into the current file during parsing, at the exact point of inclusion (just like the <code>#include</code> in C/C++). This is useful for re-using definitions in many files. For instance, C++ comment definitions are given in a file <samp>c_comment.lang</samp>, and this file is included in the Java and C++ definition files. The same happens for number and functions. For instance, the file <samp>java.lang</samp> contains the following include instructions: </p> <div class="example"> <pre class="example">include "c_comment.lang" include "number.lang" keywords ... include "function.lang" </pre></div> <p>Note that the order of inclusion is crucial since the order of definition is crucial. If function definition was included before keyword definitions, then the sentence <code>if (exp)</code> would be highlighted as a function invocation (see <a href="#Order-of-definitions">Order of definitions</a> and <a href="#How-source_002dhighlight-works">How source-highlight works</a>). </p> <hr> <a name="State_002fEnvironment-Definitions"></a> <div class="header"> <p> Next: <a href="#Explicit-subexpressions-with-names" accesskey="n" rel="next">Explicit subexpressions with names</a>, Previous: <a href="#File-inclusion" accesskey="p" rel="prev">File inclusion</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="State_002fEnvironment-Definitions-1"></a> <h3 class="section">7.9 State/Environment Definitions</h3> <a name="index-states"></a> <a name="index-environments"></a> <p>Sometimes you want some source element to be highlighted only if they are surrounded by other elements. Source-highlight language definitions provides also this feature. </p> <div class="example"> <pre class="example">state|environment <standard definition> begin <other definitions> end </pre></div> <p>This structure is recursive (so other state/environment definitions can be given within a state/environment). The meaning of a state/environment is that the definitions within the <code>begin ... end</code> are matched only if the definitions that define the state/environment have been matched. When entering a state/environment, however, the definitions given outside the state/environment are not matched. The difference between <code>state</code> and <code>environment</code> is that in the latter, normal parts of the source language (i.e., those that do not match any definition) are highlighted according to the style of the definition that defines the environment. </p> <p>As an example, the following defines the multiline nested C comment, and highlights URL and e-mail addresses only when they appear inside a comment (note that this uses file inclusion): </p> <div class="example"> <pre class="example">environment comment delim "/*" "*/" multiline nested begin include "url.lang" end </pre></div> <p>Note that we used <code>environment</code> because everything else inside a comment has to be formatted according to the comment style. </p> <p>While for programming language definitions states/environments can be avoided (although they allow to highlight some parts only if inside a specific environment, e.g., URLs inside comments, or documentation tags in Javadoc comments), they are pretty important for highlighting files such as logs and ChangeLog files, since elements have to be highlighted when they appear in a specific position. For instance, for ChangeLog (see <samp>changelog.lang</samp>), we use a state for highlighting the date, name, e-mail or URL (taken from <samp>url.lang</samp>): </p> <div class="example"> <pre class="example">state date start '[[:digit:]]{2,4}-?[[:digit:]]{2}-?[[:digit:]]{2}' begin include "url.lang" name = '([[:word:]]|[[:punct:]])+' end </pre></div> <p>Note that definitions that appear inside a state/environment have the same scope of the expressions that define the environment. While this makes sense for <code>start</code> and <code>delim</code> definitions, it may make less sense for simple definitions (i.e., those that simply lists all possible expressions): in fact, in this case, such expressions do not define a scope. For such definitions, the semantics of state/environment is that the state/environment starts after matching one of the alternatives. And where will it end? In this case you must explicitly exit the environment. For instance, you can say that, when inside a state/environment, a specific language definition, when encountered also exits the environment, with the keyword <code>exit</code> (you can also specify the number of states to exit). You can even exit all the environments with <code>exitall</code>. For instance, the following definition, highlights a non empty string following a web method: </p> <div class="example"> <pre class="example">vardef non_empty = '[^[:blank:]]+' state webmethod = "OPTIONS|GET|HEAD|POST|PUT|DELETE", "TRACE|CONNECT|PROPFIND|MKCOL|COPY|MOVE|LOCK|UNLOCK" begin string = $non_empty exit end </pre></div> <p>If you ever need such advanced features, you may want to take a look at the <samp>log.lang</samp> definition file that defines highlighting for several log files (access logs, Apache logs, etc.). Moreover, there might be cases, and the above one is one of such cases, explicit subexpressions with names will be enough (see <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>). </p> <p>We conclude this section with an interesting example: comments in M4 files can start with the <code>dnl</code> keyword (up to the end of line), e.g., </p> <div class="example"> <pre class="example">dnl @synopsis AC_CTAGS_FLAGS </pre></div> <p>Now if we want to highlight the <code>dnl</code> as a keyword, and the rest of line as a comment, we cannot simply rely on an environment, since this would highlight all the line with the same style. Moreover, we want to highlight elements starting with <code>@</code> differently, so we actually need a state (this would allow us also to highlight urls inside a comment just like in C++ comments in the example above). Thus, we need to simulate an environment with a state, and we do this for M4 as follows (see the file <samp>m4.lang</samp>): </p> <div class="example"> <pre class="example">state keyword start "dnl" begin # avoid spaces in front of urls or @[[:alpha:]]+ be captured as prefixes comment = '[[:blank:]]+' include "url.lang" include "html.lang" type = '@[[:alpha:]]+' # everything else is a comment comment = '.+' end </pre></div> <p>Once entered the state, every isolated space character is highlighted as a comment; then we have rules for URLs and @ elements; then everything else (<code>.+</code>) is highlighted as a comment. </p> <p>One might think that a smarter way would be to have simply the following definition (after all, why bothering highlighting spaces as comments): </p> <div class="example"> <pre class="example">state keyword start "dnl" begin include "url.lang" include "html.lang" type = '@[[:alpha:]]+' comment = '.+' end </pre></div> <p>Well, with this definition spaces in front of matched URLs or @ elements would be highlighted as normal, being considered as prefixes. This is due to how source-highlight searches for matching rules; we refer to <a href="#How-source_002dhighlight-works">How source-highlight works</a> for further details. </p> <hr> <a name="Explicit-subexpressions-with-names"></a> <div class="header"> <p> Next: <a href="#Redefinitions-and-Substitutions" accesskey="n" rel="next">Redefinitions and Substitutions</a>, Previous: <a href="#State_002fEnvironment-Definitions" accesskey="p" rel="prev">State/Environment Definitions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Explicit-subexpressions-with-names-1"></a> <h3 class="section">7.10 Explicit subexpressions with names</h3> <p>Often, you need to specify two program elements in the same regular expressions, because they are tightly related, but you also need to highlight them differently. </p> <p>For instance, you might want to highlight the name of a class (or interface) in a class (or interface) definition (e.g., in Java). Thus, you can rely on the preceding <code>class</code> keyword which will then be followed by an identifier. </p> <p>A definition such as </p> <div class="example"> <pre class="example">keyword = '(\<(?:class|interface))([[:blank:]]+)([$[:alnum:]]+)' </pre></div> <p>will not produce a good final result, since the name of the class will be highlighted as a keyword, which is not what you might have wanted: for instance, the class name should be highlighted as a <code>type</code>. </p> <p>Up to version 2.6, the only way to do this was to use state or environments (<a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a>) but this tended to be quite difficult to write. </p> <p>Since version 2.7, you can specify a regular expression with marked subexpressions and bind each of them to a specific language element (the regular expression must be enclosed in <code>`</code>, see <a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a>): </p> <div class="example"> <pre class="example">(elem1,...,elemn) = `(subexp1)(...)(subexpn)` </pre></div> <p>Now, with this syntax, we can accomplish our previous goal: </p> <div class="example"> <pre class="example">(keyword,normal,type) = `(\<(?:class|interface))([[:blank:]]+)([$[:alnum:]]+)` </pre></div> <p>This way, the <code>class</code> (or <code>interface</code>) will be highlighted as a keyword, the separating blank characters are formatted as <code>normal</code>, and the name of the class as a <code>type</code>. </p> <p>Note that the number of element names must be equal to the number of subexpressions in the expression; furthermore, at least in the current version, the expression can contain only marked subexpressions (no character outside is allowed) and no nested subexpressions are allowed. </p> <p>Thus, the following specifications are NOT correct: </p> <div class="example"> <pre class="example">(keyword,symbol) = `(...)(...)(...)` # number of elements doesn't match (keyword,symbol) = `(...(...)...)(...)` # contains nested subexpressions (keyword,symbol) = `...(...)...(...)` # outside characters </pre></div> <p>This mechanism permits expressing regular expressions for some situation in a much more compact and probably more readable way. For instance, for highlighting ChangeLog parts (the optional <code>*</code> as a symbol, the optional file name and the element specified in parenthesis as a <code>file</code> element, and the rest as <code>normal</code>) such as </p> <div class="example"> <pre class="example"> * src/Makefile.am (source_highlight_SOURCES): correctly include changelog_scanner.ll * this is a comment without a file name </pre></div> <p>before version 2.6, we used to use these two language definitions: </p> <div class="example"> <pre class="example">state symbol start '^(?:[[:blank:]]+)\*[[:blank:]]+' begin state file start '[^:]+\:' begin normal start '.' end end state normal start '^(?:[[:blank:]]+)' begin state file start '[^:]+\:' begin normal start '.' end end </pre></div> <p>which can be hard to read after having written them. Now, we can write them more easily (see <samp>changelog.lang</samp>): </p> <div class="example"> <pre class="example">(normal,symbol,normal,file)= `(^[[:blank:]]+)(\*)([[:blank:]]+)((?:[^:]+\:)?)` (normal,file)= `(^[[:blank:]]+)((?:[^:]+\:)?)` </pre></div> <p>Since a language element definition using explicit subexpressions with names consists of more than one element, and thus of more than one formatting style, it cannot be used to start an environment (what would the default element be?); while, as seen above, they can be used to start a state. </p> <hr> <a name="Redefinitions-and-Substitutions"></a> <div class="header"> <p> Next: <a href="#How-source_002dhighlight-works" accesskey="n" rel="next">How source-highlight works</a>, Previous: <a href="#Explicit-subexpressions-with-names" accesskey="p" rel="prev">Explicit subexpressions with names</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Redefinitions-and-Substitutions-1"></a> <h3 class="section">7.11 Redefinitions and Substitutions</h3> <p>These two features are useful when you want to define a language by re-using an existing language definition with some changes. Typically you <code>include</code> another language definition file and you redefine/substitute some elements. </p> <a name="index-redef"></a> <p>When you use <code>redef</code> you erase all the previous definitions of that language elements with the new one. The new language element definition will be placed exactly in the point of the new definition. We use this feature, for instance, when we define the <code>sml</code> language by re-using the <code>caml</code> one: they differ only for the keywords<a name="DOCF31" href="#FOOT31"><sup>31</sup></a>. In fact, the contents of <samp>sml.lang</samp> is summarized as follows: </p> <div class="example"> <pre class="example">include "caml.lang" redef keyword = "abstraction|abstype|and|andalso..." redef type = "int|byte|boolean|char|long|float|double|short|void" </pre></div> <p>Since the new language element definition appears in the exact point of the redefinition, this means that such a regular expression will be matched only if all the previous ones (the ones of the included file) cannot be matched. This may lead to unwanted results in some cases (not in the <code>sml</code> case though). In other words the following code </p> <div class="example"> <pre class="example">keyword = "foo" keyword = "bar" type = "int" redef keyword = "myfoo" </pre></div> <p>is equivalent to the following one </p> <div class="example"> <pre class="example">type = "int" keyword = "myfoo" </pre></div> <a name="index-subst"></a> <p>If this is not what you want, you can use <code>subst</code>, which is similar to <code>redef</code> apart from that it replaces the previous first definition of that language element in the exact point of that first definition (all other possible definitions are simply erased). That is to say that the following code </p> <div class="example"> <pre class="example">keyword = "foo" keyword = "bar" type = "int" subst keyword = "myfoo" </pre></div> <p>is equivalent to the following one </p> <div class="example"> <pre class="example">keyword = "myfoo" type = "int" </pre></div> <p>It is up to you to decide which one fits best your needs. We could use this feature to define <code>javascript</code> in terms of <code>java</code>, e.g.: </p> <div class="example"> <pre class="example">include "java.lang" subst keyword = "abstract|break|case|catch|class|if..." </pre></div> <p>Here using <code>redef</code> would have led to the unwanted behavior that <code>if (exp)</code> would have been highlighted as a function call, since the function element definition would have come first (and then matched first) than the redefinition of <code>if</code> as a keyword. Another example is the language definition for C# by reusing the one for C/C++, <a href="#Highlighting-C_002fC_002b_002b-and-C_0023">Highlighting C/C++ and C#</a>. </p> <hr> <a name="How-source_002dhighlight-works"></a> <div class="header"> <p> Next: <a href="#Notes-on-regular-expressions" accesskey="n" rel="next">Notes on regular expressions</a>, Previous: <a href="#Redefinitions-and-Substitutions" accesskey="p" rel="prev">Redefinitions and Substitutions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="How-source_002dhighlight-works-1"></a> <h3 class="section">7.12 How source-highlight works</h3> <p>As hinted at the beginning of <a href="#Language-Definitions">Language Definitions</a>, source-highlight uses the definitions in the language definition file to internally create, on-the-fly, regular expressions that are used to highlight the tokens of an input file. Here we provide some internal details that are crucial to understand how to write language definition files correctly<a name="DOCF32" href="#FOOT32"><sup>32</sup></a>. </p> <p>First of all, for each element definition an highlighting rule is created by source-highlight (even if they correspond to the same language element); thus, each language definition file will correspond to a list of highlighting rules. For each line of the input file, source-highlight will try to match all these rules against the whole line (more formally, against the part of the line that has not been highlighted yet). It will not stop as soon as an highlighting rule matched, since there might be another rule that matches “better”. Now, everything basically reduces to the semantics of that <em>better match</em>. </p> <a name="index-matching-strategy"></a> <p>The strategy used by source-highlight is to select the first matching rule </p> <ul> <li> with empty prefix (or prefix containing only space characters, i.e., spaces or tabs) or </li><li> with the smallest prefix, </li></ul> <a name="index-prefix"></a> <p>where the <em>prefix</em> of a matched rule is the part of the examined string that did not match<a name="DOCF33" href="#FOOT33"><sup>33</sup></a>. Thus, for instance, if we try to match the simple regular expression <code>=</code> against the string </p> <div class="example"> <pre class="example">i = 10; </pre></div> <a name="index-suffix"></a> <p>then the prefix is <code>i </code>, including the space. Following the terminology of regular expression, the remaining part that did not match, i.e., <code> 10;</code>, is the <em>suffix</em>. When source-highlight finds a matching rule, according to the above strategy, it formats the matched part (and the prefix as <code>normal</code>), and then it starts again searching for a matching rule on the suffix, until it processed the whole line. </p> <p>Let us explain this strategy a little bit further with an example. Consider the following language definition file: </p> <div class="example"> <pre class="example"><span class="roman"><i># an example for explaining the strategy of source-highlight</i></span> <tt><i>type</i></tt> = <tt>"int"</tt> <tt><i>keyword</i></tt> = <tt>"null"</tt> <tt><i>symbol</i></tt> = <tt>"="</tt> </pre></div> <p>and the following line to be highlighted: </p> <div class="example"> <pre class="example">int i = null </pre></div> <p>Then source-highlight performs these steps: </p> <ol> <li> The first matching rule is the one for <code>type</code>; since it has an empty prefix, there’s no need to look any further: it highlights <code>int</code> as <code>type</code>; the remaining part to be processed is now <code> i = null</code>; </li><li> the first matching rule is the one for <code>keyword</code>, with the prefix <code> i = </code>; since the prefix is not empty (nor it contain only spaces), we inspect other rules; </li><li> the next matching rule is the one for <code>symbol</code>, with prefix <code> i </code>, which is smaller than the one for <code>keyword</code>, and since there are no other matching rules, the one for <code>symbol</code> is better, and we highlight <code>=</code> as symbol; the remaining part to be processed is now <code> null</code>; </li><li> the first matching rule is the one for <code>keyword</code>, and, since it has a prefix with only spaces, we look no further, and we highlight <code>null</code> as <code>keyword</code>. </li></ol> <p>We conclude this section by showing the following language definition, which summarizes what we said about the highlighting strategy: </p> <div class="example"> <pre class="example"><tt><i>keyword</i></tt> = <tt>"if|class"</tt> <tt><i>type</i></tt> = <tt>'int'</tt> <tt><i>comment</i></tt> <b>delim</b> <tt>"/*"</tt> <tt>"*/"</tt> <span class="roman"><i># thus this won’t catch "/* */ /" as a regexp,</i></span> <span class="roman"><i># since comment elem definition comes first</i></span> <tt><i>regexp</i></tt> = <tt>'/.*/.*/'</tt> <span class="roman"><i># this won’t match if ( ) as a function,</i></span> <span class="roman"><i># since keyword elem definition comes first</i></span> <tt><i>function</i></tt> = <tt>'([[:alpha:]]|_)[[:word:]]*[[:blank:]]*\(*[[:blank:]]*\)'</tt> <span class="roman"><i># the following order is conceptually wrong,</i></span> <span class="roman"><i># since "//" won’t be highlighted as a comment, but as two symbols</i></span> <tt><i>symbol</i></tt> = <tt>"/"</tt> <tt><i>comment</i></tt> <b>start</b> <tt>"//"</tt> </pre></div> <hr> <a name="Notes-on-regular-expressions"></a> <div class="header"> <p> Next: <a href="#The-program-check_002dregexp" accesskey="n" rel="next">The program check-regexp</a>, Previous: <a href="#How-source_002dhighlight-works" accesskey="p" rel="prev">How source-highlight works</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Notes-on-regular-expressions-1"></a> <h3 class="section">7.13 Notes on regular expressions</h3> <a name="index-regular-expressions"></a> <p>Although we refer to Boost documentation for such syntax<a name="DOCF34" href="#FOOT34"><sup>34</sup></a>, we want to provide here some explanations of some forms of regular expressions that might be unknown but that are pretty useful in language definitions. </p> <a name="index-non_002dmarking-parenthesis"></a> <p>Typically, when you need to group sub-expressions with parenthesis, but you don’t want the parenthesis to spit out another marked sub-expression, you can use a <em>non-marking parenthesis</em> <code>(?:expression)</code>. This is not necessary in the language definition syntax: even though you use standard parenthesis, source-highlight will transform it into a non-marking parenthesis. </p> <a name="index-marked-subexpressions-1"></a> <p>Source-highlight translates possible <em>marked subexpressions</em>, i.e., those enclosed in <code>(</code> and <code>)</code>, into non-marked subexpressions (i.e., those explained above). Since version 2.7, if you specify the expression inside <code>`</code> the marked subexpressions are left as such (see also <a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a>). This is useful for <em>backreferences</em> and <em>conditionals</em>. </p> <a name="index-backreference-1"></a> <p>An escape character followed by a digit n, where n is in the range 1-9, is a <em>backreference</em> matches the same string that was matched by sub-expression n. For example the expression <code>^(a*).*\1$</code> will match the string: <code>aaabbaaa</code> but not the string <code>aaabba</code>. Backreferences are useful to write compact language elements, such as in the case of Perl’s substitution modifiers; thus </p> <div class="example"> <pre class="example">regexp = `s([^[:alnum:][:blank:]]).*\1.*\1[ixsmogce]*` </pre></div> <p>will match all these forms </p> <div class="example"> <pre class="example">s/foo/bar/g s|foo|bar|g s#foo#bar#g s@foo@bar@g </pre></div> <a name="index-lookahead-asserts"></a> <p>A useful regular expression form is the <em>Forward Lookahead Asserts</em> that come in two forms, one for positive forward lookahead asserts, and one for negative lookahead asserts: </p> <dl compact="compact"> <dt><code>(?=abc)</code></dt> <dd><p>matches zero characters only if they are followed by the expression “abc”. </p></dd> <dt><code>(?!abc)</code></dt> <dd><p>matches zero characters only if they are not followed by the expression “abc”. </p></dd> </dl> <p>For instance, in the definition of a function (<samp>function.lang</samp>) we use the following regular expression: </p> <div class="example"> <pre class="example">([[:alpha:]]|_)[[:word:]]*(?=[[:blank:]]*\() </pre></div> <p>Thus after the name of a function we test, with the regular expression <code>(?=\()</code> whether an open parenthesis <code>(</code> can be matched. If it can be matched, however, we leave that part in the input, so that the parenthesis will not be formatted the same way of a function name (see also <a href="#How-source_002dhighlight-works">How source-highlight works</a> to understand better this language element definition). </p> <p>Please, be careful when using such regular expression forms: since part of the input is not actually removed you may end up always scanning the same input part (thus looping) if you do not write the regular expressions well. For instance, consider this language definition </p> <div class="example"> <pre class="example">state foo = '(?=foo)' begin foo = '(?=foo)' end </pre></div> <p>and the following input file: </p> <div class="example"> <pre class="example">hello foo bar </pre></div> <p>As soon as we match the word <code>foo</code> we leave it in the input and we enter a state where we try to match the word <code>foo</code> still leaving it in the input. As you might have guess this will make source-highlight loop forever. Probably one might have wanted to write this language definition: </p> <div class="example"> <pre class="example">state foo = '(?=foo)' begin foo = 'foo' end </pre></div> <p>but a cut-and-paste error had its way ;-) </p> <a name="index-lookbehind-asserts"></a> <p>You can also use <em>Lookbehind Asserts</em>: </p> <dl compact="compact"> <dt><code>(?<=pattern)</code></dt> <dd><p>consumes zero characters, only if pattern could be matched against the characters preceding the current position (pattern must be of fixed length). </p></dd> <dt><code>(?<!pattern)</code></dt> <dd><p>consumes zero characters, only if pattern could not be matched against the characters preceding the current position (pattern must be of fixed length). </p></dd> </dl> <a name="index-conditional-expressions"></a> <p>Another advanced regular expression mechanism is the one of <em>conditional expressions</em> </p> <dl compact="compact"> <dt><code>(?(condition)yes-pattern|no-pattern)</code></dt> <dd><p>attempts to match yes-pattern if the condition is true, otherwise attempts to match no-pattern. </p></dd> <dt><code>(?(condition)yes-pattern)</code></dt> <dd><p>attempts to match yes-pattern if the condition is true, otherwise fails. </p></dd> </dl> <p>Condition may be either a forward lookahead assert, or the index<a name="DOCF35" href="#FOOT35"><sup>35</sup></a> of a marked sub-expression (the condition becomes true if the sub-expression has been matched). For instance, the following expression<a name="DOCF36" href="#FOOT36"><sup>36</sup></a>, that we wrote on more lines to try to make it more readable </p> <div class="example"> <pre class="example">(?: (\() |(\[) |(\{) ) [[:alpha:]]* (?: (?(1) \) |(?:(?(2) \] |(?:\} ))))) </pre></div> <p>will match <code>(foo)</code>, <code>[foo]</code> and <code>{foo}</code> but not <code>(foo]</code>, <code>{foo]</code> or <code>{foo)</code>. </p> <hr> <a name="The-program-check_002dregexp"></a> <div class="header"> <p> Next: <a href="#Listing-Language-Elements" accesskey="n" rel="next">Listing Language Elements</a>, Previous: <a href="#Notes-on-regular-expressions" accesskey="p" rel="prev">Notes on regular expressions</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="The-program-check_002dregexp-1"></a> <h3 class="section">7.14 The program <code>check-regexp</code></h3> <a name="index-check_002dregexp"></a> <p>Since version 2.7, the source-highlight package comes with a small additional program, <code>check-regexp</code>, that permits testing regular expressions on the command line. </p> <p>You simply pass as the first command line argument the regular expression and then the strings you want to try to match (actually, the program searches the string for the given regular expression, so it is not required to match the whole string). It is crucial, in order to avoid shell substitutions, to enclose both the expression and the strings in single quotes. </p> <p>The program then prints some information about the (possibly successful matching). The <code>what[0]</code> part represents the whole match, and <code>what[i]</code> part represents the i-th marked subexpression that matched. The program also prints possible prefix and suffix. </p> <p>Here’s an example of output of the program: </p> <div class="example"> <pre class="example">check-regexp '(a+)(.*)\1' 'aabcdaa' 'babbbacc' searching : aabcdaa for the regexp : (a+)(.*)\1 what[0]: aabcdaa what[1]: aa length: 2 what[2]: bcd length: 3 total number of matches: 1 searching : babbbacc for the regexp : (a+)(.*)\1 prefix: b what[0]: abbba what[1]: a length: 1 what[2]: bbb length: 3 suffix: cc total number of matches: 1 </pre></div> <p>And here’s the example of matching parenthesis we saw in <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>: </p> <div class="smallexample"> <pre class="smallexample">check-regexp \ '(?:(\()|(\[)|(\{))[[:alnum:]]*(?:(?(1)\)|(?:(?(2)\]|(?:\})))))' \ '{ciao}' '(foo]' '[hithere]' searching : {ciao} for the regexp : (?:(\()|(\[)|(\{))[[:alnum:]]*(?:(?(1)\)|(?:(?(2)\]|(?:\}))))) what[0]: {ciao} what[3]: { length: 1 total number of matches: 1 searching : (foo] for the regexp : (?:(\()|(\[)|(\{))[[:alnum:]]*(?:(?(1)\)|(?:(?(2)\]|(?:\}))))) total number of matches: 0 searching : [hithere] for the regexp : (?:(\()|(\[)|(\{))[[:alnum:]]*(?:(?(1)\)|(?:(?(2)\]|(?:\}))))) what[0]: [hithere] what[2]: [ length: 1 total number of matches: 1 </pre></div> <hr> <a name="Listing-Language-Elements"></a> <div class="header"> <p> Next: <a href="#Concluding-Remarks" accesskey="n" rel="next">Concluding Remarks</a>, Previous: <a href="#The-program-check_002dregexp" accesskey="p" rel="prev">The program check-regexp</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Listing-Language-Elements-1"></a> <h3 class="section">7.15 Listing Language Elements</h3> <p>In order for language definitions to be really useful they must be used in proper combination with formatting styles (see <a href="#Output-format-style">Output format style</a>). However, these different files might not be developed by the same person, or simply some one may want to customize one of these. In order to define good output formatting style files you should be aware of each language element defined by a language definition file. Instead of having to look inside the language definition file itself (and recursively in each included file) you can use the command line <a name="index-_002d_002dshow_002dlang_002delements-1"></a> option <code>--show-lang-elements</code><a name="DOCF37" href="#FOOT37"><sup>37</sup></a>, that simply prints to the standard output all the language elements that can be highlighted with a specific language definition file. </p> <p>For instance, for <code>cpp.lang</code> you get: </p> <div class="example"> <pre class="example">cbracket classname comment function keyword label normal number preproc specialchar string symbol todo type url usertype </pre></div> <p>while for <code>log.lang</code> you get: </p> <div class="example"> <pre class="example">cbracket comment date function ip normal number port string symbol time twonumbers webmethod </pre></div> <hr> <a name="Concluding-Remarks"></a> <div class="header"> <p> Next: <a href="#Debugging" accesskey="n" rel="next">Debugging</a>, Previous: <a href="#Listing-Language-Elements" accesskey="p" rel="prev">Listing Language Elements</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Concluding-Remarks-1"></a> <h3 class="section">7.16 Concluding Remarks</h3> <p>By mixing all these features you can unleash your imagination and define highlighting for complex source languages such as Flex and Bison by writing few lines of code and re-use existing ones. For instance, Flex and Bison have their own syntax and lets you write C/C++ code in specific parts of the source language, e.g., the code between the outmost brackets, in the following example, is C++ code, and should be highlighted following C++ language definitions (apart from variables that are prefixed with <code>$</code>): </p> <div class="example"> <pre class="example">globaltags : options { if (...) { setTags( $1 ); } } </pre></div> <p>This is easy to do (taken from <samp>flex.lang</samp>): </p> <div class="example"> <pre class="example">state cbracket delim "{" "}" multiline nested begin variable = '\$.' include "cpp.lang" end </pre></div> <p>Note that, since we used <code>nested</code> we can be sure that the C++ language definitions are not considered anymore when we matched the last closing <code>}</code>. </p> <hr> <a name="Debugging"></a> <div class="header"> <p> Next: <a href="#Tutorials-on-Language-Definitions" accesskey="n" rel="next">Tutorials on Language Definitions</a>, Previous: <a href="#Concluding-Remarks" accesskey="p" rel="prev">Concluding Remarks</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Debugging-1"></a> <h3 class="section">7.17 Debugging</h3> <a name="index-debug"></a> <p>When writing a language definition file, it is quite useful to be able to debug it (by using complex regular expressions one may experience unwanted behaviors). Since version 2.1 the command line option <code>--debug-lang</code> is available. When using this option, some additional information are printed to the standard output. </p> <p>Since version 2.5 this option also accepts the a sub specification (see <a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>). When using <code>dump</code> (the default) all the additional information explained below will be dumped without interaction with the user. When using <code>interactive</code>, for each formatted string the program will stop waiting for a command from the user. In this very primordial version of interactive debug, the user will only have to press <code>ENTER</code> to make the program continue until the next formatted string. This way, the programmer will have the chance to step the highlighting of each part of the input file. Moreover, when debugging is enabled, no buffering will be performed by the program, thus each formatted element will be immediately available in the output. For instance, you can use the command <code>tail -f</code> to see the modifications on the output file on-the-fly. </p> <p>When using this command line option the additional information produced has the following format: </p> <div class="example"> <pre class="example"><.lang filename>:<line number> expression: <matched subexpression> formatting: <source file string to be formatted> entering: <next state's id> exiting state, level: <number of states> </pre></div> <p>The lines starting with <code>entering</code>, <code>exiting</code> and <code>exitingall</code> are related to entering a new state/environment and exiting one and all states/environments (<code>current state</code>, if shown, comes after <code>entering</code> and prints the same state’s regular expression but after the substitution of dynamic backreferences, <a href="#Dynamic-Backreferences">Dynamic Backreferences</a>). The first line shows a link to the <samp>.lang</samp> definition file and the line number, i.e., and the sub-expression that matched and the line starting with <code>formatting</code> shows the source file string that matched with that expression. If a line starting with <code>formatting</code> is not preceded by a line with the link to the sub-expression, it means that no particular regular expression has matched, and thus the style <code>normal</code> will be used to format that string. </p> <p>Consider the following (simplified) Java source file: </p> <div class="example"> <pre class="example"><tt>01:</tt> <span class="roman"><i>/*</i></span> <tt>02:</tt> <span class="roman"><i> This is to demonstrate –debug-lang</i></span> <tt>03:</tt> <span class="roman"><i> </i></span><tt>http://www.lorenzobettini.it</tt> <tt>04:</tt> <span class="roman"><i>*/</i></span> <tt>05:</tt> <tt>06:</tt> <b>package</b> hello; <tt>07:</tt> <tt>08:</tt> <b>public</b> <b>class</b> Hello { <tt>09:</tt> <span class="roman"><i>// just some greetings ;-) /*</i></span> <tt>10:</tt> <b>int</b> i = 10; <tt>11:</tt> System.out.println(<tt>"Hello World!"</tt>); <tt>12:</tt> } <tt>13:</tt> </pre></div> <p>Now you can debug the <samp>java.lang</samp> file by using the <code>--debug-lang</code> command line option. And the output is as follows: </p> <div class="example"> <pre class="example">c_comment.lang:24 expression: "/\*" formatting "/*" as comment entering state: 23 formatting " This is to demonstrate --debug-lang" as default formatting " " as default url.lang:3 expression: "(?:(?:<?)[[:word:]]+://[[:word:]\./\-_]+(?:>?))" formatting "http://www.lorenzobettini.it" as url c_comment.lang:24 expression: "\*/" formatting "*/" as comment exiting state, level: 1 java.lang:1 expression: "\<(?:import|package)\>" formatting "package" as preproc formatting " hello" as default symbols.lang:1 expression: "(?:~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|/|\?|&|<|>|\|)" formatting ";" as symbol ... omissis ... c_comment.lang:13 expression: "//" formatting "//" as comment entering state: 12 formatting " just some greetings ;-) /*" as default c_comment.lang:13 expression: "\z" formatting "" as comment exiting state, level: 1 ... omissis ... </pre></div> <p>This should provide enough information to understand how the regular expressions are used and how the states/environments are entered and exited. Please note that the sub-expressions that are shown may differ from the original ones specified in the <samp>.lang</samp> file. This is due to the preprocessing that is performed by Source-highlight. Moreover, some sub-expressions are not defined at all in the <samp>.lang</samp> file: for instance, this is the case for line wide definitions, i.e., those that are defined with the keyword <code>start</code>, <a href="#Line-wide-definitions">Line wide definitions</a>. The last lines above, showing <code>expression: "\z"</code>, means that we matched the end of a line. </p> <p>Another useful feature in debugging is the option <code>--show-regex</code> that shows, on the standard output, the regular expression automaton that source-highlight creates. </p> <p>For instance, consider this language definition (<samp>comment-show.lang</samp>): </p> <div class="example"> <pre class="example"><b>vardef</b> <tt><i>TODO</i></tt> = <tt>'(TODO|FIXME)([:]?)'</tt> <b>environment</b> <tt><i>comment</i></tt> <b>delim</b> <tt>"/**"</tt> <tt>"*/"</tt> <b>multiline</b> <b>begin</b> <tt><i>type</i></tt> = <tt>'@[[:alpha:]]+'</tt> <tt><i>todo</i></tt> = <tt><i>$TODO</i></tt> <b>end</b> <b>state</b> <tt><i>cbracket</i></tt> <b>delim</b> <tt>"{"</tt> <tt>"}"</tt> <b>escape</b> <tt>"\\"</tt> <b>multiline</b> <b>nested</b> <b>begin</b> <tt><i>keyword</i></tt> = <tt>"if|then|else|endif"</tt> <b>end</b> <tt><i>string</i></tt> <b>delim</b> <tt>"<"</tt> <tt>">"</tt> <tt><i>string2</i></tt> <b>delim</b> <tt>"<<"</tt> <tt>">>"</tt> <b>multiline</b> </pre></div> <p>If you now execute the following command: </p> <div class="example"> <pre class="example">source-highlight --show-regex=comment-show.lang </pre></div> <p>you will get, on the standard output, the following output<a name="DOCF38" href="#FOOT38"><sup>38</sup></a>: </p> <div class="example"> <pre class="example">STATE 1 default: normal rule (comment) "/\*\*" (exit level: 0, next: 2) STATE 2 default: comment rule (comment) "\*/" (exit level: 1, next: 0) rule (type) "(?:\@[[:alpha:]]+)" (exit level: 0, next: 0) rule (todo) "(?:(?:TODO|FIXME)(?:[:]?))" (exit level: 0, next: 0) rule (cbracket) "\{" (exit level: 0, next: 3) STATE 3 default: normal rule (cbracket) "\}" (exit level: 1, next: 0) rule (cbracket) "\\." (exit level: 0, next: 0) rule (cbracket) "\{" (exit level: 0, next: 0, nested) rule (keyword) "\<(?:if|then|else|endif)\>" (exit level: 0, next: 0) rule (string) "<(?:[^<>])*>" (exit level: 0, next: 0) rule (string2) "<<" (exit level: 0, next: 4) STATE 4 default: string2 rule (string2) ">>" (exit level: 1, next: 0) </pre></div> <p>This shows the states and highlight rules of the regular expression automaton that source-highlight creates and will use to format an input source. </p> <p>Each state is associated a unique number in order to identify it; moreover, the default element of the state is shown (i.e., if none of the state’s rule match, then that part is highlighted with the default element style). For instance, in the initial state the default style is normal. Then for each state it shows the rules for that state. For each rule you can see the corresponding element of the rule, the regular expression for the rule and some other information, that we explain in the following. </p> <p>We can see that if we match a <code>/**</code> (it is shown as a string with escaped special characters, <code>/\*\*</code>) we enter a new state, in this case the state 2 (<code>next: 2</code>). This corresponds to the delimited element defining a new environment (<a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a>). The fact that it is actually an environment and not a state<a name="DOCF39" href="#FOOT39"><sup>39</sup></a> can be seen by the fact that the default element is the same of the environment itself. If we match a <code>*/</code>, i.e., the end of the delimited element, we exit one level (<code>exit level: 1</code>) meaning that we go back to state 1. Then we have the state for <code>cbracket</code>, which is not an environment, in fact its default state is normal. The second rule of this state, <code>\\.</code> represents the <code>escape</code> string of the state definition. Since the delimited element is defined as nested, we have a third rule <code>{</code> which has the <code>nested</code> information; thus, if we match it, we simply enter a new instance of state 3 itself. </p> <p>The <code>string</code> and <code>string2</code> show the difference implied by the <code>multiline</code> option: since source-highlight handles a line of input separately, the first delimited definition can be handled with a single regular expression while the multiline version cannot. </p> <p>Note that the states/environments are indented so that it’s easier to understand the outer and the inner states. </p> <p>Let us now consider a variation of the previous example: </p> <div class="example"> <pre class="example"><b>vardef</b> <tt><i>TODO</i></tt> = <tt>'(TODO|FIXME)([:]?)'</tt> <b>environment</b> <tt><i>comment</i></tt> <b>delim</b> <tt>"/**"</tt> <tt>"*/"</tt> <b>multiline</b> <b>nested</b> <b>begin</b> <tt><i>type</i></tt> = <tt>'@[[:alpha:]]+'</tt> <tt><i>todo</i></tt> = <tt><i>$TODO</i></tt> <b>end</b> <tt><i>regexp</i></tt> = <tt>`([^[:alnum:]]).*(\1)`</tt> <tt><i>string</i></tt> <b>delim</b> <tt>"<"</tt> <tt>">"</tt> <tt><i>string2</i></tt> <b>delim</b> <tt>"<<"</tt> <tt>">>"</tt> <b>multiline</b> (<tt><i>paren</i></tt>,<tt><i>normal</i></tt>,<tt><i>paren</i></tt>) = <tt>`(\[)(.*)(\])`</tt> </pre></div> <p>and let us see the output of <code>--show-regex</code> </p> <div class="example"> <pre class="example">STATE 1 default: normal rule (comment) "/\*\*" (exit level: 0, next: 2) STATE 2 default: comment rule (comment) "\*/" (exit level: 1, next: 0) rule (comment) "/\*\*" (exit level: 0, next: 0, nested) rule (type) "(?:\@[[:alpha:]]+)" (exit level: 0, next: 0) rule (todo) "(?:(?:TODO|FIXME)(?:[:]?))" (exit level: 0, next: 0) rule (regexp) "(?:([^[:alnum:]]).*(\1))" (exit level: 0, next: 0) rule (string) "<(?:[^<>])*>" (exit level: 0, next: 0) rule (string2) "<<" (exit level: 0, next: 3) STATE 3 default: string2 rule (string2) ">>" (exit level: 1, next: 0) rule (paren normal paren) "(\[)(.*)(\])" (exit level: 0, next: 0) </pre></div> <p>Since in the rule <code>regexp</code> we used the <code>`</code> regular expression (see <a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a>), then, the marked subexpressions are not translated in order to make backreferences work correctly. </p> <p>The last rule uses explicit subexpressions with names (see <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>); although that expression is made up of different elements, the expression is matched as a whole. </p> <hr> <a name="Tutorials-on-Language-Definitions"></a> <div class="header"> <p> Previous: <a href="#Debugging" accesskey="p" rel="prev">Debugging</a>, Up: <a href="#Language-Definitions" accesskey="u" rel="up">Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Tutorials-on-Language-Definitions-1"></a> <h3 class="section">7.18 Tutorials on Language Definitions</h3> <p>Now we provide some examples of language definitions. In the previous sections we have already provided some code snippets, while here we provide complete examples of language definitions that are included in the source-highlight distribution itself. </p> <p>In particular we will first show the language definition for the language definition syntax itself (file <samp>langdef.lang</samp>). This will be used to highlight the examples of language definitions that we will show in this section (the highlighting will not be visible if you are viewing this manual with the <code>info</code> command). Of course, this example is highlighted itself. </p> <div class="example"> <pre class="example"><span class="roman"><i># this is the language definition for the</i></span> <span class="roman"><i># language definition syntax itself</i></span> <tt><i>comment</i></tt> <b>start</b> <tt>"#"</tt> <tt><i>preproc</i></tt> = <tt>"include"</tt> <tt><i>string</i></tt> <b>delim</b> <tt>"\""</tt> <tt>"\""</tt> <b>escape</b> <tt>"\\"</tt> <b>multiline</b> <tt><i>regexp</i></tt> <b>delim</b> <tt>"'"</tt> <tt>"'"</tt> <b>escape</b> <tt>"\\"</tt> <b>multiline</b> <tt><i>regexp</i></tt> <b>delim</b> <tt>"`"</tt> <tt>"`"</tt> <b>escape</b> <tt>"\\"</tt> <b>multiline</b> <tt><i>keyword</i></tt> = <tt>"state|environment|begin|end|delim|escape|start"</tt>, <tt>"multiline|nested|vardef|exitall|exit"</tt>, <tt>"redef|subst|nonsensitive"</tt> <tt><i>symbol</i></tt> = <tt>"=|+|,|(|)"</tt> <b>vardef</b> <tt><i>ID</i></tt> = <tt>'[[:word:]]+'</tt> <tt><i>variable</i></tt> = <tt>'\$'</tt> + <tt><i>$ID</i></tt> <tt><i>variable</i></tt> = <tt><i>$ID</i></tt> </pre></div> <p>The style that is used to highlight these examples in Texinfo is <samp>texinfo.style</samp> that is shown in <a href="#Output-format-style">Output format style</a>. The language definition for the style syntax (file <samp>style.lang</samp>) is even simpler: </p> <div class="example"> <pre class="example"><span class="roman"><i># this is the language definition for the</i></span> <span class="roman"><i># style definition syntax</i></span> <tt><i>comment</i></tt> <b>start</b> <tt>"//"</tt> <tt><i>string</i></tt> <b>delim</b> <tt>"\""</tt> <tt>"\""</tt> <b>escape</b> <tt>"\\"</tt> <tt><i>keyword</i></tt> = <tt>"bgcolor|purple|orange|brightorange|brightgreen|darkgreen"</tt>, <tt>"green|darkred|red|brown|pink|yellow|cyan"</tt>, <tt>"black|teal|gray|darkblue|blue"</tt>, <tt>"normal|linenum"</tt>, <tt>"noref|nf|f|u|i|b"</tt> <tt><i>keyword</i></tt> = <tt>'bg\:'</tt> <tt><i>symbol</i></tt> = <tt>",|;"</tt> <tt><i>variable</i></tt> = <tt>'[[:word:]]+'</tt> </pre></div> <p>Note that this definition is pretty simple since the language definition syntax is simple. In the next examples we will see how to use more complex features to highlight more complex language syntaxes. </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Highlighting-C_002fC_002b_002b-and-C_0023" accesskey="1">Highlighting C/C++ and C#</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Highlighting-Diff-files" accesskey="2">Highlighting Diff files</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Pseudo-semantic-analysis" accesskey="3">Pseudo semantic analysis</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Highlighting-C_002fC_002b_002b-and-C_0023"></a> <div class="header"> <p> Next: <a href="#Highlighting-Diff-files" accesskey="n" rel="next">Highlighting Diff files</a>, Previous: <a href="#Tutorials-on-Language-Definitions" accesskey="p" rel="prev">Tutorials on Language Definitions</a>, Up: <a href="#Tutorials-on-Language-Definitions" accesskey="u" rel="up">Tutorials on Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Highlighting-C_002fC_002b_002b-and-C_0023-1"></a> <h4 class="subsection">7.18.1 Highlighting C/C++ and C#</h4> <p>This is the language definition for C, included in the file <samp>c.lang</samp>: </p> <div class="example"> <pre class="example"><span class="roman"><i># definitions for C</i></span> <b>include</b> <tt>"c_comment.lang"</tt> <tt><i>label</i></tt> = <tt>'^[[:blank:]]*[[:alnum:]]+:[[:blank:]]*\z'</tt> (<tt><i>keyword</i></tt>,<tt><i>normal</i></tt>,<tt><i>classname</i></tt>) = <tt>`(\<struct)([[:blank:]]+)([[:alnum:]_]+)`</tt> <b>state</b> <tt><i>preproc</i></tt> <b>start</b> <tt>'^[[:blank:]]*#(?:[[:blank:]]*include)'</tt> <b>begin</b> <tt><i>string</i></tt> <b>delim</b> <tt>"<"</tt> <tt>">"</tt> <tt><i>string</i></tt> <b>delim</b> <tt>"\""</tt> <tt>"\""</tt> <b>escape</b> <tt>"\\"</tt> <b>include</b> <tt>"c_comment.lang"</tt> <b>end</b> <tt><i>preproc</i></tt> = <tt>'^[[:blank:]]*#([[:blank:]]*[[:word:]]*)'</tt> <b>include</b> <tt>"number.lang"</tt> <b>include</b> <tt>"c_string.lang"</tt> <tt><i>keyword</i></tt> = <tt>"__asm|__cdecl|__declspec|__export|__far16"</tt>, <tt>"__fastcall|__fortran|__import"</tt>, <tt>"__pascal|__rtti|__stdcall|_asm|_cdecl"</tt>, <tt>"__except|_export|_far16|_fastcall"</tt>, <tt>"__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto"</tt>, <tt>"break|case|catch|cdecl|const|continue|default"</tt>, <tt>"do|else|enum|extern|for|goto"</tt>, <tt>"if|pascal"</tt>, <tt>"register|return|sizeof|static"</tt>, <tt>"struct|switch"</tt>, <tt>"typedef|union"</tt>, <tt>"volatile|while"</tt> <tt><i>type</i></tt> = <tt>"bool|char|double|float|int|long"</tt>, <tt>"short|signed|unsigned|void|wchar_t"</tt> <b>include</b> <tt>"symbols.lang"</tt> <tt><i>cbracket</i></tt> = <tt>"{|}"</tt> <b>include</b> <tt>"function.lang"</tt> <b>include</b> <tt>"clike_vardeclaration.lang"</tt> </pre></div> <p>Note that this makes use of lots of <code>include</code>s since these parts are reused in other language definitions (e.g., Java has lots of parts that are in common with C/C++ so we wrote these parts in separate files). In particular the comments definitions: </p> <div class="example"> <pre class="example"><span class="roman"><i># c_comment.lang</i></span> <span class="roman"><i># comments with documentation tags</i></span> <b>environment</b> <tt><i>comment</i></tt> <b>start</b> <tt>"///"</tt> <b>begin</b> <b>include</b> <tt>"url.lang"</tt> <b>include</b> <tt>"html_simple.lang"</tt> <tt><i>type</i></tt> = <tt>'@[[:alpha:]]+'</tt> <b>include</b> <tt>"todo.lang"</tt> <b>end</b> <tt><i>comment</i></tt> <b>start</b> <tt>"//"</tt> <span class="roman"><i># comments with documentation tags</i></span> <b>environment</b> <tt><i>comment</i></tt> <b>delim</b> <tt>"/**"</tt> <tt>"*/"</tt> <b>multiline</b> <b>begin</b> <b>include</b> <tt>"url.lang"</tt> <b>include</b> <tt>"html_simple.lang"</tt> <tt><i>type</i></tt> = <tt>'@[[:alpha:]]+'</tt> <b>include</b> <tt>"todo.lang"</tt> <b>end</b> <span class="roman"><i># standard comments</i></span> <b>environment</b> <tt><i>comment</i></tt> <b>delim</b> <tt>"/*"</tt> <tt>"*/"</tt> <b>multiline</b> <b>begin</b> <b>include</b> <tt>"url.lang"</tt> <b>include</b> <tt>"todo.lang"</tt> <b>end</b> </pre></div> <p>Here we have the definitions for line-wide comments (<code>//</code>) and for multi line comments where we highlight also URL addresses and e-mail addresses (defined in the file <samp>url.lang</samp> not shown here). Moreover, for comments that are used in automatic documentation generation tools (such as Doxygen or Javadoc), i.e., those that start with <code>/**</code> or <code>///</code>) we also highlight the complete HTML syntax (defined in the file <samp>html.lang</samp> not shown here). </p> <p>Going back to <samp>c.lang</samp> we see that we use subexpressions with names (see <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>) for highlighting the struct name (when preceded by <code>struct</code>, highlighted as a keyword). </p> <p>For preprocessor directives <code>#include</code> we use a state definition since in this case the file included with the <code><file></code> syntax must be formatted as strings (and only in this context the <code><></code> must be considered as strings, anywhere else they are operators). Since a state erases definitions defined outside the state we must include <samp>c_comment.lang</samp> again in order to highlight comments also in this context<a name="DOCF40" href="#FOOT40"><sup>40</sup></a>. Then we have a definition of <code>preproc</code> that catches all the other preprocessor directives. </p> <p>The included file <samp>number.lang</samp> defines the regular expression that catches number constants (not shown here), then we include the file <samp>c_string.lang</samp> that define strings (again shared by Java): </p> <div class="example"> <pre class="example"><b>vardef</b> <tt><i>SPECIALCHAR</i></tt> = <tt>'\\.'</tt> <b>environment</b> <tt><i>string</i></tt> <b>delim</b> <tt>"\""</tt> <tt>"\""</tt> <b>begin</b> <tt><i>specialchar</i></tt> = <tt><i>$SPECIALCHAR</i></tt> <b>end</b> <b>environment</b> <tt><i>string</i></tt> <b>delim</b> <tt>"'"</tt> <tt>"'"</tt> <b>begin</b> <tt><i>specialchar</i></tt> = <tt><i>$SPECIALCHAR</i></tt> <b>end</b> </pre></div> <p>inside a string we want to highlight in a different way the special characters (such as, e.g., <code>\n</code>, <code>\t</code>, etc.) and in general escaped characters, matched by the regular expression ‘<code>\\.</code>’. </p> <p>The included file <samp>symbols.lang</samp> defines all the symbols (shared also by other languages): </p> <div class="example"> <pre class="example"><tt><i>symbol</i></tt> = <tt>"~"</tt>,<tt>"!"</tt>,<tt>"%"</tt>,<tt>"^"</tt>,<tt>"*"</tt>,<tt>"("</tt>,<tt>")"</tt>,<tt>"-"</tt>,<tt>"+"</tt>,<tt>"="</tt>,<tt>"["</tt>, <tt>"]"</tt>,<tt>"\\"</tt>,<tt>":"</tt>,<tt>";"</tt>,<tt>","</tt>,<tt>"."</tt>,<tt>"/"</tt>,<tt>"?"</tt>,<tt>"&"</tt>,<tt>"<"</tt>,<tt>">"</tt>,<tt>"\|"</tt> </pre></div> <p>This has nothing interesting but the fact that it shows that the character <code>\</code> and <code>|</code> have to be escaped. </p> <p>The included file <samp>function.lang</samp> defines the regular expression to match a function definition or invocation: </p> <div class="example"> <pre class="example"><b>vardef</b> <tt><i>FUNCTION</i></tt> = <tt>'([[:alpha:]]|_)[[:word:]]*(?=[[:blank:]]*\()'</tt> <tt><i>function</i></tt> = <tt><i>$FUNCTION</i></tt> </pre></div> <p>that shows an example of forward lookahead assert for the opening parenthesis (see <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>). As noted in <a href="#File-inclusion">File inclusion</a>, it is crucial that this file is included after the keyword definition. </p> <p>Finally, <samp>c.lang</samp> includes the file <samp>clike_vardeclaration.lang</samp>: </p> <div class="example"> <pre class="example">(<tt><i>usertype</i></tt>,<tt><i>usertype</i></tt>,<tt><i>normal</i></tt>) = <tt>`([[:alpha:]_](?:[^[:punct:][:space:]]|[_])*)</tt> <tt>((?:<.*>)?)</tt> <tt>(\s+(?=[*&]*[[:alpha:]_][^[:punct:][:space:]]*\s*[[:punct:]\[\]]+))`</tt> </pre></div> <p>This definition, using subexpressions with names (see <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>), tries<a name="DOCF41" href="#FOOT41"><sup>41</sup></a> to match user types (e.g., struct names) in function parameter and variable declarations. It basically tries to match a type identifier, then a possible template specification<a name="DOCF42" href="#FOOT42"><sup>42</sup></a> and then we have a complete lookahead assert (<a href="#Notes-on-regular-expressions">Notes on regular expressions</a>) that tries to match the variable identifier, possibly with <code>&</code> and <code>*</code> reference and pointer specification, followed by an assignment <code>=</code> or a <code>;</code>, more generally a <code>[:punct:]</code> or <code>[]</code> (for array specifications). This should catch the user types in the correct contexts, as in the following (where we intentionally highlighted <code>usertype</code> in italics): </p> <div class="example"> <pre class="example"><span class="roman"><i>Integer</i></span> i = 10; <span class="roman"><i>Boolean</i></span> b; <span class="roman"><i>String</i></span> args[]; <b>const</b> <span class="roman"><i>MyType</i></span> args[]; <b>const</b> <span class="roman"><i>My_Type</i></span> args[]; <span class="roman"><i>List<Integer></i></span> mylist; <span class="roman"><i>List<List<Integer> ></i></span> mylist; myspace::<span class="roman"><i>InputStream</i></span> iStream ; <span class="roman"><i>MyType</i></span> *t; <span class="roman"><i>MyType</i></span> **t; <b>const</b> <span class="roman"><i>MyType</i></span> &t; <b>if</b> (argc > 0) { } <span class="roman"><i>__mytype</i></span> _i; <b>typedef</b> <span class="roman"><i>_mytype</i></span> __i; </pre></div> <p>Note that since for the third group we use a lookahead assert, what is matched is not actually formatted but it is put back in the input stream so that it can be formatted using other rules (e.g., <code>symbol</code> for <code>*</code> and <code>=</code>). </p> <p>Since, at least syntactically, C++ is an extension of C, the language definition for C++, included in the file <samp>cpp.lang</samp>, relies on <samp>c.lang</samp><a name="DOCF43" href="#FOOT43"><sup>43</sup></a>: </p> <div class="example"> <pre class="example"><span class="roman"><i># definitions for C++</i></span> <span class="roman"><i># most of it is shared with c.lang</i></span> (<tt><i>keyword</i></tt>,<tt><i>normal</i></tt>,<tt><i>classname</i></tt>) = <tt>`(\<(?:class|struct|typename))([[:blank:]]+)([[:alnum:]_]+)`</tt> <tt><i>keyword</i></tt> = <tt>"class|const_cast|delete"</tt>, <tt>"dynamic_cast|explicit|false|friend"</tt>, <tt>"inline|mutable|namespace|new|operator|private|protected"</tt>, <tt>"public|reinterpret_cast|static_cast"</tt>, <tt>"template|this|throw|true"</tt>, <tt>"try|typeid|typename"</tt>, <tt>"using|virtual"</tt> <b>include</b> <tt>"c.lang"</tt> </pre></div> <p>In particular, it extends the set of keywords. Moreover, note that we use subexpressions with names (see <a href="#Explicit-subexpressions-with-names">Explicit subexpressions with names</a>) for highlighting the class (or struct) name (when preceded by <code>class</code>, <code>struct</code> or <code>typename</code>, highlighted as a keyword). A similar rule was also present in <samp>c.lang</samp>, but it concerned only <code>struct</code>. </p> <p>Now that we wrote the language definition for C/C++, writing the one for C# is straightforward, since we only need to add the keyword <code>using</code> as a preprocessor element, and redefine (or better, “substitute”, <a href="#Redefinitions-and-Substitutions">Redefinitions and Substitutions</a>) the keywords and types: </p> <div class="example"> <pre class="example"><span class="roman"><i># definitions for C-sharp</i></span> <span class="roman"><i># by S. HEMMI, updated by L. Bettini.</i></span> <tt><i>preproc</i></tt> = <tt>"using"</tt> <tt><i>number</i></tt> = <tt>'\<[+-]?((0x[[:xdigit:]]+)|(([[:digit:]]*\.)?</tt> <tt>[[:digit:]]+([eE][+-]?[[:digit:]]+)?))([FfDdMmUulL]+)?\>'</tt> <b>include</b> <tt>"cpp.lang"</tt> <b>subst</b> <tt><i>keyword</i></tt> = <tt>"abstract|event|new|struct"</tt>, <tt>"as|explicit|null|switch"</tt>, <tt>"base|extern|this"</tt>, <tt>"false|operator|throw"</tt>, <tt>"break|finally|out|true"</tt>, <tt>"fixed|override|try"</tt>, <tt>"case|params|typeof"</tt>, <tt>"catch|for|private"</tt>, <tt>"foreach|protected"</tt>, <tt>"checked|goto|public|unchecked"</tt>, <tt>"class|if|readonly|unsafe"</tt>, <tt>"const|implicit|ref"</tt>, <tt>"continue|in|return"</tt>, <tt>"virtual"</tt>, <tt>"default|interface|sealed|volatile"</tt>, <tt>"delegate|internal"</tt>, <tt>"do|is|sizeof|while"</tt>, <tt>"lock|stackalloc"</tt>, <tt>"else|static"</tt>, <tt>"enum|namespace"</tt>, <tt>"get|partial|set"</tt>, <tt>"value|where|yield"</tt> <b>subst</b> <tt><i>type</i></tt> = <tt>"bool|byte|sbyte|char|decimal|double"</tt>, <tt>"float|int|uint|long|ulong|object"</tt>, <tt>"short|ushort|string|void"</tt> </pre></div> <hr> <a name="Highlighting-Diff-files"></a> <div class="header"> <p> Next: <a href="#Pseudo-semantic-analysis" accesskey="n" rel="next">Pseudo semantic analysis</a>, Previous: <a href="#Highlighting-C_002fC_002b_002b-and-C_0023" accesskey="p" rel="prev">Highlighting C/C++ and C#</a>, Up: <a href="#Tutorials-on-Language-Definitions" accesskey="u" rel="up">Tutorials on Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Highlighting-Diff-files-1"></a> <h4 class="subsection">7.18.2 Highlighting Diff files</h4> <p>Now we want to highlight files that are generated by <code>diff</code> (typically used to create patches). This program can generate outputs in three different formats (at least at best of my knowledge). </p> <p>With the option <code>-u|--unified</code> the differences among files are shown in the same context, for instance (the examples of the diff files shown here are manually modified so that they can fit in the page width): </p> <div class="example"> <pre class="example">diff -ruP source-highlight-2.1.1/source-highlight.spec ... <i>— source-highlight-2.1.1/source-highlight.spec ...</i> <i>+++ source-highlight-2.1.2/source-highlight.spec ...</i> <b>@@ -6,8 +6,8 @@</b> Summary: syntax highlighting for source documents Name: source-highlight <i>-Version: 2.1.1</i> <i>-Release: 2.1.1</i> <i>+Version: 2.1.2</i> <i>+Release: 2.1.2</i> License: GPL Group: Utilities/Console Source: ftp://ftp.gnu.org/gnu/source-highlight/%{name}-%{version}.tar.gz </pre></div> <p>With the option <code>-c--context</code> the differences are shown into two different parts: </p> <div class="example"> <pre class="example">diff -rc2P source-highlight-2.1.1/source-highlight.spec ... <i>*** source-highlight-2.1.1/source-highlight.spec ...</i> <i>— source-highlight-2.1.2/source-highlight.spec ...</i> <i>***************</i> <i>*** 7,12 ****</i> Summary: syntax highlighting for source documents Name: source-highlight <i>! Version: 2.1.1</i> <i>! Release: 2.1.1</i> License: GPL Group: Utilities/Console <i>— 7,12 —-</i> Summary: syntax highlighting for source documents Name: source-highlight <i>! Version: 2.1.2</i> <i>! Release: 2.1.2</i> License: GPL Group: Utilities/Console diff -rc2P source-highlight-2.1.1/src/latex.outlang ... <i>*** source-highlight-2.1.1/src/latex.outlang ...</i> <i>— source-highlight-2.1.2/src/latex.outlang ...</i> <i>***************</i> <i>*** 35,37 ****</i> <i>— 35,38 —-</i> "--" "-\\/-" "---" "-\\/-\\/-" <i>+ "\"" "\"{}" # avoids problems with some inputenc</i> end </pre></div> <p>Without options it generates only the essential difference information without any addition context lines: </p> <div class="example"> <pre class="example">diff -rP source-highlight-2.1.1/source-highlight.spec ... <b>9,10c9,10</b> <i>< Version: 2.1.1</i> <i>< Release: 2.1.1</i> --- <i>> Version: 2.1.2</i> <i>> Release: 2.1.2</i> </pre></div> <p>Summarizing, we would like to be able to handle all these three different syntaxes; note that the first format and the second format have something conflicting: the first one uses the <code>---</code> to indicate the new version of a file while the second format uses it to indicate the old version of a file. Since we want to highlight differently the old parts and the new parts (this is not visible in the Texinfo highlighting due to the lack of enhanced formatting features, but it is visible for instance in HTML output where we use two different colors), this behavior adds some difficulties. Of course, we could define three different language definitions, one for each diff output format. However, we prefer to handle them all in the same file! </p> <p>This is the language definition for diff files: </p> <div class="example"> <pre class="example"><span class="roman"><i># language definition for files created with ’diff’</i></span> <span class="roman"><i># diff created with -u option</i></span> <b>state</b> <tt><i>oldfile</i></tt> = <tt>'(?=^[-]{3})'</tt> <b>begin</b> <tt><i>oldfile</i></tt> <b>start</b> <tt>'^[-]{3}'</tt> <tt><i>oldfile</i></tt> <b>start</b> <tt>'^[-]'</tt> <tt><i>newfile</i></tt> <b>start</b> <tt>'^[+]'</tt> <tt><i>difflines</i></tt> <b>start</b> <tt>'^@@'</tt> <b>end</b> <span class="roman"><i># diff created with -c option</i></span> <b>state</b> <tt><i>oldfile</i></tt> = <tt>'(?=^[*]{3})'</tt> <b>begin</b> <b>environment</b> <tt><i>oldfile</i></tt> = <tt>'^[*]{3}[[:blank:]]+[[:digit:]]'</tt> <b>begin</b> <tt><i>normal</i></tt> <b>start</b> <tt>'^[[:space:]]'</tt> <tt><i>newfile</i></tt> = <tt>'(?=^[-]{3})'</tt> <b>exit</b> <b>end</b> <tt><i>oldfile</i></tt> <b>start</b> <tt>'^[*]{3}'</tt> <b>environment</b> <tt><i>newfile</i></tt> = <tt>'^[-]{3}[[:blank:]]+[[:digit:]]'</tt> <b>begin</b> <tt><i>normal</i></tt> <b>start</b> <tt>'^[[:space:]]'</tt> <tt><i>newfile</i></tt> = <tt>'(?=^[*]{3})'</tt> <b>exit</b> <tt><i>normal</i></tt> <b>start</b> <tt>'^diff'</tt> <b>exit</b> <b>end</b> <tt><i>newfile</i></tt> <b>start</b> <tt>'^[-]{3}'</tt> <b>end</b> <span class="roman"><i># otherwise, created without options</i></span> <b>state</b> <tt><i>difflines</i></tt> = <tt>'(?=^[[:digit:]])'</tt> <b>begin</b> <tt><i>difflines</i></tt> <b>start</b> <tt>'^[[:digit:]]'</tt> <tt><i>oldfile</i></tt> <b>start</b> <tt>'^[<]'</tt> <tt><i>newfile</i></tt> <b>start</b> <tt>'^[>]'</tt> <b>end</b> </pre></div> <p>Since we can safely assume that when we process a diff file it contains only information created with the same diff command line switch, we define three different states that correspond to the three diff output formats. Note that these states are entered with a simple definition; as noted in <a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a>, this means that no automatic exit means are provided, and since no explicit exit condition is specified, this means that once one of this state is entered it will never be exited. This is consistent with our goal. Of course, the expression that makes us enter a state must be defined correctly, and in particular we first search for an initial <code>---</code> sequence since this is used as the first difference specification by the <code>-u|--unified</code> option, so this is a distinguishing feature to be used to infer which diff format file we are processing. </p> <p>Another interesting thing, is that we use the forward lookahead assert for the opening parenthesis (see <a href="#Notes-on-regular-expressions">Notes on regular expressions</a>), since we only want to see which file format we are processing. Once we entered the right state we can define the regular expressions for the elements of the specific diff file format. </p> <p>For the files created with the option <code>-c|--context</code> we define two inner environments, one for the new file part and one for the old file part (these are delimited by a <code>---</code> or <code>***</code> and line number information). Note that these are environments, so anything that is not matched by any expression is formatted according to the style of the element that defines the environment. Thus, we provide an expression for text that must be formatted as normal. For diff files this corresponds to a line that start with a space or with <code>diff</code> (take a look at the examples above). In particular the latter case can take place only during the new file part. In both environments we must define the exit conditions. In both cases these correspond to the beginning of the complementary part; also in this case we use forward lookahead assertions, since we use it only to exit the environment. The outer definitions for <code>oldfile</code> and <code>newfile</code> are used to match the lines with source file information information. </p> <p>The third state, corresponding to the normal diff output format, should be straightforward by now. </p> <hr> <a name="Pseudo-semantic-analysis"></a> <div class="header"> <p> Previous: <a href="#Highlighting-Diff-files" accesskey="p" rel="prev">Highlighting Diff files</a>, Up: <a href="#Tutorials-on-Language-Definitions" accesskey="u" rel="up">Tutorials on Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Pseudo-semantic-analysis-1"></a> <h4 class="subsection">7.18.3 Pseudo semantic analysis</h4> <p>Source-highlight, by means of regular expressions can only perform lexical analysis of the input source. In particular, it is based on the assumption that the input source is syntactically correct with respect to the input language. However, by using the language definition syntax and by writing the right regular expression it is possible to simulate some sort of semantic analysis of the input source. </p> <p>For instance, consider the following C (or C++) source file: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <b>#if</b> 0 <span class="roman"><i>// equivalent to a comment</i></span> <b>int</b> i = 10; printf(<tt>"this should never be executed</tt>\n<tt>"</tt>); <b>return</b> 1; <b>#else</b> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <b>return</b> 0; <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <p>It is easy to verify that the code between <code>#if 0</code> and <code>#else</code> will be never executed (indeed it will not even be compiled). Thus, we might want to format it as a comment. </p> <p>We then write another language definition file, based on the file <samp>cpp.lang</samp>: </p> <div class="example"> <pre class="example"><b>environment</b> <tt><i>comment</i></tt> <b>start</b> <tt>'^[[:blank:]]*#if[[:blank:]]+0'</tt> <b>begin</b> <tt><i>comment</i></tt> <b>start</b> <tt>'^[[:blank:]]*#(else|endif)'</tt> <b>exit</b> <b>end</b> <b>include</b> <tt>"cpp.lang"</tt> </pre></div> <p>We intentionally included an error in this first version: we used the <code>start</code> element to start the environment, but such element has the scope of a single line, thus, it does not have the desired behavior: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <span class="roman"><i>#if 0 // equivalent to a comment</i></span> <b>int</b> i = 10; printf(<tt>"this should never be executed</tt>\n<tt>"</tt>); <b>return</b> 1; <b>#else</b> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <b>return</b> 0; <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <p>A better solution is the following one: </p> <div class="example"> <pre class="example"><b>environment</b> <tt><i>comment</i></tt> = <tt>'^[[:blank:]]*#[[:blank:]]*if[[:blank:]]+0'</tt> <b>begin</b> <tt><i>comment</i></tt> <b>start</b> <tt>'^[[:blank:]]*#[[:blank:]]*(else|endif)'</tt> <b>exit</b> <b>end</b> <b>include</b> <tt>"cpp.lang"</tt> </pre></div> <p>here we enter the <code>comment</code> environment by not using a delimited element, but simply the regular expression to match <code>#ifdef 0</code>. Then we exit the environment either when we match an <code>#else</code> or a <code>#endif</code>. This seems to work: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <span class="roman"><i>#if 0 // equivalent to a comment</i></span> <span class="roman"><i> int i = 10;</i></span> <span class="roman"><i> printf("this should never be executed\n");</i></span> <span class="roman"><i> return 1;</i></span> <span class="roman"><i>#else</i></span> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <b>return</b> 0; <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <p>However, it does not work if we consider nested <code>#if...#else</code>; for instance consider the following code, formatted with the previous language definition: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <span class="roman"><i>#if 0 // equivalent to a comment</i></span> <span class="roman"><i> int i = 10;</i></span> <span class="roman"><i> printf("this should never be executed\n");</i></span> <span class="roman"><i># ifdef FOO</i></span> <span class="roman"><i> printf("foo\n");</i></span> <span class="roman"><i># ifndef BAR</i></span> <span class="roman"><i> printf("no bar\n");</i></span> <span class="roman"><i># else</i></span> <b># endif</b> <b># else</b> printf(<tt>"no foo</tt>\n<tt>"</tt>); <b># endif</b> <span class="roman"><i>// FOO</i></span> <b>return</b> 1; <b>#else</b> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <b>return</b> 0; <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <p>The problem is that the previous language definition does not consider nested <code>#if</code> and thus, the first time it matches a <code>#else</code> or an <code>#endif</code> it exits the <code>comment</code> environment. </p> <p>We must then take into account possible nested occurrences. This can be done by using a delimited element with the <code>nested</code> option (<a href="#Delimited-definitions">Delimited definitions</a>): </p> <div class="example"> <pre class="example"><span class="roman"><i># treat the preprocess statement</i></span> <span class="roman"><i># #if 0</i></span> <span class="roman"><i># ...</i></span> <span class="roman"><i># #else</i></span> <span class="roman"><i># as a comment</i></span> <b>environment</b> <tt><i>comment</i></tt> = <tt>'^[[:blank:]]*#[[:blank:]]*if[[:blank:]]+0'</tt> <b>begin</b> <tt><i>comment</i></tt> <b>start</b> <tt>'^[[:blank:]]*#[[:blank:]]*else'</tt> <b>exit</b> <tt><i>comment</i></tt> <b>delim</b> <tt>'^[[:blank:]]*#[[:blank:]]*if'</tt> <tt>'^[[:blank:]]*#[[:blank:]]*endif'</tt> <b>multiline</b> <b>nested</b> <b>end</b> <b>include</b> <tt>"cpp.lang"</tt> </pre></div> <p>This time the right block of code is correctly formatted as a comment: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <span class="roman"><i>#if 0 // equivalent to a comment</i></span> <span class="roman"><i> int i = 10;</i></span> <span class="roman"><i> printf("this should never be executed\n");</i></span> <span class="roman"><i># ifdef FOO</i></span> <span class="roman"><i> printf("foo\n");</i></span> <span class="roman"><i># ifndef BAR</i></span> <span class="roman"><i> printf("no bar\n");</i></span> <span class="roman"><i># else</i></span> <span class="roman"><i># endif</i></span> <span class="roman"><i># else</i></span> <span class="roman"><i> printf("no foo\n");</i></span> <span class="roman"><i># endif // FOO</i></span> <span class="roman"><i> return 1;</i></span> <span class="roman"><i>#else</i></span> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <b>return</b> 0; <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <p>Note that it is crucial to exit the environment even when we match an <code>#else</code> (not only an <code>#endif</code>, since, this way, we can match again another <code>#ifdef 0</code>; consider, for instance, the following code: </p> <div class="example"> <pre class="example"><span class="roman"><i>// test special #if 0 treatment</i></span> <b>int</b> main() { <span class="roman"><i>#if 0 // equivalent to a comment</i></span> <span class="roman"><i> int i = 10;</i></span> <span class="roman"><i> printf("this should never be executed\n");</i></span> <span class="roman"><i> return 1;</i></span> <span class="roman"><i>#else</i></span> printf(<tt>"Hello world!</tt>\n<tt>"</tt>); <span class="roman"><i># if 0 // another one</i></span> <span class="roman"><i> return 1;</i></span> <span class="roman"><i># else</i></span> <b>return</b> 0; <b># endif</b> <b>#endif</b> printf(<tt>"never reach here!</tt>\n<tt>"</tt>); } </pre></div> <hr> <a name="Output-Language-Definitions"></a> <div class="header"> <p> Next: <a href="#Generating-References" accesskey="n" rel="next">Generating References</a>, Previous: <a href="#Language-Definitions" accesskey="p" rel="prev">Language Definitions</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Output-Language-Definitions-1"></a> <h2 class="chapter">8 Output Language Definitions</h2> <a name="index-output-language-definition"></a> <p>Since version 2.1 source-highlight uses a specific syntax to specify output formats (e.g., how to format in HTML, LaTeX, etc.). Before version 2.1, in order to add a new output format, many C++ classes had to be written. This had the drawback that a new output format could not be added “dynamically”: you had to recompile the whole source-highlight program. </p> <p>Instead, now, an output format is specified in a file, loaded dynamically, through a (hopefully) simple syntax. Then, these definitions are used internally to create, on-the-fly, text formatters. </p> <p>Here, we see such syntax in details, by relying on many examples. This allows a user to easily modify an existing output format definition and create a new one. These files have, typically, extension <samp>.outlang</samp>. </p> <p>Each definition basically associates a text style (such as, e.g., bold, italics, colors, etc.) to the representation of that style into the output format (such as, e.g., <code><b>$text</b></code> in HTML). The representation is given in <code>"</code> and you can use the classic escape character <code>\</code> to use the <code>"</code> inside the definition. If you want to specify the ASCII code for a character you can do so by specifying the numeric code in hexadecimal notation preceded by <code>\x</code>, for an example, see <a href="#Style-template">Style template</a>. </p> <p>If no definition is given for a specific style, e.g., bold, then when that style is requested during formatting, the text will be formatted as it is, i.e., the style without the definition is simply ignored. </p> <p>Comments can be given by using <code>#</code>; the rest of the line is considered as a comment. </p> <p>Files can be included in the same way as for language definitions, <a href="#File-inclusion">File inclusion</a>. </p> <p>In any case, if a definition for a style is given more than once, the last definition replaces all the others. </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#File-extension" accesskey="1">File extension</a>:</td><td> </td><td align="left" valign="top">Specify the output file extension </td></tr> <tr><td align="left" valign="top">• <a href="#Text-styles" accesskey="2">Text styles</a>:</td><td> </td><td align="left" valign="top">Bold, Italics, Underline, etc. </td></tr> <tr><td align="left" valign="top">• <a href="#Colors" accesskey="3">Colors</a>:</td><td> </td><td align="left" valign="top">Style and definitions for colors </td></tr> <tr><td align="left" valign="top">• <a href="#Anchors-and-References" accesskey="4">Anchors and References</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#One-style" accesskey="5">One style</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Style-template" accesskey="6">Style template</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Line-prefix" accesskey="7">Line prefix</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#String-translation" accesskey="8">String translation</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Document-template" accesskey="9">Document template</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Generating-HTML-output">Generating HTML output</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="File-extension"></a> <div class="header"> <p> Next: <a href="#Text-styles" accesskey="n" rel="next">Text styles</a>, Previous: <a href="#Output-Language-Definitions" accesskey="p" rel="prev">Output Language Definitions</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="File-extension-1"></a> <h3 class="section">8.1 File extension</h3> <p>With the line: </p> <div class="example"> <pre class="example">extension "<file extension>" </pre></div> <p>you define the default file extension (without the <code>.</code>) used to generate files formatted according to this output format. This is used when no output file name is specified; if the file extension is not included in the <code>.outlang</code> is not defined, and no output file name is specified, an error will occur. </p> <p>For instance, this is used in <samp>html_common.outlang</samp>: </p> <div class="example"> <pre class="example">extension "html" </pre></div> <hr> <a name="Text-styles"></a> <div class="header"> <p> Next: <a href="#Colors" accesskey="n" rel="next">Colors</a>, Previous: <a href="#File-extension" accesskey="p" rel="prev">File extension</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Text-styles-1"></a> <h3 class="section">8.2 Text styles</h3> <a name="index-bold-1"></a> <a name="index-italics-1"></a> <a name="index-underline-1"></a> <a name="index-fixed-1"></a> <a name="index-notfixed-1"></a> <p>These are the text styles that one can define: </p> <div class="example"> <pre class="example">bold italics underline notfixed fixed </pre></div> <p>These, of course, correspond to the ones used to specify the output format style, <a href="#Output-format-style">Output format style</a>. </p> <p>These definitions, for instance, are from the HTML format definition: </p> <div class="example"> <pre class="example">bold "<b>$text</b>" italics "<i>$text</i>" underline "<u>$text</u>" </pre></div> <a name="index-_0024text"></a> <p>Inside a definition you use the special variable <code>$text</code> to specify where the actual text to be formatted has to be inserted. For instance, the definition of <code>bold</code> above says that if you need to format the keyword <code>class</code> in bold in HTML, the following text will be generated: <code><b>class</b></code>. This variable is used also when mixing more than one styles recursively, in particular if you want to format in bold and italics (i.e, first bold and then italics, or, in other words, the sequence <code>i, b</code> is used in the the output format style file, see <a href="#Output-format-style">Output format style</a>), then first the text <code>class</code> is substituted for <code>$text</code> into <code><b>$text</b></code> and then the text <code><b>class</b></code> will be substituted for <code>$text</code> into <code><i>$text</i></code>, thus obtaining <code><i><b>class</b></i></code>. </p> <hr> <a name="Colors"></a> <div class="header"> <p> Next: <a href="#Anchors-and-References" accesskey="n" rel="next">Anchors and References</a>, Previous: <a href="#Text-styles" accesskey="p" rel="prev">Text styles</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Colors-1"></a> <h3 class="section">8.3 Colors</h3> <a name="index-colors"></a> <a name="index-_0024style"></a> <p>The definition for using colors during formatting requires the definition for the <code>color</code> style </p> <div class="example"> <pre class="example">color "..." </pre></div> <a name="index-background-color-2"></a> <p>and for the <code>bgcolor</code> style<a name="DOCF44" href="#FOOT44"><sup>44</sup></a>: </p> <div class="example"> <pre class="example">bgcolor "..." </pre></div> <p>This definition concerns only the background color for a specific highlighted element, i.e., the color specified in the style file with the prefix <code>bg:</code> (see <a href="#Output-format-style">Output format style</a>) or the property <code>background-color</code> specified in a CSS file passed to <code>--style-css-file</code> (see <a href="#Output-format-style-using-CSS">Output format style using CSS</a>). Thus it should not be confused with the background color of the entire output (i.e., the one specified using <code>bgcolor</code> in a style file or the property <code>background-color</code> of the <code>body</code> selector in a CSS). The background color for the entire document is explained in <a href="#Document-template">Document template</a>. </p> <p>Note that the background color might not be available for all output formats. For instance, for HTML we only have: </p> <div class="example"> <pre class="example">color "<font color=\"$style\">$text</font>" </pre></div> <p>while for XHTML we have: </p> <div class="example"> <pre class="example">color "<span style=\"color: $style\">$text</span>" bgcolor "<span style=\"background-color: $style\">$text</span>" </pre></div> <p>Apart from the variable <code>$text</code> that we already saw, we have also the variable <code>$style</code>, that will be replaced with the actual color. </p> <p>Source-highlight recognizes a number of color constants, see <a href="#Output-format-style">Output format style</a>. </p> <p>You then must associate a color constant to the color definition in the output format, through the <code>colormap</code> definition: </p> <div class="example"> <pre class="example">colormap "color constant" "color representation" "color constant" "color representation" ... default "default color representation" end </pre></div> <p>The <code>default</code> row (note the absence of <code>"</code>) defines the color to be used in case a color constant is used during formatting, but it is not defined in the output format. </p> <p>For instance, for HTML we have: </p> <div class="example"> <pre class="example">colormap "green" "#33CC00" "red" "#FF0000" "darkred" "#990000" "blue" "#0000FF" "brown" "#9A1900" "pink" "#CC33CC" "yellow" "#FFCC00" "cyan" "#66FFFF" "purple" "#993399" "orange" "#FF6600" "brightorange" "#FF9900" "brightgreen" "#33FF33" "darkgreen" "#009900" "black" "#000000" "teal" "#008080" "gray" "#808080" "darkblue" "#000080" default "#000000" end </pre></div> <p>If your output format does not handle colors you can simply avoid the definitions of <code>color</code> and <code>colormap</code> and Source-highlight will simply ignore colors. </p> <p>The color is applied after applying the other styles, e.g., bold, italics, etc. </p> <p>Thus, by continuing the example of the previous section, suppose you defined the following output style for keywords: </p> <div class="example"> <pre class="example">keyword blue i, b; </pre></div> <p>then the <code>class</code> text will be replaced to <code>$text</code> variable and the value <code>#0000FF</code> to <code>$style</code> inside the color definition <code><font color="$style">$text</font></code> obtaining <code><font color="#0000FF">class</font></code> which will then be replaced to <code>$text</code> in <code><b>$text</b></code> and so on for italics, finally obtaining </p> <p><code><i><b><font color="#0000FF">class</font></b></i></code>. </p> <hr> <a name="Anchors-and-References"></a> <div class="header"> <p> Next: <a href="#One-style" accesskey="n" rel="next">One style</a>, Previous: <a href="#Colors" accesskey="p" rel="prev">Colors</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Anchors-and-References-1"></a> <h3 class="section">8.4 Anchors and References</h3> <a name="index-_0024linenum"></a> <p>When using the command line option <code>--line-number-ref</code> (<a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>) an anchor is generated in the output file for each line numbering. The style of the anchor is defined by the definition <code>anchor</code>. If this is not defined, the option <code>--line-number-ref</code> has no effect. The <code>$linenum</code> variable will be replaced with the line number, and the <code>$text</code> variable with the actual text. </p> <p>For instance, for HTML we have </p> <div class="example"> <pre class="example">anchor "<a name=\"$linenum\">$text</a>" </pre></div> <a name="index-_0024infile"></a> <a name="index-_0024infilename"></a> <a name="index-_0024outfile"></a> <p>Since version 2.2 source-highlight can also generate references to several elements (e.g., variables, class definitions, etc.), <a href="#Generating-References">Generating References</a>. Also in this case the definition <code>anchor</code> is used; furthermore, the definition of <code>reference</code> is required. In the definition of <code>anchor</code> and <code>reference</code>, apart from the variable <code>$linenum</code>, we also have the variables <code>$infile</code> (the name of the original input file) and <code>$infilename</code> (the name of the original input file without the path) and in the definition of <code>reference</code> we also have the variable <code>$outfile</code> (the name of the file where the anchor is). One can decide how to define an anchor and a reference by using these two variables. For instance, for HTML we have </p> <div class="example"> <pre class="example">reference "<a href=\"$outfile#$linenum\">$text</a>" </pre></div> <p>Note, that in this case we use the <code>$outfile</code> since we actually generate a link to another (or possibly the same) output file. </p> <p>On the contrary, for LaTeX, since we do not generate a “clickable” reference, we refer to the original input file (we use both <code>$infilename</code> and <code>$linenum</code> in both definitions of <code>anchor</code> and <code>reference</code>): </p> <div class="example"> <pre class="example">anchor "\label{$infilename:$linenum}$text" reference "{\hfill $text $\rightarrow$ $infile:$linenum, \ page~\pageref{$infilename:$linenum}}" </pre></div> <p>In particular, we use <code>$infilename</code> for generating the <code>\label</code> and not <code>$infile</code> because the path symbol would “disturb” LaTeX (while we use the complete file path in the textual information of the reference). </p> <p>This will generate a right aligned reference. Note that it is assumed that when generating references in LaTeX one uses <code>--gen-references=postline</code> or <code>--gen-references=postdoc</code> and not <code>--gen-references=inline</code> (<a href="#Generating-References">Generating References</a>), since it makes no sense to generate an inline reference (or at least I would not know how to generate a nice looking one :-). </p> <p>Furthermore, for Texinfo: </p> <div class="example"> <pre class="example">anchor "@anchor{$infilename:$linenum}$text" reference "@flushright @xref{$infilename:$linenum,$text,$text $infile:$linenum}. @end flushright" </pre></div> <p>Note that using both <code>$infilename</code> (and not <code>$infile</code> for the same reasons) and <code>$linenum</code> also in the definition of <code>anchor</code> somehow ensures that there are no duplicate anchors; this is done for LaTeX and Texinfo but not for HTML because it is assumed that the generated <samp>.tex</samp> and <samp>.texinfo</samp> file is included directly in a master file, as it is done in this manual (while, for instance, it is assumed that a separate HTML file is generated for each source and kept separate). If this is not your case you can change the definitions of <code>anchor</code> and <code>reference</code> as you see fit. Some examples of outputs with references in Texinfo are shown in <a href="#Examples">Examples</a>. </p> <a name="index-inline_005freference"></a> <a name="index-postline_005freference"></a> <a name="index-postdoc_005freference"></a> <p>Indeed, one can use three more definitions for <code>reference</code> that corresponds to the three arguments that can be passed to <code>--gen-references</code> command line option (<a href="#Generating-References">Generating References</a>): <code>inline_reference</code>, <code>postline_reference</code> and <code>postdoc_reference</code>. If one of this not defined, then the same definition of <code>reference</code> is used. Having the possibility of specifying different definitions is useful for instance in the case of HTML: the same style for an inline reference is pretty ugly when used also for a postline or postdoc reference: </p> <div class="smallexample"> <pre class="smallexample">postline_reference "<a href=\"$outfile#$linenum\">$text -> $infile:$linenum</a>" postdoc_reference "<a href=\"$outfile#$linenum\">$text -> $infile:$linenum</a>" reference "<a href=\"$outfile#$linenum\">$text</a>" </pre></div> <hr> <a name="One-style"></a> <div class="header"> <p> Next: <a href="#Style-template" accesskey="n" rel="next">Style template</a>, Previous: <a href="#Anchors-and-References" accesskey="p" rel="prev">Anchors and References</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="One-style-1"></a> <h3 class="section">8.5 One style</h3> <a name="index-one-style"></a> <p>If the output format you are defining does not have a specific style for bold, italics, ... and for colors you can simply use the definition <code>onestyle</code>, where you can use both <code>$style</code> and <code>$text</code>. This will be used for any style (indeed any other definition such as bold, italics, color will be ignored). Indeed, in this case, it is assumed that the style of each source element is defined in a file with its own syntax, i.e., not with a syntax defined by Source-highlight. (This is the case, for instance, of HTML using CSS style sheets.) Moreover, since the output format style is not used, during formatting the variable <code>$style</code> will be replaced with the name of the element to highlight (e.g., <code>keyword</code>, <code>comment</code>, etc.). </p> <p>For instance, for HTML CSS, we simply have: </p> <div class="example"> <pre class="example">onestyle "<span class=\"$style\">$text</span>" </pre></div> <p>In fact, HTML CSS relies on style definitions provided in a separate file (the <samp>.css</samp> file indeed). Thus, when formatting a <code>keyword</code>, e.g., <code>abstract</code>, we will obtain: </p> <div class="example"> <pre class="example"><span class="keyword">abstract</span> </pre></div> <p>Of course, the style for <code>keyword</code> must be defined in the <samp>.css</samp> file. </p> <hr> <a name="Style-template"></a> <div class="header"> <p> Next: <a href="#Line-prefix" accesskey="n" rel="next">Line prefix</a>, Previous: <a href="#One-style" accesskey="p" rel="prev">One style</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Style-template-1"></a> <h3 class="section">8.6 Style template</h3> <a name="index-style-template"></a> <a name="index-style-separator"></a> <p>Some output formats are based on a unique template that where the other styles are composed; during composition the styles can be separated with a specific separator: </p> <div class="example"> <pre class="example">styletemplate "..." styleseparator "..." </pre></div> <p>This is used, for instance, for the ANSI color escape sequence output format (<samp>esc.outlang</samp>): </p> <div class="example"> <pre class="example">styletemplate "\x1b[$stylem$text\x1b[m" styleseparator ";" bold "01$style" underline "04$style" italics "$style" color "$style" </pre></div> <p>Note that, since more than one style can be mixed into the style template, <code>bold</code>, <code>underline</code>, ... explicitly use the variable <code>$style</code>. </p> <hr> <a name="Line-prefix"></a> <div class="header"> <p> Next: <a href="#String-translation" accesskey="n" rel="next">String translation</a>, Previous: <a href="#Style-template" accesskey="p" rel="prev">Style template</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Line-prefix-1"></a> <h3 class="section">8.7 Line prefix</h3> <p>This feature allows you to generate a string as the prefix of each generated line that corresponds to an input line (i.e., this prefix is not generated for other generated output elements, e.g., the lines in the header, footer, etc.). </p> <p>We use this feature in the LaTeX output (<a href="#LaTeX-output">LaTeX output</a>): </p> <div class="example"> <pre class="example">lineprefix "\mbox{}" </pre></div> <p>This way each line in the LaTeX output is prefixed with <code>\mbox{}</code><a name="DOCF45" href="#FOOT45"><sup>45</sup></a>. </p> <p>Another interesting example that uses <code>lineprefix</code> is the javadoc output, see <a href="#Generating-HTML-output">Generating HTML output</a>. </p> <hr> <a name="String-translation"></a> <div class="header"> <p> Next: <a href="#Document-template" accesskey="n" rel="next">Document template</a>, Previous: <a href="#Line-prefix" accesskey="p" rel="prev">Line prefix</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="String-translation-1"></a> <h3 class="section">8.8 String translation</h3> <p>Some character sequences that are in the source file may have a special meaning in an output format, so they need some preprocessing (e.g., escaping them). You can specify the translation table with: </p> <div class="example"> <pre class="example">translations "original sequence" "transformed sequence" 'regex' "transformed sequence" ... end </pre></div> <p>The difference between <code>"original sequence"</code> and <code>'regex'</code><a name="DOCF46" href="#FOOT46"><sup>46</sup></a> is that with the former you specify a character sequence that will be matched literally, apart from special characters such as <code>\</code> (which, if needed to be inserted, must be escaped), <code>\n</code> (new line) and <code>\t</code> (tab character). Instead, with the latter, you can specify a regular expression (this is basically the same difference between <code>"</code> and <code>'</code> in language definitions, see <a href="#Simple-definitions">Simple definitions</a>). </p> <p>For instance, for HTML, we have the following translation table: </p> <div class="example"> <pre class="example">translations "&" "&amp;" "<" "&lt;" ">" "&gt;" end </pre></div> <p>For LaTeX, the translation table is a little bit bigger; here we show only a little part, that shows how to escape special characters (such as <code>\</code>), to translate a new line character and tab character: </p> <div class="example"> <pre class="example">translations "<" "$<$" ">" "$>$" "&" "\\&" "\\" "\\textbackslash{}" "\n" " \\\\\n" " " "\\ " "\t" "\\ \\ \\ \\ \\ \\ \\ \\ " end </pre></div> <p>Note that, since a new character must be translated in LaTeX with <code>\\</code>, we have to escape two <code>\</code> (i.e., <code>\\\\</code>) and then we want to actually insert a new line in the output file <code>\n</code>. </p> <p>For HTML with not fixed font by default, <samp>html_notfixed.outlang</samp> (see <a href="#HTML-and-XHTML-output">HTML and XHTML output</a>), we need two translate two space sequence (i.e., two adjacent spaces, since in HTML more adjacent spaces are rendered as only one space<a name="DOCF47" href="#FOOT47"><sup>47</sup></a>, while we want them as they are), and we also need to translate a space starting a new line in the source (thus we use the regular expression <code>^ </code>, enclosed in <code>'</code>); thus we have: </p> <div class="example"> <pre class="example">translations "\n" "<br>\n" " " "&nbsp; " '^ ' "&nbsp;" # a space at the beginning of a line "\t" "&nbsp; &nbsp; &nbsp; &nbsp; " end </pre></div> <hr> <a name="Document-template"></a> <div class="header"> <p> Next: <a href="#Generating-HTML-output" accesskey="n" rel="next">Generating HTML output</a>, Previous: <a href="#String-translation" accesskey="p" rel="prev">String translation</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Document-template-1"></a> <h3 class="section">8.9 Document template</h3> <p>You can define the beginning and the end of an output file, with </p> <a name="index-doctemplate"></a> <div class="example"> <pre class="example">doctemplate "...beginning..." "...end..." end </pre></div> <a name="index-nodoctemplate"></a> <div class="example"> <pre class="example">nodoctemplate "...beginning..." "...end..." end </pre></div> <p>The first one is used when the <code>--doc</code> command line option is specified, while the second one is used in the other case<a name="DOCF48" href="#FOOT48"><sup>48</sup></a>. </p> <p>For instance, for HTML we have </p> <div class="example"> <pre class="example">nodoctemplate "<!-- Generator: $additional --> $header<pre><tt>" "</tt></pre>$footer " end </pre></div> <p>Note that in the end part there is an explicit new line. </p> <p>In the definition of the <code>doctemplate</code> and <code>nodoctemplate</code> the following variables can be used and will be replaced during the output generation: </p> <dl compact="compact"> <dt><code>$title</code></dt> <dd><p>the value of the title for the output file (e.g., the one passed with the <code>--title</code> command line option; </p></dd> <dt><code>$header</code></dt> <dd><p>the contents of the file specified with the command line option <code>--header</code>; </p></dd> <dt><code>$footer</code></dt> <dd><p>the contents of the file specified with the command line option <code>--footer</code>; </p></dd> <dt><code>$css</code></dt> <dd><p>the value passed with the command line option <code>--css</code>; </p></dd> <dt><code>$additional</code></dt> <dd><p>other additional information. Source-highlight replaces this with its name and its version. </p></dd> <dt><code>$docbgcolor<a name="DOCF49" href="#FOOT49"><sup>49</sup></a></code></dt> <dd><p>the background color for the output document. Source-highlight replaces this with the value specified in the <code>bgcolor</code> of the <samp>.style</samp> file (see <a href="#Output-format-style">Output format style</a>) or in the <code>body</code> selector of the CSS file passed with <code>--style-css-file</code> (see <a href="#Output-format-style-using-CSS">Output format style using CSS</a>). </p></dd> </dl> <p>For instance, for an HTML document with css, (file <samp>htmlcss.outlang</samp>) we have: </p> <div class="example"> <pre class="example">doctemplate "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> <meta name=\"GENERATOR\" content=\"$additional\"> <title>$title</title> <link rel=\"stylesheet\" href=\"$css\" type=\"text/css\"> </head> <body> $header<pre><tt>" "</tt></pre> $footer</body> </html> " end </pre></div> <p>For an HTML document with header and footer, (file <samp>html.outlang</samp>) we have (note the use of <code>$docbgcolor</code>): </p> <div class="example"> <pre class="example">doctemplate "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> <meta name=\"GENERATOR\" content=\"$additional\"> <title>$title</title> </head> <body bgcolor=\"$docbgcolor\"> $header<pre><tt>" "</tt></pre> $footer</body> </html> " end </pre></div> <p>And for an HTML table output (file <samp>htmltable.outlang</samp>): </p> <div class="example"> <pre class="example">doctemplate "<table BGCOLOR=\"$docbgcolor\" NOSAVE > <tr NOSAVE> <td NOSAVE> <pre><tt>" "</tt></pre> </td> </tr> </table> " end </pre></div> <hr> <a name="Generating-HTML-output"></a> <div class="header"> <p> Previous: <a href="#Document-template" accesskey="p" rel="prev">Document template</a>, Up: <a href="#Output-Language-Definitions" accesskey="u" rel="up">Output Language Definitions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Generating-HTML-output-1"></a> <h3 class="section">8.10 Generating HTML output</h3> <p>As a complete example we show the file <samp>html_common.outlang</samp> which contains the common definitions for the various HTML output formats (<samp>html.outlang</samp>, <samp>htmltable.outlang</samp>, etc.): </p> <div class="example"> <pre class="example"><b>include</b> <tt>"html_ref.outlang"</tt> <b>extension</b> <tt>"html"</tt> <b>bold</b> <tt>"<b>$text</b>"</tt> <b>italics</b> <tt>"<i>$text</i>"</tt> <b>underline</b> <tt>"<u>$text</u>"</tt> <b>color</b> <tt>"<font color=\"$style\">$text</font>"</tt> <b>colormap</b> <tt>"green"</tt> <tt>"#33CC00"</tt> <tt>"red"</tt> <tt>"#FF0000"</tt> <tt>"darkred"</tt> <tt>"#990000"</tt> <tt>"blue"</tt> <tt>"#0000FF"</tt> <tt>"brown"</tt> <tt>"#9A1900"</tt> <tt>"pink"</tt> <tt>"#CC33CC"</tt> <tt>"yellow"</tt> <tt>"#FFCC00"</tt> <tt>"cyan"</tt> <tt>"#66FFFF"</tt> <tt>"purple"</tt> <tt>"#993399"</tt> <tt>"orange"</tt> <tt>"#FF6600"</tt> <tt>"brightorange"</tt> <tt>"#FF9900"</tt> <tt>"brightgreen"</tt> <tt>"#33FF33"</tt> <tt>"darkgreen"</tt> <tt>"#009900"</tt> <tt>"black"</tt> <tt>"#000000"</tt> <tt>"teal"</tt> <tt>"#008080"</tt> <tt>"gray"</tt> <tt>"#808080"</tt> <tt>"darkblue"</tt> <tt>"#000080"</tt> <tt>"white"</tt> <tt>"#FFFFFF"</tt> <b>default</b> <tt>"#000000"</tt> <b>end</b> <b>translations</b> <tt>"&"</tt> <tt>"&amp;"</tt> <tt>"<"</tt> <tt>"&lt;"</tt> <tt>">"</tt> <tt>"&gt;"</tt> <b>end</b> </pre></div> <p>Moreover, this file is also used for generating javadoc output: </p> <div class="example"> <pre class="example"><b>include</b> <tt>"html_common.outlang"</tt> <b>doctemplate</b> <tt>" * <!-- Generated by Source-highlight --></tt> <tt> * <pre><tt></tt> <tt>"</tt> <tt>" * </tt></pre></tt> <tt>"</tt> <b>end</b> <b>nodoctemplate</b> <tt>" * <!-- Generated by Source-highlight --></tt> <tt> * <pre><tt></tt> <tt>"</tt> <tt>" * </tt></pre></tt> <tt>"</tt> <b>end</b> <b>lineprefix</b> <tt>" * "</tt> <b>translations</b> <tt>"*/"</tt> <tt>"&#42;/"</tt> <span class="roman"><i># this avoids the */ to be interpreted as</i></span> <span class="roman"><i># the end of a comment inside a javadoc comment</i></span> <b>end</b> </pre></div> <p>The javadoc output format is useful to format code snippets that have to be included inside a javadoc comment of another Java file<a name="DOCF50" href="#FOOT50"><sup>50</sup></a>. Apart from being formatted nicely in the generated HTML documentation, this also releases the programmer from escaping specific characters in the code snippet (i.e., <code>&</code>, <code><</code> and <code>></code>). Note also that it also avoids the sequence <code>*/</code> to be interpreted as the closing of the (javadoc) comment. For instance, if you write this code: </p> <div class="example"> <pre class="example">/** * This is an example of usage * * <pre><tt> * System.out.println("*/"); * </tt></pre> */ </pre></div> <p>The resulting Java code contains a syntax error. If you use source-highlight to format the code to insert in a javadoc comment you will avoid these problems. </p> <p>An example of a javadoc generated HTML page containing a code snippet formatted with source-highlight can be found in the file <samp>SimpleClass-doc.html</samp> in the documentation directory. </p> <hr> <a name="Generating-References"></a> <div class="header"> <p> Next: <a href="#Examples" accesskey="n" rel="next">Examples</a>, Previous: <a href="#Output-Language-Definitions" accesskey="p" rel="prev">Output Language Definitions</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Generating-References-1"></a> <h2 class="chapter">9 Generating References</h2> <a name="index-reference"></a> <a name="index-anchor"></a> <a name="index-ctags"></a> <p>Since version 2.2 Source-highlight also produces references to fields, variables, etc. In order to do this it relies on the program <em>Exuberant Ctags</em>, by Darren Hiebert, available at <a href="http://ctags.sourceforge.net">http://ctags.sourceforge.net</a>. Thus, you must install this program if you want Source-highlight to provide this feature. </p> <p>The <code>ctags</code> program generates an index (or “tag”) file for a variety of language objects found in file(s). This allows these items to be quickly and easily located by a text editor or other utility (as in this case for Source-highlight). A “tag” signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object)<a name="DOCF51" href="#FOOT51"><sup>51</sup></a>. </p> <p>This means that Source-highlight is able to generate references for a specific source language if and only if <code>ctags</code> handles such language. We refer to the command line options of <code>ctags</code>: <code>--list-maps</code> and <code>--list-languages</code> to find out the associations of file extensions and supported languages. </p> <p>Reference generation is enable by using the command line option <code>--gen-references</code> (<a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>). This option takes an argument that rules how references will be generated: </p> <dl compact="compact"> <dt><code>inline</code></dt> <dd><p>a reference pointer will be generated exactly in the same place of the specific element. This is useful in output formats that naturally supports links, such as HTML, while it is useless for output formats that do not support inline links, such as LaTeX. </p></dd> <dt><code>postline</code></dt> <dd><p>if a line of the input source contains elements for which we found references, the list of references will be generated right after the line (see the examples, <a href="#Examples">Examples</a>). </p></dd> <dt><code>postdoc</code></dt> <dd><p>All the references will be generated after the whole input file has been generated. </p></dd> </dl> <p>There is an exception: when an element has more than one reference (because a variable is defined in many sources or because a method is overloaded) then if <code>inline</code> is specified, the generation switches to <code>postline</code> for that occurrence. </p> <p>When <code>--gen-references</code> is specified, Source-highlight first invokes <code>ctags</code>. The use can customize this call by using the command line option <code>--ctags</code> (<a href="#Invoking-source_002dhighlight">Invoking source-highlight</a>). In particular, if one does not want <code>ctags</code> to be invoked by Source-highlight (e.g., because the tags file has already been generated) then <code>--ctags</code> must be passed an empty string, <code>""</code>. In this case or when the specified <code>ctags</code> command line generates an alternative output tag file (the default generated file is <samp>tags</samp>), one must specify the exact tag file with the command line option <code>--ctags-file</code>. </p> <p>Once the tag file is generated, Source-highlight relies on the library <samp>readtags</samp> provided by the <code>ctags</code> distribution, and included in the Source-highlight sources. </p> <p>Note that if a program element is formatted according to a style that has the option <code>noref</code> (see <a href="#Output-format-style">Output format style</a>) then this element is not considered a tag, and no reference is generated. This is the case, for instance, for a <code>comment</code> element: each string that is generated with the <code>comment</code> style, since this is declared with the option <code>noref</code>, it is not considered a tag (see <a href="#Examples">Examples</a>). </p> <hr> <a name="Examples"></a> <div class="header"> <p> Next: <a href="#Problems" accesskey="n" rel="next">Problems</a>, Previous: <a href="#Generating-References" accesskey="p" rel="prev">Generating References</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Examples-1"></a> <h2 class="chapter">10 Examples</h2> <p>Here we provide some examples of sources formatted with Source-highlight using the <code>-f texinfo</code> command line option. Please keep in mind that the highlighting will not be visible in the Info file, but only in the printed manual and in the HTML output (well, at least line numbers are visible everywhere :-). </p> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="#Simple-example" accesskey="1">Simple example</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#References" accesskey="2">References</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Line-ranges" accesskey="3">Line ranges</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Line-ranges-_0028with-context_0029" accesskey="4">Line ranges (with context)</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="#Regex-ranges" accesskey="5">Regex ranges</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <a name="Simple-example"></a> <div class="header"> <p> Next: <a href="#References" accesskey="n" rel="next">References</a>, Previous: <a href="#Examples" accesskey="p" rel="prev">Examples</a>, Up: <a href="#Examples" accesskey="u" rel="up">Examples</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Simple-example-1"></a> <h3 class="section">10.1 Simple example</h3> <p>The first example is produced by using the command: </p> <div class="example"> <pre class="example">source-highlight -f texinfo -i test.java -o test.java.texinfo -n </pre></div> <p>and here’s the result </p> <div class="example"> <pre class="example"><tt>01:</tt> <span class="roman"><i>/*</i></span> <tt>02:</tt> <span class="roman"><i> This is a classical Hello program</i></span> <tt>03:</tt> <span class="roman"><i> to test source-highlight with Java programs.</i></span> <tt>04:</tt> <span class="roman"><i> </i></span> <tt>05:</tt> <span class="roman"><i> to have an html translation type</i></span> <tt>06:</tt> <tt>07:</tt> <span class="roman"><i> source-highlight -s java -f html –input Hello.java –output Hello.html</i></span> <tt>08:</tt> <span class="roman"><i> source-highlight -s java -f html < Hello.java > Hello.html</i></span> <tt>09:</tt> <tt>10:</tt> <span class="roman"><i> or type source-highlight –help for the list of options</i></span> <tt>11:</tt> <tt>12:</tt> <span class="roman"><i> written by</i></span> <tt>13:</tt> <span class="roman"><i> Lorenzo Bettini</i></span> <tt>14:</tt> <span class="roman"><i> </i></span><tt>http://www.lorenzobettini.it</tt> <tt>15:</tt> <span class="roman"><i> </i></span><tt>http://www.gnu.org/software/src-highlite</tt> <tt>16:</tt> <span class="roman"><i>*/</i></span> <tt>17:</tt> <tt>18:</tt> <b>package</b> hello; <tt>19:</tt> <tt>20:</tt> <b>import</b> java.io.* ; <tt>21:</tt> <tt>22:</tt> <span class="roman"><i>/**</i></span> <tt>23:</tt> <span class="roman"><i> * </i></span><b><p></b> <tt>24:</tt> <span class="roman"><i> * A simple Hello World class, used to demonstrate some</i></span> <tt>25:</tt> <span class="roman"><i> * features of Java source highlighting.</i></span> <tt>26:</tt> <span class="roman"><i> * </i></span><b></p></b> <tt>27:</tt> <span class="roman"><i> * </i></span>TODO:<span class="roman"><i> nothing, just to show an highlighted </i></span>TODO<span class="roman"><i> or </i></span>FIXME <tt>28:</tt> <span class="roman"><i> *</i></span> <tt>29:</tt> <span class="roman"><i> * </i></span><b>@author</b><span class="roman"><i> Lorenzo Bettini</i></span> <tt>30:</tt> <span class="roman"><i> * </i></span><b>@version</b><span class="roman"><i> 2.0</i></span> <tt>31:</tt> <span class="roman"><i> */</i></span> <span class="roman"><i>/// class</i></span> <tt>32:</tt> <b>public</b> <b>class</b> Hello { <tt>33:</tt> <b>int</b> foo = 1998 ; <tt>34:</tt> <b>int</b> hex_foo = 0xCAFEBABE; <tt>35:</tt> <b>boolean</b> b = <b>false</b>; <tt>36:</tt> Integer i = <b>null</b> ; <tt>37:</tt> <b>char</b> c = <tt>'</tt>\'<tt>'</tt>, d = <tt>'n'</tt>, e = <tt>'</tt>\\<tt>'</tt> ; <tt>38:</tt> String xml = <tt>"<tag attr=</tt>\"<tt>value</tt>\"<tt>>&auml;</tag>"</tt>, foo2 = <tt>"</tt>\\<tt>"</tt> ; <tt>39:</tt> <tt>40:</tt> <span class="roman"><i>/* mymethod */</i></span> <tt>41:</tt> <b>public</b> <b>void</b> mymethod(<b>int</b> i) { <tt>42:</tt> <span class="roman"><i>// just a foo method</i></span> <tt>43:</tt> } <tt>44:</tt> <span class="roman"><i>/* mymethod */</i></span> <tt>45:</tt> <tt>46:</tt> <span class="roman"><i>/* main */</i></span> <tt>47:</tt> <b>public</b> <b>static</b> <b>void</b> main( String args[] ) { <tt>48:</tt> <span class="roman"><i>// just some greetings ;-) /*</i></span> <tt>49:</tt> System.out.println( <tt>"Hello from java2html :-)"</tt> ) ; <tt>50:</tt> System.out.println( <tt>"</tt>\t<tt>by Lorenzo Bettini"</tt> ) ; <tt>51:</tt> System.out.println( <tt>"</tt>\t<tt>http://www.lorenzobettini.it"</tt> ) ; <tt>52:</tt> <b>if</b> (argc > 0) <tt>53:</tt> String param = argc[0]; <tt>54:</tt> <span class="roman"><i>//System.out.println( "bye bye... :-D" ) ; // see you soon</i></span> <tt>55:</tt> } <tt>56:</tt> <span class="roman"><i>/* main */</i></span> <tt>57:</tt> } <tt>58:</tt> <span class="roman"><i>/// class</i></span> <tt>59:</tt> <tt>60:</tt> <span class="roman"><i>// end of file test.java</i></span> </pre></div> <hr> <a name="References"></a> <div class="header"> <p> Next: <a href="#Line-ranges" accesskey="n" rel="next">Line ranges</a>, Previous: <a href="#Simple-example" accesskey="p" rel="prev">Simple example</a>, Up: <a href="#Examples" accesskey="u" rel="up">Examples</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="References-1"></a> <h3 class="section">10.2 References</h3> <p>This example shows the use of <code>--gen-references</code> functionality. In particular, the following output is generated with the command: </p> <div class="example"> <pre class="example">source-highlight -f texinfo -i test.h -o test_ref.h.texinfo -n \ --gen-references=postline </pre></div> <p>and here’s the result (note how the comment line containing the string <code>mysum</code> does not contain references, since it is a <code>comment</code> element, and this element has the option <code>noref</code> in the <samp>texinfo.style</samp>, see <a href="#Output-format-style">Output format style</a>. The same holds for the <code>_TEXTGEN_H</code> comment in the last comment line). </p> <div class="example"> <pre class="example"><tt>01:</tt> <span class="roman"><i>/**</i></span> <tt>02:</tt> <span class="roman"><i>** Copyright (C) 1999-2007 Lorenzo Bettini</i></span> <tt>03:</tt> <span class="roman"><i>** </i></span> <tt>04:</tt> <span class="roman"><i> </i></span><tt>http://www.lorenzobettini.it</tt> <tt>05:</tt> <span class="roman"><i> </i></span> <tt>06:</tt> <span class="roman"><i> r2 = r2 XOR (1<<10);</i></span> <tt>07:</tt> <span class="roman"><i> cout << "hello world" << endl;</i></span> <tt>08:</tt> <span class="roman"><i>** </i></span> <tt>09:</tt> <span class="roman"><i>*/</i></span> <tt>10:</tt> <tt>11:</tt> <span class="roman"><i>// this file also contains the definition of mysum as a #define</i></span> <tt>12:</tt> <tt>13:</tt> <span class="roman"><i>// textgenerator.h : Text Generator class &&</i></span> <tt>14:</tt> <tt>15:</tt> <b>#ifndef</b> _TEXTGEN_H </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a16">_TEXTGEN_H ../../tests/test.h:16</a>.</i></span> </pre><pre class="example"><tt>16:</tt> <b>#define</b> <a name="test_002eh_003a16"></a>_TEXTGEN_H <tt>17:</tt> <tt>18:</tt> <b>#define</b> <a name="test_002eh_003a18"></a>foo(x) (x + 1) <tt>19:</tt> <tt>20:</tt> <b>#define</b> <a name="test_002eh_003a20"></a>mysum myfunbody <tt>21:</tt> <tt>22:</tt> <b>#include</b> <tt><iostream.h></tt> <span class="roman"><i>// for cerr</i></span> <tt>23:</tt> <tt>24:</tt> <b>#include</b> <tt>"genfun.h"</tt> <span class="roman"><i>/* for generating functions */</i></span> <tt>25:</tt> <tt>26:</tt> <b>class</b> <a name="test_002eh_003a26"></a>TextGenerator { <tt>27:</tt> <b>public</b> : <tt>28:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a28"></a>generate( <b>const</b> <b>char</b> *s ) <b>const</b> { (*sout) << s ; } <tt>29:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a29"></a>generate( <b>const</b> <b>char</b> *s, <b>int</b> start, <b>int</b> end ) <b>const</b> <tt>30:</tt> { <tt>31:</tt> <b>for</b> ( <b>int</b> i = start ; i <= end ; ++i ) <tt>32:</tt> (*sout) << s[i] ; <tt>33:</tt> <b>return</b> a<p->b ? a : 3; <tt>34:</tt> } <tt>35:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a35"></a>generateln( <b>const</b> <b>char</b> *s ) <b>const</b> <tt>36:</tt> { <tt>37:</tt> generate( s ) ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a28">generate ../../tests/test.h:28</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a29">generate ../../tests/test.h:29</a>.</i></span> </pre><pre class="example"><tt>38:</tt> (*sout) << endl ; <tt>39:</tt> } <tt>40:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a40"></a>generateEntire( <b>const</b> <b>char</b> *s ) <b>const</b> <tt>41:</tt> { <tt>42:</tt> startTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a46">startTextGeneration ../../tests/test.h:46</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a70">startTextGeneration ../../tests/test.h:70</a>.</i></span> </pre><pre class="example"><tt>43:</tt> generate(s) ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a28">generate ../../tests/test.h:28</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a29">generate ../../tests/test.h:29</a>.</i></span> </pre><pre class="example"><tt>44:</tt> endTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a47">endTextGeneration ../../tests/test.h:47</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a76">endTextGeneration ../../tests/test.h:76</a>.</i></span> </pre><pre class="example"><tt>45:</tt> } <tt>46:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a46"></a>startTextGeneration() <b>const</b> {} <tt>47:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a47"></a>endTextGeneration() <b>const</b> {} <tt>48:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a48"></a>beginText( <b>const</b> <b>char</b> *s ) <b>const</b> <tt>49:</tt> { <tt>50:</tt> startTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a46">startTextGeneration ../../tests/test.h:46</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a70">startTextGeneration ../../tests/test.h:70</a>.</i></span> </pre><pre class="example"><tt>51:</tt> <b>if</b> ( s ) <tt>52:</tt> generate( s ) ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a28">generate ../../tests/test.h:28</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a29">generate ../../tests/test.h:29</a>.</i></span> </pre><pre class="example"><tt>53:</tt> } <tt>54:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a54"></a>endText( <b>const</b> <b>char</b> *s ) <b>const</b> <tt>55:</tt> { <tt>56:</tt> <b>if</b> ( s ) <tt>57:</tt> generate( s ) ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a28">generate ../../tests/test.h:28</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a29">generate ../../tests/test.h:29</a>.</i></span> </pre><pre class="example"><tt>58:</tt> endTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a47">endTextGeneration ../../tests/test.h:47</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a76">endTextGeneration ../../tests/test.h:76</a>.</i></span> </pre><pre class="example"><tt>59:</tt> } <tt>60:</tt> } ; <tt>61:</tt> <tt>62:</tt> <span class="roman"><i>// Decorator</i></span> <tt>63:</tt> <b>class</b> <a name="test_002eh_003a63"></a>TextDecorator : <b>public</b> TextGenerator { </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a26">TextGenerator ../../tests/test.h:26</a>.</i></span> </pre><pre class="example"><tt>64:</tt> <b>protected</b> : <tt>65:</tt> TextGenerator *<a name="test_002eh_003a65"></a>decorated ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a26">TextGenerator ../../tests/test.h:26</a>.</i></span> </pre><pre class="example"><tt>66:</tt> <tt>67:</tt> <b>public</b> : <tt>68:</tt> <a name="test_002eh_003a68"></a>TextDecorator( TextGenerator *t ) : decorated( t ) {} </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a26">TextGenerator ../../tests/test.h:26</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a65">decorated ../../tests/test.h:65</a>.</i></span> </pre><pre class="example"><tt>69:</tt> <tt>70:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a70"></a>startTextGeneration() <b>const</b> <tt>71:</tt> { <tt>72:</tt> startDecorate() ; <tt>73:</tt> <b>if</b> ( decorated ) </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a65">decorated ../../tests/test.h:65</a>.</i></span> </pre><pre class="example"><tt>74:</tt> decorated->startTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a46">startTextGeneration ../../tests/test.h:46</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a65">decorated ../../tests/test.h:65</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a70">startTextGeneration ../../tests/test.h:70</a>.</i></span> </pre><pre class="example"><tt>75:</tt> } <tt>76:</tt> <b>virtual</b> <b>void</b> <a name="test_002eh_003a76"></a>endTextGeneration() <b>const</b> <tt>77:</tt> { <tt>78:</tt> <b>if</b> ( decorated ) </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a65">decorated ../../tests/test.h:65</a>.</i></span> </pre><pre class="example"><tt>79:</tt> decorated->endTextGeneration() ; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a47">endTextGeneration ../../tests/test.h:47</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a65">decorated ../../tests/test.h:65</a>.</i></span> </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a76">endTextGeneration ../../tests/test.h:76</a>.</i></span> </pre><pre class="example"><tt>80:</tt> endDecorate() ; <tt>81:</tt> mysum; </pre><pre class="example"><span class="roman"><i>See <a href="#test_002eh_003a20">mysum ../../tests/test.h:20</a>.</i></span> </pre><pre class="example"><tt>82:</tt> } <tt>83:</tt> <tt>84:</tt> <span class="roman"><i>// pure virtual functions</i></span> <tt>85:</tt> <b>virtual</b> <b>void</b> startDecorate() <b>const</b> = 0 ; <tt>86:</tt> <b>virtual</b> <b>void</b> endDecorate() <b>const</b> = 0 ; <tt>87:</tt> } ; <tt>88:</tt> <tt>89:</tt> <b>#endif</b> <span class="roman"><i>// _TEXTGEN_H</i></span> <tt>90:</tt> </pre></div> <hr> <a name="Line-ranges"></a> <div class="header"> <p> Next: <a href="#Line-ranges-_0028with-context_0029" accesskey="n" rel="next">Line ranges (with context)</a>, Previous: <a href="#References" accesskey="p" rel="prev">References</a>, Up: <a href="#Examples" accesskey="u" rel="up">Examples</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Line-ranges-1"></a> <h3 class="section">10.3 Line ranges</h3> <a name="index-line-ranges-1"></a> <p>This is an example that uses <code>--line-range</code> command line option on the input file shown in See <a href="#Simple-example">Simple example</a>: </p> <div class="example"> <pre class="example">source-highlight -f texinfo -i test.java -n \ --line-range="12-18","29-34" </pre></div> <p>This generates the following output </p> <div class="example"> <pre class="example"><tt>12:</tt> <span class="roman"><i> written by</i></span> <tt>13:</tt> <span class="roman"><i> Lorenzo Bettini</i></span> <tt>14:</tt> <span class="roman"><i> </i></span><tt>http://www.lorenzobettini.it</tt> <tt>15:</tt> <span class="roman"><i> </i></span><tt>http://www.gnu.org/software/src-highlite</tt> <tt>16:</tt> <span class="roman"><i>*/</i></span> <tt>17:</tt> <tt>18:</tt> <b>package</b> hello; <tt>29:</tt> <span class="roman"><i> * </i></span><b>@author</b><span class="roman"><i> Lorenzo Bettini</i></span> <tt>30:</tt> <span class="roman"><i> * </i></span><b>@version</b><span class="roman"><i> 2.0</i></span> <tt>31:</tt> <span class="roman"><i> */</i></span> <span class="roman"><i>/// class</i></span> <tt>32:</tt> <b>public</b> <b>class</b> Hello { <tt>33:</tt> <b>int</b> foo = 1998 ; <tt>34:</tt> <b>int</b> hex_foo = 0xCAFEBABE; </pre></div> <p>Note that, although the specified line ranges span comment environments, the highlighting is respected: the starting of the comment is not printed, but the remaining parts of the comment are correctly highlighted as comment. </p> <hr> <a name="Line-ranges-_0028with-context_0029"></a> <div class="header"> <p> Next: <a href="#Regex-ranges" accesskey="n" rel="next">Regex ranges</a>, Previous: <a href="#Line-ranges" accesskey="p" rel="prev">Line ranges</a>, Up: <a href="#Examples" accesskey="u" rel="up">Examples</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Line-ranges-_0028with-context_0029-1"></a> <h3 class="section">10.4 Line ranges (with context)</h3> <a name="index-line-ranges-2"></a> <a name="index-range-context-1"></a> <a name="index-range-separator-1"></a> <p>This is an example that uses the command line option <code>--line-range</code> together with the <code>--range-context</code> and <code>--range-separator</code>: </p> <div class="example"> <pre class="example">source-highlight -f texinfo -i test.java -n \ --line-range="12-18","29-34" \ --range-context=2 \ --range-separator="{... not in range ...}" </pre></div> <p>This generates the following output </p> <div class="example"> <pre class="example">{... not in range ...} <tt>10:</tt> or type source-highlight --help for the list of options <tt>11:</tt> <tt>12:</tt> <span class="roman"><i> written by</i></span> <tt>13:</tt> <span class="roman"><i> Lorenzo Bettini</i></span> <tt>14:</tt> <span class="roman"><i> </i></span><tt>http://www.lorenzobettini.it</tt> <tt>15:</tt> <span class="roman"><i> </i></span><tt>http://www.gnu.org/software/src-highlite</tt> <tt>16:</tt> <span class="roman"><i>*/</i></span> <tt>17:</tt> <tt>18:</tt> <b>package</b> hello; <tt>19:</tt> <tt>20:</tt> import java.io.* ; {... not in range ...} <tt>27:</tt> * TODO: nothing, just to show an highlighted TODO or FIXME <tt>28:</tt> * <tt>29:</tt> <span class="roman"><i> * </i></span><b>@author</b><span class="roman"><i> Lorenzo Bettini</i></span> <tt>30:</tt> <span class="roman"><i> * </i></span><b>@version</b><span class="roman"><i> 2.0</i></span> <tt>31:</tt> <span class="roman"><i> */</i></span> <span class="roman"><i>/// class</i></span> <tt>32:</tt> <b>public</b> <b>class</b> Hello { <tt>33:</tt> <b>int</b> foo = 1998 ; <tt>34:</tt> <b>int</b> hex_foo = 0xCAFEBABE; <tt>35:</tt> boolean b = false; <tt>36:</tt> Integer i = null ; {... not in range ...} </pre></div> <p>Note the two additional 2 lines before and after the ranges (compare it with the output in <a href="#Line-ranges">Line ranges</a>). Note that the (elements of the) context lines are not highlighted. Moreover, the range separator line <code>"{... not in range ...}"</code> is printed between ranges (the separator string is preformatted automatically, so, e.g., you don’t have to escape special output characters, such as the { } in texinfo output). </p> <hr> <a name="Regex-ranges"></a> <div class="header"> <p> Previous: <a href="#Line-ranges-_0028with-context_0029" accesskey="p" rel="prev">Line ranges (with context)</a>, Up: <a href="#Examples" accesskey="u" rel="up">Examples</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Regex-ranges-1"></a> <h3 class="section">10.5 Regex ranges</h3> <a name="index-regex-ranges-1"></a> <p>Ranges can be expressed also using regular expressions, with the command line option <code>--regex-range</code>. In this case the beginning of the range will be detected by a line containing (in any point) a string matching the specified regular expression; the end will be detected by a line containing a string matching the same regular expression that started the range. This feature is very useful when we want to document some code (e.g., in this very manual) by showing only specific parts, that are delimited in a ad-hoc way in the source code (e.g., with specific comment patterns). </p> <p>For instance, the following output was produced, starting from the source file shown in See <a href="#Simple-example">Simple example</a>, by specifying: </p> <div class="example"> <pre class="example">--regex-range="/// [[:alpha:]]+" </pre></div> <p>Note that the lines containing <code>/// class</code>, which determine the range, are not shown in the output: </p> <div class="example"> <pre class="example"><tt>32:</tt> <b>public</b> <b>class</b> Hello { <tt>33:</tt> <b>int</b> foo = 1998 ; <tt>34:</tt> <b>int</b> hex_foo = 0xCAFEBABE; <tt>35:</tt> <b>boolean</b> b = <b>false</b>; <tt>36:</tt> Integer i = <b>null</b> ; <tt>37:</tt> <b>char</b> c = <tt>'</tt>\'<tt>'</tt>, d = <tt>'n'</tt>, e = <tt>'</tt>\\<tt>'</tt> ; <tt>38:</tt> String xml = <tt>"<tag attr=</tt>\"<tt>value</tt>\"<tt>>&auml;</tag>"</tt>, foo2 = <tt>"</tt>\\<tt>"</tt> ; <tt>39:</tt> <tt>40:</tt> <span class="roman"><i>/* mymethod */</i></span> <tt>41:</tt> <b>public</b> <b>void</b> mymethod(<b>int</b> i) { <tt>42:</tt> <span class="roman"><i>// just a foo method</i></span> <tt>43:</tt> } <tt>44:</tt> <span class="roman"><i>/* mymethod */</i></span> <tt>45:</tt> <tt>46:</tt> <span class="roman"><i>/* main */</i></span> <tt>47:</tt> <b>public</b> <b>static</b> <b>void</b> main( String args[] ) { <tt>48:</tt> <span class="roman"><i>// just some greetings ;-) /*</i></span> <tt>49:</tt> System.out.println( <tt>"Hello from java2html :-)"</tt> ) ; <tt>50:</tt> System.out.println( <tt>"</tt>\t<tt>by Lorenzo Bettini"</tt> ) ; <tt>51:</tt> System.out.println( <tt>"</tt>\t<tt>http://www.lorenzobettini.it"</tt> ) ; <tt>52:</tt> <b>if</b> (argc > 0) <tt>53:</tt> String param = argc[0]; <tt>54:</tt> <span class="roman"><i>//System.out.println( "bye bye... :-D" ) ; // see you soon</i></span> <tt>55:</tt> } <tt>56:</tt> <span class="roman"><i>/* main */</i></span> <tt>57:</tt> } </pre></div> <p>Furthermore, the line numbers are consistent with the lines of the original file. </p> <p>If we want to output only what is included between <code>/* main */</code>, we specify (note that we must escape the special regular expression character <code>*</code>): </p> <div class="example"> <pre class="example">--regex-range="/\* main \*/" </pre></div> <p>and we get: </p> <div class="example"> <pre class="example"><tt>47:</tt> <b>public</b> <b>static</b> <b>void</b> main( String args[] ) { <tt>48:</tt> <span class="roman"><i>// just some greetings ;-) /*</i></span> <tt>49:</tt> System.out.println( <tt>"Hello from java2html :-)"</tt> ) ; <tt>50:</tt> System.out.println( <tt>"</tt>\t<tt>by Lorenzo Bettini"</tt> ) ; <tt>51:</tt> System.out.println( <tt>"</tt>\t<tt>http://www.lorenzobettini.it"</tt> ) ; <tt>52:</tt> <b>if</b> (argc > 0) <tt>53:</tt> String param = argc[0]; <tt>54:</tt> <span class="roman"><i>//System.out.println( "bye bye... :-D" ) ; // see you soon</i></span> <tt>55:</tt> } </pre></div> <p>If we want to show only the methods, which in the source file are delimited by comment lines containing the method’s name, we can specify: </p> <div class="example"> <pre class="example">--regex-range="/\* [[:alpha:]]+ \*/" </pre></div> <div class="example"> <pre class="example"><tt>41:</tt> <b>public</b> <b>void</b> mymethod(<b>int</b> i) { <tt>42:</tt> <span class="roman"><i>// just a foo method</i></span> <tt>43:</tt> } <tt>47:</tt> <b>public</b> <b>static</b> <b>void</b> main( String args[] ) { <tt>48:</tt> <span class="roman"><i>// just some greetings ;-) /*</i></span> <tt>49:</tt> System.out.println( <tt>"Hello from java2html :-)"</tt> ) ; <tt>50:</tt> System.out.println( <tt>"</tt>\t<tt>by Lorenzo Bettini"</tt> ) ; <tt>51:</tt> System.out.println( <tt>"</tt>\t<tt>http://www.lorenzobettini.it"</tt> ) ; <tt>52:</tt> <b>if</b> (argc > 0) <tt>53:</tt> String param = argc[0]; <tt>54:</tt> <span class="roman"><i>//System.out.println( "bye bye... :-D" ) ; // see you soon</i></span> <tt>55:</tt> } </pre></div> <p>In this case, we might have also specified: </p> <div class="example"> <pre class="example">--regex-range="/\* main \*/","/\* mymethod \*/" </pre></div> <p>since <code>--regex-range</code> accepts multiple regular expressions. </p> <p>IMPORTANT: the order of regular expression specification is crucial, since they are tested in the same order they are specified at the command line. </p> <hr> <a name="Problems"></a> <div class="header"> <p> Next: <a href="#Mailing-Lists" accesskey="n" rel="next">Mailing Lists</a>, Previous: <a href="#Examples" accesskey="p" rel="prev">Examples</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Reporting-Bugs"></a> <h2 class="chapter">11 Reporting Bugs</h2> <a name="index-bugs"></a> <a name="index-problems"></a> <p>If you find a bug in <code>source-highlight</code>, please send electronic mail to </p> <p><code>bug-source-highlight at gnu dot org</code> </p> <p>Include the version number, which you can find by running ‘<samp><span class="nolinebreak">source-highlight</span> <span class="nolinebreak">--version</span></samp>’<!-- /@w -->. Also include in your message the output that the program produced and the output you expected. </p> <p>Even better, please file a bug report at Savannah site: </p> <p><a href="https://savannah.gnu.org/bugs/?group=src-highlite">https://savannah.gnu.org/bugs/?group=src-highlite</a> </p> <p>If you have other questions, comments or suggestions about <code>source-highlight</code>, contact the author via electronic mail (find the address at <a href="http://www.lorenzobettini.it">http://www.lorenzobettini.it</a>). The author will try to help you out, although he may not have time to fix your problems. </p> <hr> <a name="Mailing-Lists"></a> <div class="header"> <p> Next: <a href="#Concept-Index" accesskey="n" rel="next">Concept Index</a>, Previous: <a href="#Problems" accesskey="p" rel="prev">Problems</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Mailing-Lists-1"></a> <h2 class="chapter">12 Mailing Lists</h2> <a name="index-mailing-list"></a> <p>The following mailing lists are available: </p> <p><code>help-source-highlight at gnu dot org</code> </p> <p>for generic discussions about the program and for asking for help about it (open mailing list), <a href="http://mail.gnu.org/mailman/listinfo/help-source-highlight">http://mail.gnu.org/mailman/listinfo/help-source-highlight</a> </p> <p><code>info-source-highlight at gnu dot org</code> </p> <p>for receiving information about new releases and features (read-only mailing list), <a href="http://mail.gnu.org/mailman/listinfo/info-source-highlight">http://mail.gnu.org/mailman/listinfo/info-source-highlight</a>. </p> <p>If you want to subscribe to a mailing list just go to the URL and follow the instructions, or send me an e-mail and I’ll subscribe you. </p> <p>I’ll describe new features in new releases also in my blog, at this URL: </p> <p><a href="http://tronprog.blogspot.com/search/label/source-highlight">http://tronprog.blogspot.com/search/label/source-highlight</a> </p> <hr> <a name="Concept-Index"></a> <div class="header"> <p> Previous: <a href="#Mailing-Lists" accesskey="p" rel="prev">Mailing Lists</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <a name="Concept-Index-1"></a> <h2 class="unnumbered">Concept Index</h2> <a name="index-tail-recursion"></a> <table><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Concept-Index_cp_symbol-1"><b>"</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-2"><b>$</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-3"><b>'</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-4"><b>-</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-5"><b>`</b></a> <br> <a class="summary-letter" href="#Concept-Index_cp_letter-A"><b>A</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-B"><b>B</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-C"><b>C</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-D"><b>D</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-E"><b>E</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-F"><b>F</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-G"><b>G</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-H"><b>H</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-I"><b>I</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-J"><b>J</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-K"><b>K</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-L"><b>L</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-M"><b>M</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-N"><b>N</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-O"><b>O</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-P"><b>P</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-Q"><b>Q</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-R"><b>R</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-S"><b>S</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-T"><b>T</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-U"><b>U</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-V"><b>V</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-W"><b>W</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-X"><b>X</b></a> </td></tr></table> <table class="index-cp" border="0"> <tr><td></td><th align="left">Index Entry</th><td> </td><th align="left"> Section</th></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_symbol-1">"</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-_0022expression_0022"><code>"expression"</code></a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_symbol-2">$</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024infile">$infile</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024infilename">$infilename</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024linenum">$linenum</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024outfile">$outfile</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024style">$style</a>:</td><td> </td><td valign="top"><a href="#Colors">Colors</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_0024text">$text</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_symbol-3">'</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-_0027expression_0027"><code>'expression'</code></a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_symbol-4">-</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002ddata_002ddir"><code>--data-dir</code></a>:</td><td> </td><td valign="top"><a href="#The-program-source_002dhighlight_002dsettings">The program source-highlight-settings</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002ddata_002ddir-1"><code>--data-dir</code></a>:</td><td> </td><td valign="top"><a href="#Configuration-files">Configuration files</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002ddata_002ddir-2"><code>--data-dir</code></a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dinfer_002dlang"><code>--infer-lang</code></a>:</td><td> </td><td valign="top"><a href="#Perl">Perl</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dinfer_002dlang-1"><code>--infer-lang</code></a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dinfer_002dlang-2"><code>--infer-lang</code></a>:</td><td> </td><td valign="top"><a href="#How-the-input-language-is-discovered">How the input language is discovered</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dshow_002dlang_002delements"><code>--show-lang-elements</code></a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dshow_002dlang_002delements-1"><code>--show-lang-elements</code></a>:</td><td> </td><td valign="top"><a href="#Listing-Language-Elements">Listing Language Elements</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dstyle_002dcss_002dfile"><code>--style-css-file</code></a>:</td><td> </td><td valign="top"><a href="#Output-format-style-using-CSS">Output format style using CSS</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dstyle_002dfile"><code>--style-file</code></a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-_002d_002dwith_002ddoxygen"><code>--with-doxygen</code></a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_symbol-5">`</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-_0060expression_0060"><code>`expression`</code></a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-A">A</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-anchor">anchor</a>:</td><td> </td><td valign="top"><a href="#Generating-References">Generating References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-ANSI-color">ANSI color</a>:</td><td> </td><td valign="top"><a href="#ANSI-color-escape-sequences">ANSI color escape sequences</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Apache">Apache</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-autoconf">autoconf</a>:</td><td> </td><td valign="top"><a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a></td></tr> <tr><td></td><td valign="top"><a href="#index-autoconf-1">autoconf</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-automake">automake</a>:</td><td> </td><td valign="top"><a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a></td></tr> <tr><td></td><td valign="top"><a href="#index-automake-1">automake</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-B">B</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-background-color">background color</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-background-color-1">background color</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-background-color-2">background color</a>:</td><td> </td><td valign="top"><a href="#Colors">Colors</a></td></tr> <tr><td></td><td valign="top"><a href="#index-backreference">backreference</a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-backreference-1">backreference</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-backtick">backtick</a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-bash-completion">bash completion</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-bgcolor"><code>bgcolor</code></a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-bold">bold</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-bold-1">bold</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td></td><td valign="top"><a href="#index-boost">boost</a>:</td><td> </td><td valign="top"><a href="#Building-with-qmake">Building with qmake</a></td></tr> <tr><td></td><td valign="top"><a href="#index-boost-1">boost</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Boost-regex">Boost regex</a>:</td><td> </td><td valign="top"><a href="#Tips-on-installing-Boost-Regex-library">Tips on installing Boost Regex library</a></td></tr> <tr><td></td><td valign="top"><a href="#index-bugs">bugs</a>:</td><td> </td><td valign="top"><a href="#Problems">Problems</a></td></tr> <tr><td></td><td valign="top"><a href="#index-building-requirements">building requirements</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-C">C</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-CGI">CGI</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-as-a-CGI">Using source-highlight as a CGI</a></td></tr> <tr><td></td><td valign="top"><a href="#index-check_002dregexp"><code>check-regexp</code></a>:</td><td> </td><td valign="top"><a href="#The-program-check_002dregexp">The program check-regexp</a></td></tr> <tr><td></td><td valign="top"><a href="#index-code2blog">code2blog</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-color">color</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-color-1">color</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-colors">colors</a>:</td><td> </td><td valign="top"><a href="#Colors">Colors</a></td></tr> <tr><td></td><td valign="top"><a href="#index-compilation">compilation</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-compilation-requirements">compilation requirements</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-conditional-expressions">conditional expressions</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-configuration-files">configuration files</a>:</td><td> </td><td valign="top"><a href="#Configuration-files">Configuration files</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Copying-conditions">Copying conditions</a>:</td><td> </td><td valign="top"><a href="#Copying">Copying</a></td></tr> <tr><td></td><td valign="top"><a href="#index-cpp2html">cpp2html</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-CSS">CSS</a>:</td><td> </td><td valign="top"><a href="#Output-format-style-using-CSS">Output format style using CSS</a></td></tr> <tr><td></td><td valign="top"><a href="#index-ctags">ctags</a>:</td><td> </td><td valign="top"><a href="#Generating-References">Generating References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-CXXFLAGS"><code>CXXFLAGS</code></a>:</td><td> </td><td valign="top"><a href="#Tips-on-installing-Boost-Regex-library">Tips on installing Boost Regex library</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-D">D</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-debug">debug</a>:</td><td> </td><td valign="top"><a href="#Debugging">Debugging</a></td></tr> <tr><td></td><td valign="top"><a href="#index-default_002elang">default.lang</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-as-a-simple-formatter">Using source-highlight as a simple formatter</a></td></tr> <tr><td></td><td valign="top"><a href="#index-default_002elang-1">default.lang</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-default_002estyle">default.style</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-definition-order">definition order</a>:</td><td> </td><td valign="top"><a href="#Order-of-definitions">Order of definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-delimited-definitions">delimited definitions</a>:</td><td> </td><td valign="top"><a href="#Delimited-definitions">Delimited definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-direct-color-scheme">direct color scheme</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-directories">directories</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-DocBook">DocBook</a>:</td><td> </td><td valign="top"><a href="#DocBook-output">DocBook output</a></td></tr> <tr><td></td><td valign="top"><a href="#index-doctemplate">doctemplate</a>:</td><td> </td><td valign="top"><a href="#Document-template">Document template</a></td></tr> <tr><td></td><td valign="top"><a href="#index-download">download</a>:</td><td> </td><td valign="top"><a href="#Download">Download</a></td></tr> <tr><td></td><td valign="top"><a href="#index-doxygen">doxygen</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-dynamic-backreference">dynamic backreference</a>:</td><td> </td><td valign="top"><a href="#Dynamic-Backreferences">Dynamic Backreferences</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-E">E</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-environments">environments</a>:</td><td> </td><td valign="top"><a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-F">F</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-failsafe">failsafe</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-as-a-simple-formatter">Using source-highlight as a simple formatter</a></td></tr> <tr><td></td><td valign="top"><a href="#index-failsafe-1">failsafe</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-features">features</a>:</td><td> </td><td valign="top"><a href="#Introduction">Introduction</a></td></tr> <tr><td></td><td valign="top"><a href="#index-file-inclusion">file inclusion</a>:</td><td> </td><td valign="top"><a href="#File-inclusion">File inclusion</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Firefox">Firefox</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-fixed">fixed</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-fixed-1">fixed</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Fortran">Fortran</a>:</td><td> </td><td valign="top"><a href="#Fortran">Fortran</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-G">G</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-getting-help">getting help</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Git">Git</a>:</td><td> </td><td valign="top"><a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a></td></tr> <tr><td></td><td valign="top"><a href="#index-gnulib">gnulib</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-H">H</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-help">help</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-HTML">HTML</a>:</td><td> </td><td valign="top"><a href="#HTML-and-XHTML-output">HTML and XHTML output</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-I">I</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-Ikiwiki">Ikiwiki</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-inline_005freference">inline_reference</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-installation">installation</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-introduction">introduction</a>:</td><td> </td><td valign="top"><a href="#Introduction">Introduction</a></td></tr> <tr><td></td><td valign="top"><a href="#index-invoking">invoking</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-italics">italics</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-italics-1">italics</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-J">J</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-java2html">java2html</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-java2html-1">java2html</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-K">K</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-KDE">KDE</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-KDE-1">KDE</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Ksrc2highlight">Ksrc2highlight</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-L">L</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-language-definition">language definition</a>:</td><td> </td><td valign="top"><a href="#Language-Definitions">Language Definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-language-inference">language inference</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-language-map">language map</a>:</td><td> </td><td valign="top"><a href="#Language-map">Language map</a></td></tr> <tr><td></td><td valign="top"><a href="#index-LaTeX">LaTeX</a>:</td><td> </td><td valign="top"><a href="#LaTeX-output">LaTeX output</a></td></tr> <tr><td></td><td valign="top"><a href="#index-LDFLAGS"><code>LDFLAGS</code></a>:</td><td> </td><td valign="top"><a href="#Tips-on-installing-Boost-Regex-library">Tips on installing Boost Regex library</a></td></tr> <tr><td></td><td valign="top"><a href="#index-library">library</a>:</td><td> </td><td valign="top"><a href="#Introduction">Introduction</a></td></tr> <tr><td></td><td valign="top"><a href="#index-library-1">library</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-libtool">libtool</a>:</td><td> </td><td valign="top"><a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a></td></tr> <tr><td></td><td valign="top"><a href="#index-libtool-1">libtool</a>:</td><td> </td><td valign="top"><a href="#What-you-need-to-build-source_002dhighlight">What you need to build source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-line-ranges">line ranges</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-line-ranges-1">line ranges</a>:</td><td> </td><td valign="top"><a href="#Line-ranges">Line ranges</a></td></tr> <tr><td></td><td valign="top"><a href="#index-line-ranges-2">line ranges</a>:</td><td> </td><td valign="top"><a href="#Line-ranges-_0028with-context_0029">Line ranges (with context)</a></td></tr> <tr><td></td><td valign="top"><a href="#index-lines">lines</a>:</td><td> </td><td valign="top"><a href="#Line-wide-definitions">Line wide definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-lookahead-asserts">lookahead asserts</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-lookbehind-asserts">lookbehind asserts</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-M">M</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-mailing-list">mailing list</a>:</td><td> </td><td valign="top"><a href="#Mailing-Lists">Mailing Lists</a></td></tr> <tr><td></td><td valign="top"><a href="#index-marked-subexpressions">marked subexpressions</a>:</td><td> </td><td valign="top"><a href="#Ways-of-specifying-regular-expressions">Ways of specifying regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-marked-subexpressions-1">marked subexpressions</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-matching-strategy">matching strategy</a>:</td><td> </td><td valign="top"><a href="#How-source_002dhighlight-works">How source-highlight works</a></td></tr> <tr><td></td><td valign="top"><a href="#index-MinGW">MinGW</a>:</td><td> </td><td valign="top"><a href="#Building-with-qmake">Building with qmake</a></td></tr> <tr><td></td><td valign="top"><a href="#index-MSVC">MSVC</a>:</td><td> </td><td valign="top"><a href="#Building-with-qmake">Building with qmake</a></td></tr> <tr><td></td><td valign="top"><a href="#index-msys">msys</a>:</td><td> </td><td valign="top"><a href="#Building-with-qmake">Building with qmake</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-N">N</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-nodoctemplate">nodoctemplate</a>:</td><td> </td><td valign="top"><a href="#Document-template">Document template</a></td></tr> <tr><td></td><td valign="top"><a href="#index-nohilite_002elang">nohilite.lang</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-as-a-simple-formatter">Using source-highlight as a simple formatter</a></td></tr> <tr><td></td><td valign="top"><a href="#index-non_002dmarking-parenthesis">non-marking parenthesis</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-nonsensitive">nonsensitive</a>:</td><td> </td><td valign="top"><a href="#Simple-definitions">Simple definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-noref">noref</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-notfixed">notfixed</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-notfixed-1">notfixed</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-O">O</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-one-style">one style</a>:</td><td> </td><td valign="top"><a href="#One-style">One style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-options">options</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-output-language-definition">output language definition</a>:</td><td> </td><td valign="top"><a href="#Output-Language-Definitions">Output Language Definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-output-language-map">output language map</a>:</td><td> </td><td valign="top"><a href="#Output-Language-map">Output Language map</a></td></tr> <tr><td></td><td valign="top"><a href="#index-output-style">output style</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-P">P</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-Pastebin">Pastebin</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-patching">patching</a>:</td><td> </td><td valign="top"><a href="#Patching-from-a-previous-version">Patching from a previous version</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Perl">Perl</a>:</td><td> </td><td valign="top"><a href="#Perl">Perl</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Perl-1">Perl</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Php">Php</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-postdoc_005freference">postdoc_reference</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-postline_005freference">postline_reference</a>:</td><td> </td><td valign="top"><a href="#Anchors-and-References">Anchors and References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-prefix">prefix</a>:</td><td> </td><td valign="top"><a href="#How-source_002dhighlight-works">How source-highlight works</a></td></tr> <tr><td></td><td valign="top"><a href="#index-problems">problems</a>:</td><td> </td><td valign="top"><a href="#Problems">Problems</a></td></tr> <tr><td></td><td valign="top"><a href="#index-PyQt">PyQt</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Python">Python</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-Q">Q</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-qmake">qmake</a>:</td><td> </td><td valign="top"><a href="#Building-with-qmake">Building with qmake</a></td></tr> <tr><td></td><td valign="top"><a href="#index-QSource_002dHighlight">QSource-Highlight</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Qt">Qt</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Qt-1">Qt</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-R">R</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-range-context">range context</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-range-context-1">range context</a>:</td><td> </td><td valign="top"><a href="#Line-ranges-_0028with-context_0029">Line ranges (with context)</a></td></tr> <tr><td></td><td valign="top"><a href="#index-range-separator">range separator</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-range-separator-1">range separator</a>:</td><td> </td><td valign="top"><a href="#Line-ranges-_0028with-context_0029">Line ranges (with context)</a></td></tr> <tr><td></td><td valign="top"><a href="#index-RapidWeaver">RapidWeaver</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-redef">redef</a>:</td><td> </td><td valign="top"><a href="#Redefinitions-and-Substitutions">Redefinitions and Substitutions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-reference">reference</a>:</td><td> </td><td valign="top"><a href="#Generating-References">Generating References</a></td></tr> <tr><td></td><td valign="top"><a href="#index-regex-ranges">regex ranges</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td></td><td valign="top"><a href="#index-regex-ranges-1">regex ranges</a>:</td><td> </td><td valign="top"><a href="#Regex-ranges">Regex ranges</a></td></tr> <tr><td></td><td valign="top"><a href="#index-regular-expressions">regular expressions</a>:</td><td> </td><td valign="top"><a href="#Notes-on-regular-expressions">Notes on regular expressions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-rpm">rpm</a>:</td><td> </td><td valign="top"><a href="#Building-_002erpm">Building .rpm</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-S">S</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-sample">sample</a>:</td><td> </td><td valign="top"><a href="#Simple-Usage">Simple Usage</a></td></tr> <tr><td></td><td valign="top"><a href="#index-shadow-build">shadow build</a>:</td><td> </td><td valign="top"><a href="#Installation">Installation</a></td></tr> <tr><td></td><td valign="top"><a href="#index-shadow-build-1">shadow build</a>:</td><td> </td><td valign="top"><a href="#Anonymous-Git-Checkout">Anonymous Git Checkout</a></td></tr> <tr><td></td><td valign="top"><a href="#index-SHJS">SHJS</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-simple-language-definition">simple language definition</a>:</td><td> </td><td valign="top"><a href="#Simple-definitions">Simple definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-SIP">SIP</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-source_002dhighlight_002desc_002esh">source-highlight-esc.sh</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-with-less">Using source-highlight with less</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Source_002dHighlight_002dQt">Source-Highlight-Qt</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-source_002dhighlight_002dsettings">source-highlight-settings</a>:</td><td> </td><td valign="top"><a href="#The-program-source_002dhighlight_002dsettings">The program source-highlight-settings</a></td></tr> <tr><td></td><td valign="top"><a href="#index-source_002dhighlight_002econf">source-highlight.conf</a>:</td><td> </td><td valign="top"><a href="#The-program-source_002dhighlight_002dsettings">The program source-highlight-settings</a></td></tr> <tr><td></td><td valign="top"><a href="#index-SourceHighlightIDE">SourceHighlightIDE</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-SOURCE_005fHIGHLIGHT_005fDATADIR"><code>SOURCE_HIGHLIGHT_DATADIR</code></a>:</td><td> </td><td valign="top"><a href="#The-program-source_002dhighlight_002dsettings">The program source-highlight-settings</a></td></tr> <tr><td></td><td valign="top"><a href="#index-SOURCE_005fHIGHLIGHT_005fDATADIR-1"><code>SOURCE_HIGHLIGHT_DATADIR</code></a>:</td><td> </td><td valign="top"><a href="#Configuration-files">Configuration files</a></td></tr> <tr><td></td><td valign="top"><a href="#index-src_002dhilite_002dlesspipe_002esh">src-hilite-lesspipe.sh</a>:</td><td> </td><td valign="top"><a href="#Using-source_002dhighlight-with-less">Using source-highlight with less</a></td></tr> <tr><td></td><td valign="top"><a href="#index-states">states</a>:</td><td> </td><td valign="top"><a href="#State_002fEnvironment-Definitions">State/Environment Definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-style-separator">style separator</a>:</td><td> </td><td valign="top"><a href="#Style-template">Style template</a></td></tr> <tr><td></td><td valign="top"><a href="#index-style-template">style template</a>:</td><td> </td><td valign="top"><a href="#Style-template">Style template</a></td></tr> <tr><td></td><td valign="top"><a href="#index-style_002edefaults">style.defaults</a>:</td><td> </td><td valign="top"><a href="#Default-Styles">Default Styles</a></td></tr> <tr><td></td><td valign="top"><a href="#index-subst">subst</a>:</td><td> </td><td valign="top"><a href="#Redefinitions-and-Substitutions">Redefinitions and Substitutions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-suffix">suffix</a>:</td><td> </td><td valign="top"><a href="#How-source_002dhighlight-works">How source-highlight works</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-T">T</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-tail-recursion">tail recursion</a>:</td><td> </td><td valign="top"><a href="#Concept-Index">Concept Index</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Texinfo">Texinfo</a>:</td><td> </td><td valign="top"><a href="#Texinfo-output">Texinfo output</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-U">U</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-underline">underline</a>:</td><td> </td><td valign="top"><a href="#Output-format-style">Output format style</a></td></tr> <tr><td></td><td valign="top"><a href="#index-underline-1">underline</a>:</td><td> </td><td valign="top"><a href="#Text-styles">Text styles</a></td></tr> <tr><td></td><td valign="top"><a href="#index-usage">usage</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-V">V</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-variables">variables</a>:</td><td> </td><td valign="top"><a href="#Variable-definitions">Variable definitions</a></td></tr> <tr><td></td><td valign="top"><a href="#index-version">version</a>:</td><td> </td><td valign="top"><a href="#Invoking-source_002dhighlight">Invoking source-highlight</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-W">W</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-Wiki">Wiki</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td></td><td valign="top"><a href="#index-Wiki-1">Wiki</a>:</td><td> </td><td valign="top"><a href="#Related-Software-and-Links">Related Software and Links</a></td></tr> <tr><td colspan="4"> <hr></td></tr> <tr><th><a name="Concept-Index_cp_letter-X">X</a></th><td></td><td></td></tr> <tr><td></td><td valign="top"><a href="#index-XHTML">XHTML</a>:</td><td> </td><td valign="top"><a href="#HTML-and-XHTML-output">HTML and XHTML output</a></td></tr> <tr><td colspan="4"> <hr></td></tr> </table> <table><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Concept-Index_cp_symbol-1"><b>"</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-2"><b>$</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-3"><b>'</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-4"><b>-</b></a> <a class="summary-letter" href="#Concept-Index_cp_symbol-5"><b>`</b></a> <br> <a class="summary-letter" href="#Concept-Index_cp_letter-A"><b>A</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-B"><b>B</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-C"><b>C</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-D"><b>D</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-E"><b>E</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-F"><b>F</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-G"><b>G</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-H"><b>H</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-I"><b>I</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-J"><b>J</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-K"><b>K</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-L"><b>L</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-M"><b>M</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-N"><b>N</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-O"><b>O</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-P"><b>P</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-Q"><b>Q</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-R"><b>R</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-S"><b>S</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-T"><b>T</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-U"><b>U</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-V"><b>V</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-W"><b>W</b></a> <a class="summary-letter" href="#Concept-Index_cp_letter-X"><b>X</b></a> </td></tr></table> <a name="SEC_Overview"></a> <h2 class="shortcontents-heading">Short Table of Contents</h2> <div class="shortcontents"> <ul class="no-bullet"> <li><a name="stoc-Introduction-1" href="#toc-Introduction-1">1 Introduction</a></li> <li><a name="stoc-Installation-1" href="#toc-Installation-1">2 Installation</a></li> <li><a name="stoc-Copying-Conditions" href="#toc-Copying-Conditions">3 Copying Conditions</a></li> <li><a name="stoc-Simple-Usage-1" href="#toc-Simple-Usage-1">4 Simple Usage</a></li> <li><a name="stoc-Configuration-files-1" href="#toc-Configuration-files-1">5 Configuration files</a></li> <li><a name="stoc-Invoking-source_002dhighlight-1" href="#toc-Invoking-source_002dhighlight-1">6 Invoking <code>source-highlight</code></a></li> <li><a name="stoc-Language-Definitions-1" href="#toc-Language-Definitions-1">7 Language Definitions</a></li> <li><a name="stoc-Output-Language-Definitions-1" href="#toc-Output-Language-Definitions-1">8 Output Language Definitions</a></li> <li><a name="stoc-Generating-References-1" href="#toc-Generating-References-1">9 Generating References</a></li> <li><a name="stoc-Examples-1" href="#toc-Examples-1">10 Examples</a></li> <li><a name="stoc-Reporting-Bugs" href="#toc-Reporting-Bugs">11 Reporting Bugs</a></li> <li><a name="stoc-Mailing-Lists-1" href="#toc-Mailing-Lists-1">12 Mailing Lists</a></li> <li><a name="stoc-Concept-Index-1" href="#toc-Concept-Index-1">Concept Index</a></li> </ul> </div> <div class="footnote"> <hr> <h4 class="footnotes-heading">Footnotes</h4> <h3><a name="FOOT1" href="#DOCF1">(1)</a></h3> <p>Up to version 2.9, there were also the suffixes <code>-doc</code> and <code>-css-doc</code>, but this mechanism was quite confusing and complex; hopefully, this new one should be better.</p> <h3><a name="FOOT2" href="#DOCF2">(2)</a></h3> <p>Although this might have been achieved with previous version, it is an official supported feature since version 2.5.</p> <h3><a name="FOOT3" href="#DOCF3">(3)</a></h3> <p>Since version 3.1.2 of Source-highlight the CVS repository was dismissed in favor of Git (<a href="http://git-scm.com/">http://git-scm.com/</a>).</p> <h3><a name="FOOT4" href="#DOCF4">(4)</a></h3> <p><a href="http://www.gnu.org/software/autoconf">http://www.gnu.org/software/autoconf</a></p> <h3><a name="FOOT5" href="#DOCF5">(5)</a></h3> <p><a href="http://www.gnu.org/software/automake">http://www.gnu.org/software/automake</a></p> <h3><a name="FOOT6" href="#DOCF6">(6)</a></h3> <p><a href="http://www.gnu.org/software/libtool">http://www.gnu.org/software/libtool</a></p> <h3><a name="FOOT7" href="#DOCF7">(7)</a></h3> <p><a href="http://www.gnu.org/software/gnulib">http://www.gnu.org/software/gnulib</a></p> <h3><a name="FOOT8" href="#DOCF8">(8)</a></h3> <p>Since version 2.11, the <code>configure</code> script should be able to correctly find the boost regex library if it is in the compiler default path.</p> <h3><a name="FOOT9" href="#DOCF9">(9)</a></h3> <p>Command lines that are too long are split into multiple indented lines separated by a <code>\</code>. Of course these commands are to be given in one line only, anyway.</p> <h3><a name="FOOT10" href="#DOCF10">(10)</a></h3> <p>Command lines that are too long are split into multiple indented lines separated by a <code>\</code>. Of course these commands are to be given in one line only, anyway.</p> <h3><a name="FOOT11" href="#DOCF11">(11)</a></h3> <p>Before version 2.1, this file was called <samp>tags.j2h</samp> which used to be a very obscure name. I hope this name convention is a better one :-).</p> <h3><a name="FOOT12" href="#DOCF12">(12)</a></h3> <p>Since version 2.6.</p> <h3><a name="FOOT13" href="#DOCF13">(13)</a></h3> <p>Before version 2.1, this command line option was called <code>--tags-file</code> which used to be a very obscure name. I hope this name convention is a better one :-).</p> <h3><a name="FOOT14" href="#DOCF14">(14)</a></h3> <p>Since version 2.6.</p> <h3><a name="FOOT15" href="#DOCF15">(15)</a></h3> <p>Of course, if you use HTML and an external CSS file you will achieve the same result.</p> <h3><a name="FOOT16" href="#DOCF16">(16)</a></h3> <p>You can see these colors in HTML in the file <samp>colors.html</samp>.</p> <h3><a name="FOOT17" href="#DOCF17">(17)</a></h3> <p>Note that, since version 2.2, you must use double quotes.</p> <h3><a name="FOOT18" href="#DOCF18">(18)</a></h3> <p>Since version 2.6.</p> <h3><a name="FOOT19" href="#DOCF19">(19)</a></h3> <p>Since version 2.9.</p> <h3><a name="FOOT20" href="#DOCF20">(20)</a></h3> <p>This is the main difference introduced in version 2.0 with respect the previous version.</p> <h3><a name="FOOT21" href="#DOCF21">(21)</a></h3> <p>This is the main difference introduced in version 2.1 with respect the the previous version.</p> <h3><a name="FOOT22" href="#DOCF22">(22)</a></h3> <p>As explained before, originally Source-highlight was thought mainly for generating HTML output, this is why the term <em>css</em> is used for style sheets.</p> <h3><a name="FOOT23" href="#DOCF23">(23)</a></h3> <p>Padding character can be specified since version 2.8.</p> <h3><a name="FOOT24" href="#DOCF24">(24)</a></h3> <p>Since version 2.7.</p> <h3><a name="FOOT25" href="#DOCF25">(25)</a></h3> <p>Since version 3.1.2.</p> <h3><a name="FOOT26" href="#DOCF26">(26)</a></h3> <p>Since version 2.7.</p> <h3><a name="FOOT27" href="#DOCF27">(27)</a></h3> <p>This issue concerning Perl regular expression syntax was raised by Elias Pipping, and this also pushed me to deal with this more powerful syntax that permits using backreferences, for instance. Although we’re still far from highlighting Perl syntax completely (<a href="#Perl">Perl</a>), I definitely must thank Elias for his precious information about this matter :-)</p> <h3><a name="FOOT28" href="#DOCF28">(28)</a></h3> <p>As Ed Kelly correctly pointed out, C-style comments are NOT nested; it’s a big shame I’ve been using C++ and Java for years and have always thought they were nested :-)... Thus, in previous versions of source-highlight distributions, C-style comments were (uncorrectly) defined as nested. Thank you Ed, for your feedback!</p> <h3><a name="FOOT29" href="#DOCF29">(29)</a></h3> <p>Since version 2.8</p> <h3><a name="FOOT30" href="#DOCF30">(30)</a></h3> <p>I’m grateful to Jurgen Hotzel for rising this issue about Lua comments; this led me to introduce dynamic backreferences.</p> <h3><a name="FOOT31" href="#DOCF31">(31)</a></h3> <p>At least, to the best of my knowledge :-)</p> <h3><a name="FOOT32" href="#DOCF32">(32)</a></h3> <p>The strategy used by source-highlight for matching regular expressions changed since version 2.11 (and in version 2.10 the strategy used was not completely conceptually correct and it had a lot of overhead).</p> <h3><a name="FOOT33" href="#DOCF33">(33)</a></h3> <p>according to the terminology of regular expressions.</p> <h3><a name="FOOT34" href="#DOCF34">(34)</a></h3> <p><a href="http://www.boost.org/libs/regex/doc/syntax.html">http://www.boost.org/libs/regex/doc/syntax.html</a></p> <h3><a name="FOOT35" href="#DOCF35">(35)</a></h3> <p>the index only, without the escape character.</p> <h3><a name="FOOT36" href="#DOCF36">(36)</a></h3> <p>This expression was provided by John Maddock, the author of the Boost regex library, as a solution of a problem I posted on the boost list, </p> <p><a href="http://thread.gmane.org/gmane.comp.lib.boost.devel/158237/focus=158276">http://thread.gmane.org/gmane.comp.lib.boost.devel/158237/focus=158276</a></p> <h3><a name="FOOT37" href="#DOCF37">(37)</a></h3> <p>Since version 2.4.</p> <h3><a name="FOOT38" href="#DOCF38">(38)</a></h3> <p>Up to version 2.9 the output of <code>--show-regex</code> was a little bit more complex to read; hopefully this output is better.</p> <h3><a name="FOOT39" href="#DOCF39">(39)</a></h3> <p>Please note that this concept of state is different from the concept of “state” of an automaton.</p> <h3><a name="FOOT40" href="#DOCF40">(40)</a></h3> <p>As a future extension we might think of providing a way, in the language definition syntax, to define a state/environment that extends the outer contexts instead of overriding them.</p> <h3><a name="FOOT41" href="#DOCF41">(41)</a></h3> <p>This was not tested extensively and might not catch all the correct situations.</p> <h3><a name="FOOT42" href="#DOCF42">(42)</a></h3> <p>OK, there are no templates in C, and they are only in C++, but we think it should no harm when highlighting C files.</p> <h3><a name="FOOT43" href="#DOCF43">(43)</a></h3> <p>Before version 2.9, there was only <samp>cpp.lang</samp> which was used both for C and C++; however, this way, if you had a C program where you were using a C++ keyword as a variable name—which of course is correct in C—that variable was actually highlighted as a keyword and this was not correct.</p> <h3><a name="FOOT44" href="#DOCF44">(44)</a></h3> <p>Since version 2.6.</p> <h3><a name="FOOT45" href="#DOCF45">(45)</a></h3> <p>This is a sort of trick to insert spaces at the beginning of a line without using a tabular environment; without the leading <code>\mbox{}</code> these spaces would be ignored. This is the only way I found to achieve this, if you have suggestions, please let me know!</p> <h3><a name="FOOT46" href="#DOCF46">(46)</a></h3> <p>Since version 2.4.</p> <h3><a name="FOOT47" href="#DOCF47">(47)</a></h3> <p>Unless they are inside a <code><tt>...</tt></code>.</p> <h3><a name="FOOT48" href="#DOCF48">(48)</a></h3> <p>Up to version 2.9, there was only <code>doctemplate</code> and for <code>--doc</code> there was a separate <code>.outlang</code> file; I think the present solution is better and reduces the number of files.</p> <h3><a name="FOOT49" href="#DOCF49">(49)</a></h3> <p>Since version 2.6.</p> <h3><a name="FOOT50" href="#DOCF50">(50)</a></h3> <p>Although I haven’t tested it, I think this will work also for Doxygen comments.</p> <h3><a name="FOOT51" href="#DOCF51">(51)</a></h3> <p>This description is taken from the ctags man page</p> </div> <hr> </body> </html>