[education/rkward] rkward/syntax: Sync R console highlighting with R highlighting in frameworks

Thomas Friedrichsmeier null at kde.org
Mon Oct 13 21:34:03 BST 2025


Git commit 5ee4ff86fda9a8ee4ee09a738fe196108a05850c by Thomas Friedrichsmeier.
Committed on 13/10/2025 at 19:16.
Pushed by tfry into branch 'master'.

Sync R console highlighting with R highlighting in frameworks

Trying to keep the diff minimal, therefore also copying comments etc.

M  +75   -51   rkward/syntax/rkward.xml

https://invent.kde.org/education/rkward/-/commit/5ee4ff86fda9a8ee4ee09a738fe196108a05850c

diff --git a/rkward/syntax/rkward.xml b/rkward/syntax/rkward.xml
index 44b5e8077..77cbe4e29 100644
--- a/rkward/syntax/rkward.xml
+++ b/rkward/syntax/rkward.xml
@@ -23,7 +23,7 @@ SPDX-FileCopyrightText: by Arne Hennigsen
 SPDX-FileContributor: The RKWard Team <rkward at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 -->
-<language version="10" kateversion="2.5" name="R interactive session" section="Scripts" extensions="" mimetype="" author="P. Ecochard" license="GPL">
+<language version="14" kateversion="5.0" name="R interactive session" section="Scripts" extensions="" mimetype="" author="P. Ecochard" license="GPLv2">
 <highlighting>
 
 	<list name="controls">
@@ -54,7 +54,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 	<contexts>
 		<!-- This context dispatches to the two main contexts output or command. -->
 		<context attribute="Prompt" lineEndContext="#stay" name="ctxbase">
-			<Detect2Chars attribute="Prompt" context="command0" char=">" char1=" " column="0" beginRegion="commandRegion"/>
+			<Detect2Chars attribute="Prompt" context="level0" char=">" char1=" " column="0" beginRegion="commandRegion"/>
 			<RegExpr attribute="Normal Text" context="output" String="^([^>\+]|$)" lookAhead="true"/>
 		</context>
 		
@@ -162,27 +162,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		
 		<!-- ################ COMMAND ######################### --> 
 
-		<!-- The base level context in command mode. Does not allow closing '}' -->
-		<context attribute="Normal Text" lineEndContext="#stay" name="command0">
-			<IncludeRules context="CommandContinuationCheck"/>
+		<!-- This context is really only good for detecting unexpected closing braces '}'. Since opening braces go to ctx0 (and nesting in there), this context is only active on the base level -->
+		<context attribute="Normal Text" lineEndContext="#stay" name="level0">
 			<IncludeRules context="CommonRules"/>
-			<DetectChar attribute="Error" context="#stay" char="}" />
-			<DetectChar attribute="Error" context="#stay" char=")"/>
+
+			<AnyChar attribute="Error" context="#stay" String="})"/>
 		</context>
 		
-		<!-- A nested context in command mode. Closing '}' pops a level -->
-		<context attribute="Normal Text" lineEndContext="#stay" name="command">
-			<IncludeRules context="CommandContinuationCheck"/>
+		<context attribute="Normal Text" lineEndContext="#stay" name="ctx0">
 			<IncludeRules context="CommonRules"/>
-			<DetectChar attribute="Symbol" context="#pop" char="}" />
+
+			<DetectChar attribute="Symbol" context="#pop" char="}" endRegion="Brace1" />
 			<DetectChar attribute="Error" context="#stay" char=")"/>
 		</context>
 
 		<context attribute="Normal Text" lineEndContext="#stay" name="parenthesis">
-			<IncludeRules context="CommandContinuationCheck"/>
 			<DetectChar attribute="Symbol" context="#pop" char=")"/>
 			
-			<RegExpr attribute="Identifier" context="#stay" String="[a-zA-Z_\.][0-9a-zA-Z_\.]*[\s]*=(?=([^=]|$))"/>
+			<RegExpr attribute="Identifier" context="#stay" String="[a-zA-Z_\.][0-9a-zA-Z_\.]*[\s]*[:]?=(?=[^=]|$)"/>
+
 			<IncludeRules context="CommonRules"/>
 			<DetectChar attribute="Error" context="#stay" char="}" />
 		</context>
