@ 261105.1

200829.1 · c419d6a0bb35ab4c3c471ddb8396dd88f755173c

summer fix collection

reading declarations

ChangeLog.adoc

@@ -6,6 +6,14 @@ :toc: left :toclevels: 1 +== highlight 3.58++17.08.2020++  - improved `--force` fallback argument handling (https://gitlab.com/saalen/highlight/-/issues/163)+  - added C++ attribute syntax support+  - fixed issues in bash.lang (https://gitlab.com/saalen/highlight/-/issues/161)+  - fixed Bash heredoc highlighting in bash_functions.lua (https://gitlab.com/saalen/highlight/-/issues/156)  == highlight 3.57 

README_PLUGINS.adoc

@@ -1,6 +1,6 @@ = HIGHLIGHT PLUGIN MANUAL André Simon-v3.57, May 2020+v3.57, June 2020 :lang: en :toc: left :toc-title: Contents@@ -275,6 +275,7 @@ OnStateChange(oldState, newState, token, kwGroupID, lineno, column) Returns `HL_REJECT` if the recognized token and state should be discarded; the first character of token will be outputted and highlighted as `oldState`. + Example for its usage in a plugin context:  [source,lua]@@ -292,6 +293,46 @@ keyword belongs to keyword group 5. If keyword group 5 is defined by a regex, this token will be recognized later as a keyword even if the regular expression does no longer match. +[IMPORTANT]+================================================================================+If both the syntax file and the plug-in script contain an `OnStateChange` +function, the plug-in definition will replace the function of the syntax file.+In order to prevent this, the exising function can be assigned to an new +variable and called using this name in the plug-in `OnStateChange` code chunk.++See this example in the plug-in `bash_functions.lua`:+================================================================================++[source,lua]+--------------------------------------------------------------------------------+function syntaxUpdate(desc)+  if desc=="Bash" then++  table.insert( Keywords,+                  { Id=5, Regex=[[(\w+)\s*\(]]+                  } )++    if OnStateChange ~= nil then+      OrigOnStateChange = OnStateChange;+    end++    -- add keywords to list 5 if pattern matches+    function OnStateChange(oldState, newState, token, kwgroup)++      if newState==HL_KEYWORD and kwgroup==5 then+        AddKeyword(token, 5)+        return newState+      end+      if OrigOnStateChange then+        return OrigOnStateChange(oldState, newState, token, kwgroup)+      end+    end++  end+end+--------------------------------------------------------------------------------++  === FUNCTION OVERRIDEPARAM 

langDefs/c.lang

@@ -38,6 +38,9 @@ Keywords={   },   { Id=4,     Regex=[[(\w+)\s*\(]]+  },+  { Id=5,+    Regex=[[ \[\[\w+?\]\] ]]   } } 

langDefs/sh.lang

@@ -3,7 +3,7 @@ Description="Bash"  Categories = {"script", "shell"} -Identifiers=[[ [a-zA-Z_][\w\-]*(?!\/) ]]+Identifiers=[[ [a-zA-Z_]\w*(?!\w*\/) ]]  Keywords={   { Id=1,@@ -19,7 +19,7 @@ Keywords={         "unset", "wait", "eval", "bg", "cd", "echo", "exec", "exit", "kill"},   },   { Id=3,-    List={"ls", "cat", "tac", "rev", "cp", "mv", "rm", "rmdir", "chmod",+    List={"ls", "cat", "tac", "rev", "cp", "mv", "rm", "rmdir", "chmod", "mkdir", "ls", "ll",         "chattr", "ln", "find", "xargs", "expr", "date", "zdump", "time", "touch", "at",         "batch", "cal", "sleep", "usleep", "hwclock", "clock", "sort", "tsort", "diff",         "patch", "diff3", "sdiff", "cmp", "comm", "uniq", "expand", "unexpand", "cat",@@ -39,7 +39,7 @@ Keywords={   -- fixes issue with expressions like ${SHELL="${CONFIG_SHELL-/bin/sh}"}   -- the [^\}]+ part fixes issue with "s#@PATH@#/opt/${pkgname}/bin/# ${pkgdir}/etc/profile.d/${pkgname}.sh"   { Id=4,-    Regex=[[\$\{[^\}]+\$\{.+?\}.+?\}|\$\{.+?\} ]],+    Regex=[[\$\{[^\}]+\$\{.+?\}.+?\}|\$\{.+?\}|\$\(.+?\) ]],   },   { Id=4,     Regex=[[ \$[\w\#]+ ]],

plugins/bash_functions.lua

@@ -13,21 +13,24 @@ Categories = {"bash"} function syntaxUpdate(desc)   if desc=="Bash" then -  --add function name pattern ("f_" prefix omitted but maybe reasonable)   table.insert( Keywords,                   { Id=5, Regex=[[(\w+)\s*\(]]                   } ) +    if OnStateChange ~= nil then+      OrigOnStateChange = OnStateChange;+    end+     -- add keywords to list 5 if pattern matches     function OnStateChange(oldState, newState, token, kwgroup)        if newState==HL_KEYWORD and kwgroup==5 then-    --if string.find(token, "f_%a+") then-      AddKeyword(token, 5)-    --end-    --more patterns could be defined here+        AddKeyword(token, 5)+        return newState+      end+      if OrigOnStateChange then+        return OrigOnStateChange(oldState, newState, token, kwgroup)       end-      return newState     end    end

plugins/outhtml_ie7_webctrl.lua

@@ -15,6 +15,9 @@ function syntaxUpdate(desc)     return ' '   end +  if OnStateChange ~= nil then+      OrigOnStateChange = OnStateChange;+  end   -- trigger OverrideParam   function OnStateChange(oldState, newState, token, groupID, lineno, column)     if (called==nil) then@@ -22,6 +25,9 @@ function syntaxUpdate(desc)       OverrideParam("format.maskws", "true")       called=1     end+    if OrigOnStateChange then+        return OrigOnStateChange(oldState, newState, token, groupID, lineno, column)+    end     return newState   end 

plugins/outhtml_keyword_matcher.lua

@@ -32,8 +32,13 @@ function syntaxUpdate(desc) ]]   end ++  if OnStateChange ~= nil then+      OrigOnStateChange = OnStateChange;+  end+   --may be triggered twice per keyword-  function OnStateChange(oldState, newState, token, kwgroup)+  function OnStateChange(oldState, newState, token, kwgroup, lineno, column)     if newState==HL_KEYWORD  and kwgroup==keywordGroup then        if kwID[token] == nil then@@ -46,6 +51,9 @@ function syntaxUpdate(desc)       end      end+    if OrigOnStateChange then+        return OrigOnStateChange(oldState, newState, token, kwgroup, lineno, column)+    end     return newState   end 

src/cli/main.cpp

@@ -546,8 +546,9 @@ int HLCmdLineApp::run ( const int argc, const char*argv[] )         if ( !options.syntaxGiven() ) { // determine file type for each file             suffix = dataDir.guessFileType ( dataDir.getFileSuffix ( inFileList[i] ), inFileList[i] );         }-        +         if ( suffix.empty()  && options.forceOutput()) suffix=options.getFallbackSyntax(); //avoid segfault+                 if ( suffix.empty() ) {             if ( !options.enableBatchMode() )                 cerr << "highlight: Undefined language definition. Use --"@@ -561,6 +562,10 @@ int HLCmdLineApp::run ( const int argc, const char*argv[] )         if ( suffix != lastSuffix ) {                          string langDefPath=options.getAbsLangPath().empty() ? dataDir.getLangPath ( suffix+".lang" ) : options.getAbsLangPath();+            +            if (!Platform::fileExists(langDefPath) && !options.getFallbackSyntax().empty()) {+                langDefPath = dataDir.getLangPath ( options.getFallbackSyntax()+".lang" );+            }              highlight::LoadResult loadRes= generator-> loadLanguage( langDefPath ); 

src/core/syntaxreader.cpp

@@ -249,17 +249,6 @@ LoadResult SyntaxReader::load ( const string& langDefPath, const string& pluginR             idx++;         }         -        /*-        if (globals.count("GeneratorOverride")) {-            idx=1;-            Diluculum::LuaValue lVal = ls["GeneratorOverride"][idx].value();-            while (lVal !=Diluculum::Nil) {-                pluginConfigOverride[StringTools::change_case(lVal["Param"].asString())] = lVal["Value"].asString();-                idx++;-                lVal = ls["GeneratorOverride"][idx].value();-            }-        }*/-                 if (globals.count("KeywordFormatHints")) {             idx=1;             Diluculum::LuaValue lVal = ls["KeywordFormatHints"][idx].value();@@ -418,7 +407,7 @@ LoadResult SyntaxReader::load ( const string& langDefPath, const string& pluginR                 ++listIdx;             }             //allow host syntax-            allowInnerSections[getCurrentPath()] = true;               +            allowInnerSections[getCurrentPath()] = true;         }          if (globals.count("HeaderInjection")) {

src/core/xterm256generator.cpp

@@ -206,7 +206,7 @@ void Xterm256Generator::xterm2rgb ( unsigned char color, unsigned char* rgb )  void Xterm256Generator::maketable() {-    unsigned char c, rgb[3];+    unsigned char c, rgb[3] = {0};     for ( c=0; c<=253; c++ ) {         xterm2rgb ( c,rgb );         colortable[c][0] = rgb[0];

src/include/version.h

@@ -29,7 +29,7 @@ along with Highlight.  If not, see <http://www.gnu.org/licenses/>. #define VERSION_H  #define HIGHLIGHT_MAJOR "3"-#define HIGHLIGHT_MINOR "57"+#define HIGHLIGHT_MINOR "58"  #define HIGHLIGHT_VERSION  HIGHLIGHT_MAJOR "." HIGHLIGHT_MINOR 

src/makefile

@@ -12,11 +12,11 @@  # See src/gui-qt/highlight.pro for the Qt GUI compilation options -#CXX=clang++-CXX=g+++#CXX ?= clang+++CXX ?= g++  # was: qmake-qt5-QMAKE=qmake+QMAKE ?= qmake  # Added -std=c++11 because of auto_ptr to unique_ptr transition CFLAGS:=-Wall -O2 ${CFLAGS} -DNDEBUG -std=c++11 -D_FILE_OFFSET_BITS=64