Hans,

the attached patch comes from code that Christoph Reller kindly provided
me with to fix comments in TeX, MP and Lua
(https://bitbucket.org/philexander/context-highlight/issues/2/highlight-for-tex).

* It formats the whole comment (both character and text [not only the
former]) for TeX and MP.

* It does the same for one-line comments in Lua.

* It fixes multiline comments in Lua.

* It fixes a minor typo.

The following code is compiled in the PDF attachment that shows the
difference before and after the patch:

    \starttext
    \startTEX
    % comment for the whole line
    \stopTEX

    \startMP
    a % comment for the rest of the line
    \stopMP

    \startLUA
    --[[

    multiline

    comment
    --]]

    ---[[

    multiline

    but not comment
    ---]]
    \stopLUA
    \stoptext

Could you consider merging in ConTeXt?

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
--- mkiv/buff-imp-lua.lua	2017-12-20 10:56:19.000000000 +0100
+++ buff-imp-lua.lua	2018-01-02 22:38:47.585994426 +0100
@@ -9,7 +9,7 @@
 -- borrowed from ctx scite lexers
 -- add goto/label scanning
 --
--- depricated:
+-- deprecated:
 --
 -- gcinfo unpack getfenv setfenv loadlib
 -- table.maxn table.getn table.setn
@@ -135,7 +135,10 @@
     name_c       = visualizename_c,
 }
 
-local comment     = P("--")
+local comment     = P("--") * (patterns.anything - patterns.newline)^0
+local commentopen = P("--[[")
+local commentclose = P("--]]")
+local commentinterior = patterns.utf8char - commentclose - patterns.newline
 local name        = (patterns.letter + patterns.underscore)
                   * (patterns.letter + patterns.underscore + patterns.digit)^0
 local boundary    = S('()[]{}')
@@ -168,8 +171,12 @@
     longstring =
         longstring / long,
     comment =
-        makepattern(handler,"comment",comment)
-      * (V("space") + V("content"))^0,
+        makepattern(handler, "comment", commentopen)
+      * (   makepattern(handler, "comment", commentinterior)
+          + V("whitespace")
+        )^0 
+      * makepattern(handler, "comment", commentclose)
+      + makepattern(handler,"comment",comment),
     longcomment =
         makepattern(handler,"comment",comment)
       * longstring / long,
--- mkiv/buff-imp-tex.lua	2017-12-20 10:56:19.000000000 +0100
+++ buff-imp-tex.lua	2018-01-02 22:29:47.602776293 +0100
@@ -40,7 +40,7 @@
 
 -- todo: unicode letters in control sequences (slow as we need to test the nature)
 
-local comment  = S("%")
+local comment  = P("%") * (patterns.anything - patterns.newline)^0
 local name     = P("\\") * (patterns.letter + S("@!?_"))^1
 local escape   = P("\\") * (patterns.anything - patterns.newline)^-1 -- else we get \n
 local group    = S("${}")
 --- buff-imp-mp.lua	2018-01-31 18:51:13.790990927 +0100
+++ mkiv/buff-imp-mp.lua	2018-01-31 18:51:17.805959417 +0100
@@ -85,7 +85,7 @@
     name         = visualizename,
 }
 
-local comment     = S("%")
+local comment     = P("%") * (patterns.anything - patterns.newline)^0
 local name        = (patterns.letter + S("_"))^1
 local constructor = S("$@#")
 local boundary    = S('()[]:=<>;"')
 

Attachment: unpatched-patched.pdf
Description: Adobe PDF document

_______________________________________________
dev-context mailing list
dev-context@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-context

Reply via email to