[education/rkward/mr-origin-23] rkward/syntax: More robust handling of tibble output using a dedicated context

Thomas Friedrichsmeier null at kde.org
Wed Oct 18 17:24:53 BST 2023


Git commit a08c5a4333923d997969fae5cbf25b441f67b69b by Thomas Friedrichsmeier, on behalf of Pierre de Villemereuil.
Committed on 18/10/2023 at 18:23.
Pushed by tfry into branch 'mr-origin-23'.

More robust handling of tibble output using a dedicated context

M  +23   -2    rkward/syntax/rkward.xml

https://invent.kde.org/education/rkward/-/commit/a08c5a4333923d997969fae5cbf25b441f67b69b

diff --git a/rkward/syntax/rkward.xml b/rkward/syntax/rkward.xml
index ecc929a39..1fc3b42a5 100644
--- a/rkward/syntax/rkward.xml
+++ b/rkward/syntax/rkward.xml
@@ -77,6 +77,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		<context attribute="Output Error" lineEndContext="#pop" name="Output Error">
 		</context>
 		
+		<!-- Special context for tibble output -->
+		<context attribute="Output Tibble" lineEndContext="#stay" name="outputtibble">
+			<!-- If a "> " is encountered at line start, pop back to ctxbase (and to command0 from there) -->
+			<Detect2Chars attribute="Prompt" context="#pop" char=">" char1=" " column="0" lookAhead="true" endRegion="commandRegion"/>
+			
+			<!-- If a "# " is encountered at line start, pop back to output context -->
+			<StringDetect attribute="Prompt" context="#pop" String="# …" column="0" lookAhead="true" endRegion="commandRegion"/>
+			
+			<!-- Tibble special highlights -->
+			<DetectChar attribute="Output Comment" context="Output Comment" char="#" column="0"/>
+			<RegExpr attribute="Output Data Type" context="#stay" String="<(lgl|int|dbl|chr|cpl|raw|list|named list|fct|ord|date|dttm|drtn|time|int64|blob|df\[\,1\]|tibble\[\,1\]|I|\?\?\?|list<.+>|vctrs_vc|prtl_fctr|prtl|fn|sym|expression|quos)>"/>
+			<RegExpr attribute="Output Index" context="#stay" String="[ ]{0,2}[0-9]+" column="0"/>
+			<!-- Common highlights -->
+			<RegExpr attribute="Output Float" context="#stay" String="(?<=<|>|\(|\[| |^)-?([1-9][0-9]*|0)(\.[0-9]*)?i?(e[-+]?[ ]{0,3}[0-9]+)?(?![0-9a-zA-Z/_\~\-\]+]|[.,;:][^ \t])"/>
+			<WordDetect attribute="Output NA" context="#stay" String="NA"/>
+			<WordDetect attribute="Output True" context="#stay" String="TRUE"/>
+			<WordDetect attribute="Output False" context="#stay" String="FALSE"/>
+		</context>
+		
 		<!-- Special context for str_view() -->
 		<context attribute="Output StrView" lineEndContext="#pop" name="outputstrview">
 			<IncludeRules context="OutputContinuationCheck"/>
@@ -97,6 +116,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
 			<DetectChar attribute="Output String" context="outputstring" char="""/>
 			<RegExpr attribute="Output StrView Index" context="outputstrview" String="([ ]*\[[0-9]+\] )?│" firstNonSpace="true"/>
 			
+			<!-- Tibble = special highlights -->
+			<RegExpr attribute="Output Comment" context="outputtibble" String="# A tibble: .*$"/>
+			
 			<!-- Full-line highlights (see above) -->
 			<Detect2Chars attribute="Output Headline" context="Output Headline" char="#" char1="#" column="0"/>
 			<Detect2Chars attribute="Output Headline" context="Output Headline" char="─" char1="─" column="0"/>
@@ -109,8 +131,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 			<DetectChar attribute="Output Comment" context="Output Comment" char="#" column="0"/>
 			
 			<!-- Other specials highlights -->
-			<RegExpr attribute="Output Data Type" context="#stay" String="<(lgl|int|dbl|chr|cpl|raw|list|named list|fct|ord|date|dttm|drtn|time|int64|blob|df\[\,1\]|tibble\[\,1\]|I|\?\?\?|list<.+>|vctrs_vc|prtl_fctr|prtl|fn|sym|expression|quos)>"/>
-			<RegExpr attribute="Output Index" context="#stay" String="([ ]{0,2}|[ ]*\[)[0-9]+,?[0-9]*\]?\:?(?![.0-9]|.*[:,.;]$)" column="0"/>
+			<RegExpr attribute="Output Index" context="#stay" String="([ ]{0,2}|[ ]*\[)[0-9]+,?[0-9]*(\]|\: )(?![.0-9]|.*[:,.;]$)" column="0"/>
 			<RegExpr attribute="Output Index" context="#stay" String="([ ]+\[,[1-9]+[0-9]*\])+$" column="0"/>
 			<!-- Floats are hard to catch in R Output -->
 			<RegExpr attribute="Output Float" context="#stay" String="(?<=<|>|\(|\[| |^)-?([1-9][0-9]*|0)(\.[0-9]*)?i?(e[-+]?[ ]{0,3}[0-9]+)?(?![0-9a-zA-Z/_\~\-\]+]|[.,;:][^ \t])"/>



More information about the rkward-tracker mailing list