190720.1 · 1deb35410332359c5e8154136933746fdf98d19a
added AddPersistentState calls to markdown.lang; README update
reading declarations
@@ -10,6 +10,7 @@ 19.07.2019 + - fixed out-of-range exception with repeated `AddKeyword` calls - added `Priority` and `Constraints` elements to syntax regex definitions - added Lua function `AddPersistentState` - renamed md.lang to markdown.lang
@@ -187,7 +187,7 @@ General options: --config-file=<file> set path to a lang or theme file -d, --outdir=<directory> name of output directory -h, --help[=topic] print this help or a topic description- <topic> = [syntax, theme, plugin, config]+ <topic> = [syntax, theme, plugin, config, test] -i, --input=<file> name of single input file -o, --output=<file> name of single output file -P, --progress print progress bar in batch mode@@ -201,6 +201,8 @@ General options: <type> = [langs, themes, plugins] --list-cat=<categories> filter the scripts by the given categories (example: --list-cat='source;script')+ --max-size=<size> set maximum input file size+ (examples: 512M, 1G; default: 256M) --plug-in=<script> execute Lua plug-in script; repeat option to execute multiple plug-ins --plug-in-param=<value> set plug-in input parameter@@ -226,17 +228,21 @@ Output formatting options: use a plug-in file instead -f, --fragment omit document header and footer -F, --reformat=<style> reformats and indents output in given style- <style> = [allman, banner, gnu,- horstmann, java, kr, linux, mozilla, otbs, vtk,- stroustrup, whitesmith, google, pico, lisp]+ <style> = [allman, gnu, google, horstmann,+ java, kr, linux, lisp, mozilla, otbs, pico,+ vtk, ratliff, stroustrup, webkit, whitesmith, user]+ The user style does not apply a predefined scheme.+ Use --reformat-option to define the reformatting.+ --reformat-option=<opt> apply an astyle cmd line option (assumes -F) -I, --include-style include style definition in output file -J, --line-length=<num> line length before wrapping (see -V, -W) -j, --line-number-length=<num> line number width incl. left padding (default: 5)+ --line-range=<start-end> output only lines from number <start> to <end> -k, --font=<font> set font (specific to output format) -K, --font-size=<num?> set font size (specific to output format) -l, --line-numbers print line numbers in output file -m, --line-number-start=<cnt> start line numbering with cnt (assumes -l)- -s, --style=<style> set colour style (theme). See --base16+ -s, --style=<style> set colour style (theme). See --base16 -t, --replace-tabs=<num> replace tabs by <num> spaces -T, --doc-title=<title> document title -u, --encoding=<enc> set output encoding which matches input file@@ -247,7 +253,7 @@ Output formatting options: --wrap-no-numbers omit line numbers of wrapped lines (assumes -l) -z, --zeroes pad line numbers with 0's- --base16 use a theme of the Base16 collection+ --base16[=theme] use a theme of the Base16 collection --delim-cr set CR as end-of-line delimiter (MacOS 9) --isolate output each syntax token separately (verbose output) --keep-injections output plug-in injections in spite of -f@@ -255,6 +261,8 @@ Output formatting options: <case> = [upper, lower, capitalize] --no-trailing-nl omit trailing newline --no-version-info omit version info comment+ --two-pass=<file> write plug-in with persistent state information+ (beta; requires syntax with store instructions) (X)HTML output options:@@ -267,7 +275,7 @@ Output formatting options: --class-name=<name> set CSS class name prefix; omit class name if set to NONE --inline-css output CSS within each tag (verbose output)- --enclose-pre enclose fragmented output with pre tag+ --enclose-pre enclose fragmented output with pre tag (assumes -f) @@ -282,7 +290,7 @@ LaTeX output options: RTF output options: --page-color include page color attributes- -x, --page-size=<ps> set page size+ -x, --page-size=<ps> set page size <ps> = [a3, a4, a5, b4, b5, b6, letter] --char-styles include character stylesheets @@ -293,6 +301,11 @@ SVG output options: --width set image width (see --height) +Terminal escape output options (xterm256 or truecolor):++ --canvas[=width] set background colour padding (default: 80)++ GNU source-highlight compatibility options: --doc create stand alone document@@ -538,16 +551,24 @@ If there exist multiple suffixes, list them in {filetypes_conf}. ==== Syntax elements ................................................................................-Keywords = { Id, List|Regex, Group? }-- Id: Integer, keyword group id (values 1-4, can be reused for several keyword- groups)- List: List, list of keywords- Regex: String, regular expression- Group: Integer, capturing group id of regular expression, defines part of regex- which should be returned as keyword (optional; if not set, the match- with the highest group number is returned (counts from left to right))-+Keywords = { Id, List|Regex, Group?, Priority?, Constraints? }++ Id: Integer, keyword group id (can be reused for several groups).+ Default themes support 4 and base16 themes 6 groups.+ List: List, list of keywords+ Regex: String, regular expression+ Group: Integer, capturing group id of regular expression, defines part of+ regex which should be returned as keyword (optional; if not set, + the match with the highest group number is returned (counts from + left to right))+ Priority: Integer, if not zero no more regexes will be evaluated if this+ regex matches+ Constraints: table consisting of:+ Line: Integer, limit match to line number, + Filename: String, limit match to input file name+ +Regular expressions are evaluated in the their order within Keywords. If a regex +does not appear to match, there might be a conflicting expression listed before. Comments = { {Block, Nested?, Delimiter={Open, Close?} } @@ -855,6 +876,8 @@ enhances the settings of theme and language definition files. Plug-ins make it possible to apply costum settings without the need to edit installed configuration files. You can apply multiple plugins by using the `--plug-in` option more than once.+If your syntax supports persistent states, use `--two-pass` to generate a +plug-in file which can be used in subsequent invocations. See {README_PLUGINS} for a detailed description and examples of packaged plugins.
@@ -177,7 +177,7 @@ General options: --config-file=<file> set path to a lang or theme file -d, --outdir=<directory> name of output directory -h, --help[=topic] print this help or a topic description- <topic> = [syntax, theme, plugin, config]+ <topic> = [syntax, theme, plugin, config, test] -i, --input=<file> name of single input file -o, --output=<file> name of single output file -P, --progress print progress bar in batch mode@@ -191,6 +191,8 @@ General options: <type> = [langs, themes, plugins] --list-cat=<categories> filter the scripts by the given categories (example: --list-cat='source;script')+ --max-size=<size> set maximum input file size+ (examples: 512M, 1G; default: 256M) --plug-in=<script> execute Lua plug-in script; repeat option to execute multiple plug-ins --plug-in-param=<value> set plug-in input parameter@@ -216,17 +218,21 @@ Output formatting options: use a plug-in file instead -f, --fragment omit document header and footer -F, --reformat=<style> reformats and indents output in given style- <style> = [allman, banner, gnu,- horstmann, java, kr, linux, mozilla, otbs, vtk,- stroustrup, whitesmith, google, pico, lisp]+ <style> = [allman, gnu, google, horstmann,+ java, kr, linux, lisp, mozilla, otbs, pico,+ vtk, ratliff, stroustrup, webkit, whitesmith, user]+ The user style does not apply a predefined scheme.+ Use --reformat-option to define the reformatting.+ --reformat-option=<opt> apply an astyle cmd line option (assumes -F) -I, --include-style include style definition in output file -J, --line-length=<num> line length before wrapping (see -V, -W) -j, --line-number-length=<num> line number width incl. left padding (default: 5)+ --line-range=<start-end> output only lines from number <start> to <end> -k, --font=<font> set font (specific to output format) -K, --font-size=<num?> set font size (specific to output format) -l, --line-numbers print line numbers in output file -m, --line-number-start=<cnt> start line numbering with cnt (assumes -l)- -s, --style=<style> set colour style (theme). See --base16+ -s, --style=<style> set colour style (theme). See --base16 -t, --replace-tabs=<num> replace tabs by <num> spaces -T, --doc-title=<title> document title -u, --encoding=<enc> set output encoding which matches input file@@ -237,7 +243,7 @@ Output formatting options: --wrap-no-numbers omit line numbers of wrapped lines (assumes -l) -z, --zeroes pad line numbers with 0's- --base16 use a theme of the Base16 collection+ --base16[=theme] use a theme of the Base16 collection --delim-cr set CR as end-of-line delimiter (MacOS 9) --isolate output each syntax token separately (verbose output) --keep-injections output plug-in injections in spite of -f@@ -245,6 +251,8 @@ Output formatting options: <case> = [upper, lower, capitalize] --no-trailing-nl omit trailing newline --no-version-info omit version info comment+ --two-pass=<file> write plug-in with persistent state information+ (beta; requires syntax with store instructions) (X)HTML output options:@@ -257,7 +265,7 @@ Output formatting options: --class-name=<name> set CSS class name prefix; omit class name if set to NONE --inline-css output CSS within each tag (verbose output)- --enclose-pre enclose fragmented output with pre tag+ --enclose-pre enclose fragmented output with pre tag (assumes -f) @@ -272,7 +280,7 @@ LaTeX output options: RTF output options: --page-color include page color attributes- -x, --page-size=<ps> set page size+ -x, --page-size=<ps> set page size <ps> = [a3, a4, a5, b4, b5, b6, letter] --char-styles include character stylesheets @@ -283,6 +291,11 @@ SVG output options: --width set image width (see --height) +Terminal escape output options (xterm256 or truecolor):++ --canvas[=width] set background colour padding (default: 80)++ GNU source-highlight compatibility options: --doc create stand alone document@@ -537,17 +550,25 @@ Sollte es mehrere gebrauechliche Erweiterungen geben, werden diese in der Datei ==== Syntax-Elemente ................................................................................-Keywords = { Id, List|Regex, Group? }-- Id: Integer, ID der Schluesselwortgruppe (Werte 1-4, die mehrfach verwendet- werden koennen)- List: Liste, Auflistung von Schluesselwoertern- Regex: String, Regulaerer Ausdruck- Group: Integer, Capturing Group ID der Regex, bestimmt den Teil des gefundenen- Ausdrucks, der als Schluesselwort hervorgehoben werden soll (optional,- wenn nicht gesetzt wird der Match mit der hoechsten Group-ID zurueck-- gegeben (gezaehlt wird von links nach rechts))-+Keywords = { Id, List|Regex, Group?, Priority?, Constraints? }++ Id: Integer, ID der Schluesselwortgruppe (mehrfach verwendbar)+ Default-Themes unterstuetzen 4 Gruppen, Base16-Themes 6.+ List: Liste, Auflistung von Schluesselwoertern+ Regex: String, Regulaerer Ausdruck+ Group: Integer, Capturing Group ID der Regex, bestimmt den Teil des + gefundenen Ausdrucks, der als Schluesselwort hervorgehoben werden+ soll (optional, wenn nicht gesetzt wird der Match mit der + hoechsten Group-ID zurueckgegeben (Zaehlung von links nach rechts))+ Priority: Integer, wenn nicht Null werden keine weiteren Ausdruecke + ausgewertet wenn diese Regex einen Treffer liefert+ Constraints: Tabelle, bestehend aus:+ Line: Integer, begrenzt Suche auf die Zeilennummer, + Filename: String, begrenzt Suche auf den DAteinamen++Regulaere Ausdruecke werden in ihrer Reihenfolge innerhalb von Keywords ausgewertet.+Sollte ein Ausdruck nicht funktionieren, koennte ein vorher definierter Ausdruck+ebenfalls matchen und einen Konflikt ausloesen. Comments = { {Block, Nested?, Delimiter} } @@ -661,7 +682,7 @@ OnStateChange(oldState, newState, token, kwGroupID, lineno, column) ................................................................................ `HL_REJECT` wird dann zurueckgegeben, wenn das Token und der erkannte Zustand-verworfen werden sollen; das erste Zeichzen von Token wird dann ausgegeben und+verworfen werden sollen; das erste Zeichen von Token wird dann ausgegeben und als `oldState` hervorgehoben. Weitere Funktionen sind in {README_PLUGINS} beschrieben.@@ -867,6 +888,8 @@ Mit Hilfe dieser Plugins kann die Ausgabe angepasst werden, ohne installierte Konfigurations-Dateien zu aendern. Man kann mehrere Plugins anwenden, indem die `--plug-in` Option wiederholt angegeben wird.+Wenn die Syntax Persistenz unterstuetzt, kann mit `--two-pass` ein Plugin erzeugt+werden, das bei folgenden Aufrufen genutzt werden kann. Siehe {README_PLUGINS} um mehr darueber zu erfahren.
@@ -1,6 +1,6 @@ = HIGHLIGHT PLUGIN MANUAL André Simon-v3.50, March 2019+v3.53, July 2019 :lang: en :toc: left :toc-title: Contents@@ -223,6 +223,34 @@ RemoveKeyword(keyword) ................................................................................ +=== FUNCTION ADDPERSISTENTSTATE++[[AddPersistentState]]+This function enables storage of keywords and keyword ranges in a plug-in file. +If the syntax contains elements which depend on a context, you can highlight +them although this context is lost in other input files or code sections.+The `--two-pass` command line parameter will save the information passed to +AddPersistentState as syntax plug-in for subsequent invocations with `--plug-in`.++................................................................................+AddPersistentState(keyword, kwGroupID)++ Parameters: keyword: string which should be added to a keyword list+ kwGroupID: keyword group ID of the keyword+ Returns: true if successfull+................................................................................++................................................................................+AddPersistentState(lineno, kwGroupID, column, length)++ Parameters: lineno: line number+ kwGroupID: the keyword group ID+ column: column+ length: length of the keyword+ Returns: true if successfull+................................................................................++ === FUNCTION ONSTATECHANGE [[OnStateChange]]
@@ -234,7 +234,7 @@ The available character classes are: | xdigit | Any hexadecimal digit character, 0-9, a-f and A-F. | word | Any word character - all alphanumeric characters plus the underscore. | Unicode | Any character whose code is greater than 255, this applies to the- wide character traits classes only.+ wide character traits classes only. (not applicable in highlight) |=============================================================================== There are some shortcuts that can be used in place of the character classes,
@@ -1,6 +1,6 @@ Description="GitHub Flavored Markdown" -Categories = {"markup"}+Categories = {"markup", "two-pass"} Keywords={ { Id=1,@@ -12,6 +12,13 @@ Keywords={ { Id=3, Regex=[[\(http.+?\) ]], },+ --needs to be placed before kwd 4+ { Id=1,+ Regex=[[ ^\-{3,} ]],+ },+ { Id=1,+ Regex=[[ ^\={3,} ]],+ }, { Id=4, Regex=[[ ^\s*(\-|\*|>) ]], },@@ -22,3 +29,17 @@ Strings={ } IgnoreCase=false++-- if highlight is called with --two-pass, this handler will save all lines +-- preceeding header lines as range with keyword ID 1+function OnStateChange(oldState, newState, token, kwgroup, lineNumber, column)+ if newState==HL_KEYWORD and kwgroup==1 and token[0]~='#' and lineNumber>1 then+ + AddPersistentState(lineNumber-1, kwgroup, column, #token)+ end+ + if token=="gfsdg" then+ AddPersistentState(token, 5)+ end++end
@@ -2557,8 +2557,8 @@ bool CodeGenerator::printPersistentState ( const string &outFile ) ofstream pluginOutFile( outFile.c_str()); if ( !pluginOutFile.fail() ) { - pluginOutFile <<"Description=\"Plugin generated with --two-pass option\"\n"- <<"Categories = {\"persistence\" }\n"+ pluginOutFile <<"Description=\"Plugin generated with --two-pass option\"\n\n"+ <<"Categories = {\"two-pass\" }\n\n" <<"function syntaxUpdate(desc)\n\n"; for ( unsigned int i=0; i<currentSyntax->getPersistentSnippets().size(); i++ )@@ -2567,10 +2567,10 @@ bool CodeGenerator::printPersistentState ( const string &outFile ) pluginOutFile <<"\n\n"; } - pluginOutFile<<"\nend\n"+ pluginOutFile<<"end\n\n" <<"Plugins={\n" <<" { Type=\"lang\", Chunk=syntaxUpdate }\n"- <<"}";+ <<"}\n"; } else { return false;
@@ -437,9 +437,9 @@ void SyntaxReader::removeKeyword(const string& kw) keywords.erase(kw); } -int SyntaxReader::isKeyword ( const string &s )+bool SyntaxReader::isKeyword ( const string &s ) {- return ( s.length() && keywords.count ( s ) ) ? keywords[s] : 0;+ return ( s.length() && keywords.count ( s ) ) ; } int SyntaxReader::luaAddKeyword (lua_State *L)@@ -581,7 +581,6 @@ int SyntaxReader::luaAddPersistentState (lua_State *L) lua_getglobal(L, GLOBAL_SR_INSTANCE_NAME); SyntaxReader **a=reinterpret_cast<SyntaxReader **>(lua_touserdata(L, 3)); if (*a) {- if (!(*a)->isKeyword(keyword)) { (*a)->addKeyword(kwgroupID, keyword); (*a)->addPersistentKeyword(kwgroupID, keyword);
@@ -130,8 +130,8 @@ public: } /** \param s String- \return class id of keyword, 0 if s is not a keyword */- int isKeyword ( const string &s ) ;+ \return true if s is not a known keyword */+ bool isKeyword ( const string &s ) ; /** \return True if multi line comments may be nested */ bool allowNestedMLComments() const