[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    [patch] (Kate ruby highlighting) Why must a comment be preceded by
From:       "Robin Pedersen" <robinpeder () gmail ! com>
Date:       2008-05-30 10:03:39
Message-ID: op.ubyowdsw9lgty9 () lenobin
[Download RAW message or body]

From the ruby.xml syntax file:

<RegExpr attribute="Comment" String="#"  context="Comment Line"  
firstNonSpace="true"/>
<RegExpr attribute="Comment" String="(\b|\s)#"  context="General Comment"/>

The second line has caused me trouble more than once, because I had to  
make sure not to skip whitespace in other contexts, or the comments wasn't  
recognized. I can't really figure out why the '#' character must be either  
the first non-space character, or preceded by a word boundary or  
whitespace.

I want to change it to:
<RegExpr attribute="Comment" String="#"  context="General Comment"/>
or, more simplified:
<DetectChar attribute="Comment" char="#" context="General Comment"/>

With this change, I can remove several other "hacks" that exists only to  
make sure whitespace isn't discarded. It would also fix several cases  
where kate doesn't recognize valid ruby comments.

I have tried several cases in the interactive ruby console that is not  
recognized as comments in kate, because of this. These examples are all  
recognized as comments by ruby, but not kate:

   foo?#comment
   foo!#comment
   10 +#comment
   10 /#comment

This, however is not a comment, but inside a regexp. But because the  
regexp/division errors are fixed, it won't be mistaken for a comment.
   foo /#comment

My question is: Can you think of any cases where a '#' character in a  
normal code context, not preceded by a word boundary or whitespace, would  
not be recognized as a comment by ruby?


-- 
Robin Pedersen
["comments.diff" (comments.diff)]

Index: syntax/data/ruby.xml
===================================================================
--- syntax/data/ruby.xml	(revision 814410)
+++ syntax/data/ruby.xml	(working copy)
@@ -281,8 +281,7 @@
 				
 				<RegExpr attribute="Comment" String="#\s*BEGIN.*$"  context="#stay" \
                beginRegion="marker" column="0"/>
 				<RegExpr attribute="Comment" String="#\s*END.*$"  context="#stay" \
                endRegion="marker" column="0"/>
-				<RegExpr attribute="Comment" String="#"  context="Comment Line" \
                firstNonSpace="true"/>
-				<RegExpr attribute="Comment" String="(\b|\s)#"  context="General Comment"/>
+				<DetectChar attribute="Comment" char="#" context="General Comment"/>
 				
 				<DetectChar attribute="Delimiter" char="["  context="#stay"/>
 				<DetectChar attribute="Delimiter" char="]"  context="check_div_1"/>
@@ -309,21 +308,18 @@
 			
 			<!-- A slash is always a division operator, even if preceeded by whitespace -->
 			<context name="check_div_1" attribute="Normal Text" fallthrough="true" \
                fallthroughContext="#pop" lineEndContext="#pop">
-				<RegExpr String="\s*[^\s/]" lookAhead="true" context="#pop"/>
 				<RegExpr attribute="Normal Text" String="\s*" context="#stay"/>
 				<DetectChar attribute="Operator" char="/" context="#pop"/>
 			</context>
 			
 			<!-- Same as check_div_1, but with double pop to exit the surrounding context -->
 			<context name="check_div_1_pop" attribute="Normal Text" fallthrough="true" \
                fallthroughContext="#pop#pop" lineEndContext="#pop#pop">
-				<RegExpr String="\s*[^\s/]" lookAhead="true" context="#pop#pop"/>
 				<RegExpr attribute="Normal Text" String="\s*" context="#stay"/>
 				<DetectChar attribute="Operator" char="/" context="#pop#pop"/>
 			</context>
 
 			<!-- A slash is division operator if it's the first character, or if preceeded \
and followed by whitespace -->  <context name="check_div_2" attribute="Normal Text" \
                fallthrough="true" fallthroughContext="#pop" lineEndContext="#pop">
-				<RegExpr String="\s*[^\s/]" lookAhead="true" context="#pop"/>
 				<DetectChar attribute="Operator" char="/" context="#pop"/>
 				<RegExpr attribute="Normal Text" String="\s+" context="check_div_2_internal"/>
 			</context>
@@ -335,7 +331,6 @@
 			
 			<!-- Same as check_div_2, but with double pop to exit the surrounding context -->
 			<context name="check_div_2_pop" attribute="Normal Text" fallthrough="true" \
                fallthroughContext="#pop#pop" lineEndContext="#pop#pop">
-				<RegExpr String="\s*[^\s/]" lookAhead="true" context="#pop#pop"/>
 				<DetectChar attribute="Operator" char="/" context="#pop#pop"/>
 				<RegExpr attribute="Normal Text" String="\s+" \
context="check_div_2_pop_internal"/>  </context>



_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic