Bug 92628

Summary: Makefile highlighting does not recognize escaped '#'
Product: [Applications] kate Reporter: Rolf Eike Beer <kde>
Component: syntaxAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: wawanbreton
Priority: NOR    
Version: 2.3.1   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Patch to Makefile.xml
quick and dirty fix
Describes the bug as encountered in version 3.10.5

Description Rolf Eike Beer 2004-11-03 12:21:35 UTC
Version:           2.3.1 (using KDE 3.3.1, SuSE)
Compiler:          gcc version 3.3.1 (SuSE Linux)
OS:                Linux (i686) release 2.6.9-rc4

In the typical "clean" rule the escaped '#' is still seen as the beginning of a comment:

clean:
	rm -f *.o *~ \#* $(TARGETS)
Comment 1 Rolf Eike Beer 2004-11-03 12:22:41 UTC
Created attachment 8148 [details]
Patch to Makefile.xml

This one works for me.
Comment 2 Rolf Eike Beer 2004-11-03 14:19:19 UTC
The patch has two bugs: the file names look reversed and now comments at the beginning of a line are ignored :(
Comment 3 Anders Lund 2005-01-12 00:23:32 UTC
CVS commit by alund: 

do not render escaped hashmark ('\#') as comment
BUG: 92628


  M +1 -1      makefile.xml   1.9


--- kdelibs/kate/data/makefile.xml  #1.8:1.9
@@ -27,5 +27,5 @@
         <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;" />
         <RegExpr attribute="Operator" context="Commands" String="^\s*[@-]"/>
-        <RegExpr attribute="Comment" context="#stay" String="#.*$"/>
+        <RegExpr attribute="Comment" context="#stay" String="(:^|[^\\])#.*$"/>
       </context>
 


Comment 4 Rolf Eike Beer 2005-01-21 13:57:59 UTC
Doesn't work for me (kate 2.3.2), full line comments are not highlighted as comments. Local problem or should it be reopened?
Comment 5 Anders Lund 2005-01-21 14:10:12 UTC
It works in head, where it was applied.
Did you apply the change to your local copy of makefile.xml?
In that case, make sure that the copy you changed is the one used (up the version number and make sure you haven't a copy under ~/.kde)

I can't see why it shouldn't work under kde 3.2.
Comment 6 Rolf Eike Beer 2005-05-19 13:39:07 UTC
Verified on different machine:

--
this is code #this is comment
this is code \# this is still code
#this one is not recognized as comment
 #but this one is
--
Comment 7 Rolf Eike Beer 2005-05-19 13:46:22 UTC
Created attachment 11104 [details]
quick and dirty fix

against version 1.06, works for me
Comment 8 Rolf Eike Beer 2005-12-29 16:04:49 UTC
Still present in 3.5.0. What about my patch?
Comment 9 Dominik Haumann 2006-06-28 09:26:52 UTC
SVN commit 555659 by dhaumann:

fix: highlight # at the beginning of a line as comment
BUG: 92628


 M  +2 -2      makefile.xml  


--- branches/KDE/3.5/kdelibs/kate/data/makefile.xml #555658:555659
@@ -2,7 +2,7 @@
 <!DOCTYPE language SYSTEM "language.dtd">
 <!-- Makefile syntaxfile v0.9 by Per Wigren <wigren@home.se> -->
 <!-- Modified by Joseph Wenninger <jowenn@kde.org> -->
-<language name="Makefile" version="1.06" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
+<language name="Makefile" version="1.07" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
   <highlighting>
     <list name = "keywords">
       <item> include </item>
@@ -26,7 +26,7 @@
         <RegExpr attribute="Operator" context="VarFromNormal" String="[$][\({]"/>
         <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;" />
         <RegExpr attribute="Operator" context="Commands" String="[@-]" firstNonSpace="true"/>
-        <RegExpr attribute="Comment" context="#stay" String="(:^|[^\\])#.*$"/>
+        <RegExpr attribute="Comment" context="#stay" String="(?:^|[^\\])#.*$"/>
       </context>
 
       <context attribute="String" lineEndContext="#pop" name="String">
Comment 10 Dominik Haumann 2006-06-28 09:28:13 UTC
SVN commit 555660 by dhaumann:

fix: highlight # at the beginning of a line as comment
CCBUG: 92628


 M  +2 -2      makefile.xml  


--- trunk/KDE/kdelibs/kate/data/makefile.xml #555659:555660
@@ -2,7 +2,7 @@
 <!DOCTYPE language SYSTEM "language.dtd">
 <!-- Makefile syntaxfile v0.9 by Per Wigren <wigren@home.se> -->
 <!-- Modified by Joseph Wenninger <jowenn@kde.org> -->
-<language name="Makefile" version="1.06" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
+<language name="Makefile" version="1.07" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
   <highlighting>
     <list name = "keywords">
       <item> include </item>
@@ -26,7 +26,7 @@
         <RegExpr attribute="Operator" context="VarFromNormal" String="[$][\({]"/>
         <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;" />
         <RegExpr attribute="Operator" context="Commands" String="[@-]" firstNonSpace="true"/>
-        <RegExpr attribute="Comment" context="#stay" String="(:^|[^\\])#.*$"/>
+        <RegExpr attribute="Comment" context="#stay" String="(?:^|[^\\])#.*$"/>
       </context>
 
       <context attribute="String" lineEndContext="#pop" name="String">
Comment 11 Matthew Woehlke 2006-06-28 22:28:49 UTC
I agree that for the life of me, the patch *should* work. However, I have applied it to my own makefile.xml, and it doesn't (worse, I seem to recall it WAS working yesterday). Any guesses?

I have tried these regexpr's (none work):
"(:^|[^\\])#.*$"
"(?:^|[^\\])#.*$"
"(?=^|[^\\])#.*$"
"(?!\\)#.*$"

Comment 12 Dominik Haumann 2006-06-29 00:47:07 UTC
Can you give me the strings/examples where it does not work?
Did you restart kate?
Comment 13 Matthew Woehlke 2006-06-29 01:33:20 UTC
I started a brand new KATE while I had the '?:' variant in my makefile.xml... it fails on a file consisting of the two characters "\#". I can also verify my method of making KATE reload the highlighter by making verifiable changes, so I'm somewhat comfortable testing without restarting for each minor change.

I *am* running older KATE (KWrite 4.4, from KDE 3.4.3 I think, not sure what actual version of KATE), but I didn't think KATE itself was broken here... maybe I am wrong?

Anyway, thanks for the help!
Comment 14 Dominik Haumann 2006-06-29 07:09:45 UTC
No, it's not broken in 3.4. Please try
 <RegExpr attribute="Comment" context="#stay" String="(^|[^\\])#.*$"/>
and if this does not work, try
 <RegExpr attribute="Comment" context="#stay" String="^#.*$"/> 
 <RegExpr attribute="Comment" context="#stay" String="[^\\])#.*$"/>

Thanks.
Comment 15 Rolf Eike Beer 2006-06-29 08:36:52 UTC
See comment #6 for examples. None of the provided regexps works correctly in all cases.

The two from comment #14 will do lines 2 and 3 right, the one committed does everything but line 2 correct.
Comment 16 Dominik Haumann 2006-06-29 11:31:33 UTC
SVN commit 556104 by dhaumann:

backport: really fix comments + optimizations; please test :)
CCBUG:92628


 M  +6 -5      makefile.xml  


--- branches/KDE/3.5/kdelibs/kate/data/makefile.xml #556103:556104
@@ -2,7 +2,7 @@
 <!DOCTYPE language SYSTEM "language.dtd">
 <!-- Makefile syntaxfile v0.9 by Per Wigren <wigren@home.se> -->
 <!-- Modified by Joseph Wenninger <jowenn@kde.org> -->
-<language name="Makefile" version="1.07" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
+<language name="Makefile" version="1.08" kateversion="2.4" section="Other" extensions="*makefile*;*Makefile*" mimetype="text/x-makefile" author="Per Wigren (wigren@home.se)" license="">
   <highlighting>
     <list name = "keywords">
       <item> include </item>
@@ -24,9 +24,10 @@
         <RegExpr attribute="Section" context="#stay" String="^[.].*:"/>
         <DetectChar attribute="String" context="String" char="&quot;"/>
         <RegExpr attribute="Operator" context="VarFromNormal" String="[$][\({]"/>
-        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;" />
-        <RegExpr attribute="Operator" context="Commands" String="[@-]" firstNonSpace="true"/>
-        <RegExpr attribute="Comment" context="#stay" String="(?:^|[^\\])#.*$"/>
+        <Detect2Chars attribute="Special" context="#stay" char="\" char1="#"/>
+        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;"/>
+        <AnyChar attribute="Operator" context="Commands" String="@-" firstNonSpace="true"/>
+        <RegExpr attribute="Comment" context="#stay" String="#.*$"/>
       </context>
 
       <context attribute="String" lineEndContext="#pop" name="String">
@@ -49,7 +50,7 @@
       </context>
 
       <context name="VarFromNormal" attribute="Variable" lineEndContext="#stay">
-        <RegExpr attribute="Operator" String="[\)}]" context="#pop"/>
+        <AnyChar attribute="Operator" String=")}" context="#pop"/>
       </context>
 
       <context name="Commands" attribute="Normal Text" lineEndContext="#pop">
Comment 17 Matthew Woehlke 2006-06-29 17:28:39 UTC
FWIW, that's what I finally came up with independantly, except that Detect2Chars on my KATE doesn't seem to want to work with '\', as a result of which I had to use a RegExpr instead. It does seem to work, however.
Comment 18 Dominik Haumann 2006-06-29 17:39:06 UTC
Detect2Chars really should work. In what way does it not work? I cannot imagine ;)

