[rkward-cvs] SF.net SVN: rkward:[4084] trunk/rkward/rkward/syntax

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Dec 8 19:28:44 UTC 2011


Revision: 4084
          http://rkward.svn.sourceforge.net/rkward/?rev=4084&view=rev
Author:   tfry
Date:     2011-12-08 19:28:44 +0000 (Thu, 08 Dec 2011)
Log Message:
-----------
Use an auxiliary context to check operator right hand sides for (some) errors. This makes the rules more simple and efficient, in addition to catch more issues.
This also fixes false positive markup of sequences like x*-1, which are legal.

Regressions:
"->+" , "->>-", "::-", ":::+"
and some others are no longer marked as error, although they really are.

Modified Paths:
--------------
    trunk/rkward/rkward/syntax/r-syntax-test.R
    trunk/rkward/rkward/syntax/r.xml
    trunk/rkward/rkward/syntax/rkward.xml

Modified: trunk/rkward/rkward/syntax/r-syntax-test.R
===================================================================
--- trunk/rkward/rkward/syntax/r-syntax-test.R	2011-12-08 16:36:44 UTC (rev 4083)
+++ trunk/rkward/rkward/syntax/r-syntax-test.R	2011-12-08 19:28:44 UTC (rev 4084)
@@ -30,8 +30,10 @@
 try ( {
 	x <<- 1
 	x <<<- 1		# syntax error
+	x <- * 1		# syntax error
 	x += 1 -= x1 *= x2	# syntax error
-	x =+ 1 =- x1 =* x2	# syntax error
+	x =* 1 =/ x1 // x2	# syntax error
+	x =+ 1 =- x1		# These look misleading, but are legal
 	"%my 1st infix%" <- function (x, y) { x + y }		# legal infix
 	3 %my 1st infix% 4
 	"%my%infix%" <- function (x, y) { x + y }		# illegal infix

Modified: trunk/rkward/rkward/syntax/r.xml
===================================================================
--- trunk/rkward/rkward/syntax/r.xml	2011-12-08 16:36:44 UTC (rev 4083)
+++ trunk/rkward/rkward/syntax/r.xml	2011-12-08 19:28:44 UTC (rev 4084)
@@ -8,7 +8,7 @@
 	R      : http://www.r-project.org/
 	RKWard : http://rkward.sourceforge.net/
 	-->
-<language version="2.05" kateversion="2.5" name="R Script" section="Scripts" extensions="*.R;*.r;*.S;*.s;*.q" mimetype="" license="GPL">
+<language version="2.06" kateversion="2.5" name="R Script" section="Scripts" extensions="*.R;*.r;*.S;*.s;*.q" mimetype="" license="GPL">
 <highlighting>
 
 	<list name="controls">
@@ -77,6 +77,15 @@
 			<HlCStringChar attribute="String Char" context="#stay"/>
 		</context>
 
+		<context attribute="Normal Text" lineEndContext="#stay" name="operator_rhs" fallthrough="true" fallthroughContext="#pop">
+			<!-- While there is nothing of interest, stay in the context -->
+			<StringDetect attribute="Headline" context="Headline" String="##"/>
+			<DetectChar attribute="Comment" context="Comment" char="#"/>
+			<DetectChar attribute="String" context="#stay" char=" "/>
+			<!-- Operators other than + and - directly after another operator are an error. -->
+			<RegExpr attribute="Error" context="#stay" String="(\*|/|<|>|=|\!|\||&|:|\^|@|\$|~)"/>
+		</context>
+
 		<context attribute="Headline" lineEndContext="#pop" name="Headline"/>
 		<context attribute="Comment" lineEndContext="#pop" name="Comment"/>
 
@@ -95,21 +104,12 @@
 			<StringDetect attribute="Headline" context="Headline" String="##"/>
 			<DetectChar attribute="Comment" context="Comment" char="#"/>
 
-			<!-- The following three lines look worse than they are: If there are any other operators directly before or after -> and <-, this is a syntax error (expections: ->> and <<-) -->
-			<RegExpr attribute="Error" context="#stay" String="([\+\-\*/\^\:\$~!&\|=>@^])([<]{1,2}\-|\-[>]{1,2})"/>
-			<RegExpr attribute="Error" context="#stay" String="([<]{1,2}\-|\-[>]{1,2})([\+\-\*/\^\:\$~!&\|=<@])"/>
-			<RegExpr attribute="Error" context="#stay" String="([<]{3}|[>]{3})"/>
-			<RegExpr attribute="Assign" context="#stay" String="[<]{1,2}\-"/>
-			<RegExpr attribute="Assign" context="#stay" String="\-[>]{1,2}"/>
-			<!-- Much like above: Most other operators are forbidden around = -->
-			<RegExpr attribute="Error" context="#stay" String="([\+\-\*/\^\:\$~&\|@^])="/>
-			<RegExpr attribute="Error" context="#stay" String="=([\+\-\*/\^\:\$~!<>&\|@^])"/>
-			<RegExpr attribute="Assign" context="#stay" String="=(?!=)"/>
-
-			<!-- These operators are fine as long as they're followed by something else or end of line. Error otherwise -->
-			<RegExpr attribute="Operator" context="#stay" String="(\+|\-|\*{1,2}|/|<=|>=|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~)((?!(\+|\-|\*|/|<=|>=|=|\!=|\||&|:|\^|@|\$|~))|$)"/>
-			<RegExpr attribute="Error" context="#stay" String="(\+|\-|\*{1,2}|/|<=|>=|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~){2,}"/>
-			<RegExpr attribute="Operator" context="#stay" String="%[^%]*%"/>
+			<!-- For (assignment) operators, enter a new context operator_rhs to check what follows (generally, that should not be another op) -->
+			<RegExpr attribute="Assign" context="operator_rhs" String="[<]{1,2}\-"/>
+			<RegExpr attribute="Assign" context="operator_rhs" String="\-[>]{1,2}"/>
+			<RegExpr attribute="Assign" context="operator_rhs" String="=(?!=)"/>
+			<RegExpr attribute="Operator" context="operator_rhs" String="(\+|\-|\*{1,2}|/|<=?|>=?|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~)"/>
+			<RegExpr attribute="Operator" context="operator_rhs" String="%[^%]*%"/>
 			
 			<DetectChar attribute="Symbol" context="ctx0" char="{" beginRegion="Brace1" />
 

Modified: trunk/rkward/rkward/syntax/rkward.xml
===================================================================
--- trunk/rkward/rkward/syntax/rkward.xml	2011-12-08 16:36:44 UTC (rev 4083)
+++ trunk/rkward/rkward/syntax/rkward.xml	2011-12-08 19:28:44 UTC (rev 4084)
@@ -9,7 +9,7 @@
 	R      : http://www.r-project.org/
 	RKWard : http://rkward.sourceforge.net/
 	-->
-<language version="2.05" kateversion="2.5" name="R interactive session" section="Scripts" extensions="" mimetype="" author="P. Ecochard" license="GPL">
+<language version="2.06" kateversion="2.5" name="R interactive session" section="Scripts" extensions="" mimetype="" author="P. Ecochard" license="GPL">
 <highlighting>
 	<list name="controls">
 	<item> for </item>
@@ -103,8 +103,19 @@
 			<!-- See above -->
 			<RegExpr attribute="Normal Text" context="output" String="^([^\+]|$)" lookAhead="true"/>
 			<Detect2Chars attribute="Prompt" context="#stay" char=">" char1=" " column="0" lookAhead="true"/>
+			<Detect2Chars attribute="Prompt" context="#stay" char="+" char1=" " column="0"/>
 		</context>
 
+		<context attribute="Normal Text" lineEndContext="#stay" name="operator_rhs" fallthrough="true" fallthroughContext="#pop">
+			<IncludeRules context="CommandContinuationCheck"/>
+			<!-- While there is nothing of interest, stay in the context -->
+			<StringDetect attribute="Headline" context="Headline" String="##"/>
+			<DetectChar attribute="Comment" context="Comment" char="#"/>
+			<DetectChar attribute="String" context="#stay" char=" "/>
+			<!-- Operators other than + and - directly after another operator are an error. -->
+			<RegExpr attribute="Error" context="#stay" String="(\*|/|<|>|=|\!|\||&|:|\^|@|\$|~)"/>
+		</context>
+
 		<!-- This context is not really used, but contains the common rules -->
 		<context attribute="Normal Text" name="CommonRules" lineEndContext="#stay">
 			<DetectChar attribute="String" context="string" char="""/>
@@ -120,21 +131,12 @@
 			<StringDetect attribute="Headline" context="Headline" String="##"/>
 			<DetectChar attribute="Comment" context="Comment" char="#"/>
 			
-			<!-- The following three lines look worse than they are: If there are any other operators directly before or after -> and <-, this is a syntax error (expections: ->> and <<-) -->
-			<RegExpr attribute="Error" context="#stay" String="([\+\-\*/\^\:\$~!&\|=>@^])([<]{1,2}\-|\-[>]{1,2})"/>
-			<RegExpr attribute="Error" context="#stay" String="([<]{1,2}\-|\-[>]{1,2})([\+\-\*/\^\:\$~!&\|=<@])"/>
-			<RegExpr attribute="Error" context="#stay" String="([<]{3}|[>]{3})"/>
-			<RegExpr attribute="Assign" context="#stay" String="[<]{1,2}\-"/>
-			<RegExpr attribute="Assign" context="#stay" String="\-[>]{1,2}"/>
-			<!-- Much like above: Most other operators are forbidden around = -->
-			<RegExpr attribute="Error" context="#stay" String="([\+\-\*/\^\:\$~&\|@^])="/>
-			<RegExpr attribute="Error" context="#stay" String="=([\+\-\*/\^\:\$~!<>&\|@^])"/>
-			<RegExpr attribute="Assign" context="#stay" String="=(?!=)"/>
-			
-			<!-- These operators are fine as long as they're followed by something else or end of line. Error otherwise -->
-			<RegExpr attribute="Operator" context="#stay" String="(\+|\-|\*{1,2}|/|<=|>=|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~)((?!(\+|\-|\*|/|<=|>=|=|\!=|\||&|:|\^|@|\$|~))|$)"/>
-			<RegExpr attribute="Error" context="#stay" String="(\+|\-|\*{1,2}|/|<=|>=|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~){2,}"/>
-			<RegExpr attribute="Operator" context="#stay" String="%[^%]*%"/>
+			<!-- For (assignment) operators, enter a new context operator_rhs to check what follows (generally, that should not be another op) -->
+			<RegExpr attribute="Assign" context="operator_rhs" String="[<]{1,2}\-"/>
+			<RegExpr attribute="Assign" context="operator_rhs" String="\-[>]{1,2}"/>
+			<RegExpr attribute="Assign" context="operator_rhs" String="=(?!=)"/>
+			<RegExpr attribute="Operator" context="operator_rhs" String="(\+|\-|\*{1,2}|/|<=?|>=?|={1,2}|\!=|\|{1,2}|&{1,2}|:{1,3}|\^|@|\$|~)"/>
+			<RegExpr attribute="Operator" context="operator_rhs" String="%[^%]*%"/>
 
 			<!-- Contrary to the normal R Script highlighting, we don't start a region here, but we do go into a command sub-context -->
 			<DetectChar attribute="Symbol" context="command" char="{" />

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rkward-tracker mailing list