@@ -208,18 +206,29 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		<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=" "/>
+			<DetectSpaces />
+			<IncludeRules context="FindComments"/>
 			<!-- Operators other than +, -, and ! directly after another operator are an error. -->
-			<RegExpr attribute="Error" context="#stay" String="(\*|/|<|>|\!=|=|\||&|:|\^|@|\$|~)"/>
+			<Detect2Chars attribute="Error" context="#stay" char="!" char1="="/>
+			<AnyChar attribute="Error" context="#stay" String="*/<>=|&:^@$~"/>
+		</context>
+
+		<context attribute="Numeric Suffix" lineEndContext="#pop" name="NumericSuffix" fallthrough="true" fallthroughContext="#pop">
+			<AnyChar attribute="Numeric Suffix" context="#pop" String="Li"/>
 		</context>
 
+
+		<context attribute="Normal Text" lineEndContext="#stay" name="FindComments">
+			<Detect2Chars attribute="Headline" context="Headline" char="#" char1="#"/>
+			<DetectChar attribute="Comment" context="Comment" char="#"/>
+		</context>
 		<context attribute="Headline" lineEndContext="#pop" name="Headline">
-			<IncludeRules context="##Alerts" />
+			<DetectSpaces />
+			<IncludeRules context="##Comments" />
 		</context>
 		<context attribute="Comment" lineEndContext="#pop" name="Comment">
-			<IncludeRules context="##Alerts" />
+			<DetectSpaces />
+			<IncludeRules context="##Comments" />
 		</context>
 
 		<!-- This context is not really used, but meant to be included. It checks whether a new line is a continuation of a command. If so, it eats the "+ " at the line start. Else it tries to pop back to the top level -->
@@ -234,32 +243,44 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 		<!-- This context is not really used, but contains the common rules -->
 		<context name="CommonRules" lineEndContext="#stay" attribute="Normal Text" >