Just for info: I used Detect2Chars because it is *much much* faster than RegExpr, and if you look closely, the whole highlighting definition almost uses 100% only RegExprs, which is speedwise very bad.
Comment 19 Matthew Woehlke 2006-06-29 18:14:45 UTC
Um... huh, it's working now. It doesn't understand escape chars ("\\" doesn't work, which is somewhat unfortunate), but I thought I had tried "\" as well. Oh, well.
Comment 20 Dominik Haumann 2006-06-30 00:13:35 UTC
\\ are both colored pink as far as I know. This is due to the rule
<AnyChar ... String="...\..." />

Feel free to fix/rewrite the parts ;) But if it works now that's good.
Comment 21 Rolf Eike Beer 2006-06-30 13:15:17 UTC
My testcase now works.

What about things like this:

foo \\#bar

This still does not work. But I don't see any use for such things. Just leave it as is. Don't forget to put the same thing into trunk/
Comment 22 Dominik Haumann 2006-06-30 13:40:27 UTC
SVN commit 556472 by dhaumann:

SVN_SILENT: neverending story
CCBUG: 92628


 M  +2 -1      makefile.xml  


--- branches/KDE/3.5/kdelibs/kate/data/makefile.xml #556471:556472
@@ -25,7 +25,8 @@
         <DetectChar attribute="String" context="String" char="&quot;"/>
         <RegExpr attribute="Operator" context="VarFromNormal" String="[$][\({]"/>
         <Detect2Chars attribute="Special" context="#stay" char="\" char1="#"/>