+			<IncludeRules context="CommandContinuationCheck"/>
+			<DetectSpaces />
+			<IncludeRules context="FindComments"/>
 			<DetectChar attribute="String" context="string" char="""/>
 			<DetectChar attribute="String" context="string2" char="'"/>
 			<DetectChar attribute="String" context="backquotedsymbol" char="`"/>
 			<keyword attribute="Control Structure" context="#stay" String="controls"/>
 			<keyword attribute="Reserved Words" context="#stay" String="words"/>
-			<!-- No need to distinguish Int and Float in R, but Float should include scientific notations -->
-			<RegExpr attribute="Float" context="#stay" String="(\b[0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?"/>
-			<RegExpr attribute="Keyword" context="#stay" String="[a-zA-Z_]+[a-zA-Z_\.0-9]*(?=[\s]*[(])"/>
-			<RegExpr attribute="Keyword" context="#stay" String="\.[a-zA-Z_\.]+[a-zA-Z_\.0-9]*(?=[\s]*[(])"/>
-			<RegExpr attribute="Symbol" context="parenthesis" String="\("/>
-			<StringDetect attribute="Headline" context="Headline" String="##"/>
-			<DetectChar attribute="Comment" context="Comment" char="#"/>
-			
+			<Float attribute="Float" context="#stay"/>
+			<Int attribute="Int" context="NumericSuffix"/>
+			<RegExpr attribute="Keyword" context="#stay" String="[a-zA-Z_]+[a-zA-Z_\.0-9]*(?=[\s]*[(])|\.[a-zA-Z_\.]+[a-zA-Z_\.0-9]*(?=[\s]*[(])"/>
+			<DetectChar attribute="Symbol" context="parenthesis" char="("/>
+
 			<!-- 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,3}|\^|@|\$|~)"/>
-			<RegExpr attribute="Operator" context="operator_rhs" String="%[^%]*%"/>
+			<StringDetect attribute="Assign" context="operator_rhs" String="<<-"/>
+			<Detect2Chars attribute="Assign" context="operator_rhs" char="<" char1="-"/>
+			<StringDetect attribute="Assign" context="operator_rhs" String="->>"/>
+			<Detect2Chars attribute="Assign" context="operator_rhs" char="-" char1=">"/>
+			<RegExpr attribute="Assign" context="operator_rhs" String="=(?!(=|>))"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="*" char1="*"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="<" char1="="/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char=">" char1="="/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="=" char1="="/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="=" char1=">"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="!" char1="="/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="|" char1=">"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="|" char1="|"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char="&" char1="&"/>
+			<StringDetect attribute="Operator" context="operator_rhs" String=":::"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char=":" char1=":"/>
+			<Detect2Chars attribute="Operator" context="operator_rhs" char=":" char1="="/>
+			<AnyChar attribute="Operator" context="operator_rhs" String="+-*/<>=!|&:^@$~"/>
+			<RangeDetect attribute="Operator" context="operator_rhs" char="%" char1="%"/>
+
+			<DetectChar attribute="Symbol" context="ctx0" char="{" beginRegion="Brace1" />
 
-			<!-- 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 is needed only to assist variable based indentation -->
-			<DetectChar attribute="Symbol" context="#stay" char="[" />
-			<DetectChar attribute="Symbol" context="#stay" char="]" />
+			<AnyChar attribute="Symbol" context="#stay" String="[]" />
 		</context>
 	</contexts>
 
@@ -284,28 +305,31 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		<itemData name="Output StrView Index" defStyleNum="dsComment"/>
 		<itemData name="Output StrView Highlight" defStyleNum="dsSpecialChar"/>
 		
-		<itemData name="Prompt" defStyleNum="dsNormal"/>
-		<itemData name="Normal Text" defStyleNum="dsNormal"/>
-		<itemData name="Symbol" defStyleNum="dsNormal"/>
-		<itemData name="Keyword" defStyleNum="dsKeyword"/>
-		<itemData name="Identifier" defStyleNum="dsDataType"/>
+		<itemData name="Prompt" defStyleNum="dsNormal" spellChecking="false"/>
+		<itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false"/>
+		<itemData name="Symbol" defStyleNum="dsNormal" spellChecking="false"/>
+		<itemData name="Keyword" defStyleNum="dsFunction" spellChecking="false"/>
+		<itemData name="Identifier" defStyleNum="dsAttribute" spellChecking="false"/>
 		<itemData name="String" defStyleNum="dsString"/>
-		<itemData name="Headline" defStyleNum="dsComment" color="#b00000" selColor="#b00000" bold="1" italic="0"/> <!-- KDE default color: text 5 -->
+		<itemData name="Headline" defStyleNum="dsDocumentation" bold="1"/>
 		<itemData name="Comment" defStyleNum="dsComment"/>
-		<itemData name="Assign" defStyleNum="dsNormal" color="#336366" selColor="#ccc099" bold="1" italic="0"/> <!-- KDE default color: text 7 -->
-		<itemData name="Control Structure" defStyleNum="dsControlFlow"/>
-		<itemData name="Reserved Words" defStyleNum="dsOthers"/>
-		<itemData name="Error" defStyleNum="dsError"/>
-		<itemData name="Operator" defStyleNum="dsOperator"/>
-		<itemData name="String Char"  defStyleNum="dsChar"/>
-		<itemData name="Float" defStyleNum="dsFloat"/>
+		<itemData name="Assign" defStyleNum="dsOthers" bold="1" italic="0" spellChecking="false"/>
+		<itemData name="Control Structure" defStyleNum="dsControlFlow" spellChecking="false"/>
+		<itemData name="Reserved Words" defStyleNum="dsConstant" spellChecking="false"/>
+		<itemData name="Error" defStyleNum="dsError" spellChecking="false"/>
+		<itemData name="Operator" defStyleNum="dsSpecialChar" spellChecking="false"/>
+		<itemData name="String Char"  defStyleNum="dsSpecialChar" spellChecking="false"/>
+		<itemData name="Float" defStyleNum="dsFloat" spellChecking="false"/>
+		<itemData name="Int" defStyleNum="dsDecVal" spellChecking="false"/>
+		<itemData name="Numeric Suffix" defStyleNum="dsDataType" spellChecking="false"/>
 	</itemDatas>
 </highlighting>
 
 <general>
 	<comments>
-		<comment name="singleLine" start="#" end=""/>
+		<comment name="singleLine" start="#"/>
 	</comments>
 	<keywords casesensitive="true" weakDeliminator="." additionalDeliminator="$"/>
 </general>
 </language>
+<!-- kate: replace-tabs off; -->



More information about the rkward-tracker mailing list