-        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;"/>
+        <Detect2Chars attribute="Special" context="#stay" char="\" char1="\"/>
+        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\&#059;"/>
         <AnyChar attribute="Operator" context="Commands" String="@-" firstNonSpace="true"/>
         <RegExpr attribute="Comment" context="#stay" String="#.*$"/>
       </context>
Comment 23 Dominik Haumann 2006-06-30 13:41:20 UTC
SVN commit 556473 by dhaumann:

SVN_SILENT: forward port: neverending story ;) make \\# bla work
CCBUG: 92628


 M  +2 -1      makefile.xml  


--- trunk/KDE/kdelibs/kate/data/makefile.xml #556472:556473
@@ -25,7 +25,8 @@
         <DetectChar attribute="String" context="String" char="&quot;"/>
         <RegExpr attribute="Operator" context="VarFromNormal" String="[$][\({]"/>
         <Detect2Chars attribute="Special" context="#stay" char="\" char1="#"/>
-        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\\&#059;"/>
+        <Detect2Chars attribute="Special" context="#stay" char="\" char1="\"/>
+        <AnyChar attribute="Operator" context="#stay" String="+*=%$():\&#059;"/>
         <AnyChar attribute="Operator" context="Commands" String="@-" firstNonSpace="true"/>
         <RegExpr attribute="Comment" context="#stay" String="#.*$"/>
       </context>
Comment 24 Erwan MATHIEU 2013-07-30 10:14:57 UTC
Created attachment 81449 [details]
Describes the bug as encountered in version 3.10.5
Comment 25 Erwan MATHIEU 2013-07-30 10:15:41 UTC
Hi,

I have a similar problem in version 3.10.5 (see attached screenshot for details)

Maybe this bug should be re-opened ?
Comment 26 Christoph Feck 2013-08-10 19:11:08 UTC
Erwan, no, what you see is a different bug, please report it separately. I can reproduce it on today's master. The issue is with the colon within the comments, causing the highlighter to treat it as a rule.