<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!-- Kate 2.0 (KDE 3.0) highlighting module for RKWard
	version 2.0: (c) 2006 P. Ecochard
	lincense: GPL v2
	Based on the highlighting module for R version 2.0: (c) 2006 Thomas Friedrichsmeier, Arne Henningsen, and the RKWard Team
	
	Kate   : http://kate.kde.org/
	R      : http://www.r-project.org/
	RKWard : http://rkward.sourceforge.net/
	-->
<language version="2.02" kateversion="2.5" name="RKWard output" section="Scripts" extensions="" mimetype="" author="P. Ecochard" license="GPL">
<highlighting>
	<list name="controls">
	<item> for </item>
	<item> in </item>
	<item> next </item>
	<item> break </item>
	<item> while </item>
	<item> repeat </item>
	<item> if </item>
	<item> else </item>
	<item> switch </item>
	<item> function </item>
	</list>
	<list name="words">
	<item> TRUE </item>
	<item> FALSE </item>
	<item> NULL </item>
	<item> NA </item>
	<item> NA_integer_ </item>
	<item> NA_real_ </item>
	<item> NA_complex_ </item>
	<item> NA_character_ </item>
	<item> Inf </item>
	<item> NaN </item>
	</list>
	
	<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="&gt;" char1=" " column="0" beginRegion="commandRegion"/>
			<RegExpr attribute="Normal Text" context="output" String="^([^&gt;\+]|$)" lookAhead="true"/>
		</context>

		<!-- The output context does no highlighting. If a "> " is encountered at line start, pop back to ctxbase (and to command0 from there) --> 
		<context attribute="Output" lineEndContext="#stay" name="output">
			<Detect2Chars attribute="Prompt" context="#pop" char="&gt;" char1=" " column="0" lookAhead="true" endRegion="commandRegion"/>
		</context>

		<!-- The base level context in command mode. Does not allow closing '}' -->
		<context attribute="Normal Text" lineEndContext="#stay" name="command0">
			<IncludeRules context="CommandContinuationCheck"/>
			<IncludeRules context="CommonRules"/>
			<DetectChar attribute="Error" context="#stay" char="}" />
			<DetectChar attribute="Error" context="#stay" char=")"/>
		</context>
		
		<!-- A nested context in command mode. Closing '}' pops a level -->
		<context attribute="Normal Text" lineEndContext="#stay" name="command">
			<IncludeRules context="CommandContinuationCheck"/>
			<IncludeRules context="CommonRules"/>
			<DetectChar attribute="Symbol" context="#pop" char="}" />
			<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]*=(?=([^=]|$))"/>
			
			<IncludeRules context="CommonRules"/>
			<DetectChar attribute="Error" context="#stay" char="}" />
		</context>

		<context attribute="String" lineEndContext="#stay" name="string">
			<IncludeRules context="CommandContinuationCheck"/>
			<DetectChar attribute="String" context="#pop" char="&quot;"/>
			<HlCStringChar attribute="String Char" context="#stay"/>
		</context>

		<context attribute="String" lineEndContext="#stay" name="string2">
			<IncludeRules context="CommandContinuationCheck"/>
			<DetectChar attribute="String" context="#pop" char="'"/>
			<HlCStringChar attribute="String Char" context="#stay"/>
		</context>

		<context attribute="Identifier" lineEndContext="#stay" name="backquotedsymbol">
			<IncludeRules context="CommandContinuationCheck"/>
			<DetectChar attribute="String" context="#pop" char="`"/>
			<HlCStringChar attribute="String Char" context="#stay"/>
		</context>

		<context attribute="Headline" lineEndContext="#pop" name="Headline"/>
		<context attribute="Comment" lineEndContext="#pop" name="Comment"/>

		<!-- 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 -->
		<context attribute="Normal Text" name="CommandContinuationCheck" lineEndContext="#stay">
			<!-- Since this rule is included in every (relevant) context, this will unwind the entire context stack back to ctxbase. -->
			<RegExpr attribute="Prompt" context="#pop" String="^&gt; " lookAhead="true" endRegion="commandRegion"/>
			<!-- See above -->
			<RegExpr attribute="Normal Text" context="#pop" String="^([^\+]|$)" lookAhead="true"/>
			<RegExpr attribute="Prompt" 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="&quot;"/>
			<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"/>
			<Float attribute="Float" context="#stay"/>
			<Int attribute="Int" context="#stay"/>
			<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="#"/>
			
			<!-- 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="([\+\-\*/\^\:\$~!&amp;\|=&gt;@^])([&lt;]{1,2}\-|\-[&gt;]{1,2})"/>
			<RegExpr attribute="Error" context="#stay" String="([&lt;]{1,2}\-|\-[&gt;]{1,2})([\+\-\*/\^\:\$~!&amp;\|=&lt;@])"/>
			<RegExpr attribute="Error" context="#stay" String="([&lt;]{3}|[&gt;]{3})"/>
			<RegExpr attribute="Assign" context="#stay" String="[&lt;]{1,2}\-"/>
			<RegExpr attribute="Assign" context="#stay" String="\-[&gt;]{1,2}"/>
			<!-- Much like above: Most other operators are forbidden around = -->
			<RegExpr attribute="Error" context="#stay" String="([\+\-\*/\^\:\$~&amp;\|@^])="/>
			<RegExpr attribute="Error" context="#stay" String="=([\+\-\*/\^\:\$~!&lt;&gt;&amp;\|@^])"/>
			<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="(\+|\-|\*|/|&lt;=|&gt;=|={1,2}|\!=|\|{1,2}|&amp;{1,2}|:{1,3}|\^|@|\$|~)((?!(\+|\-|\*|/|&lt;=|&gt;=|=|\!=|\||&amp;|:|\^|@|\$|~))|$)"/>
			<RegExpr attribute="Error" context="#stay" String="(\+|\-|\*|/|&lt;=|&gt;=|={1,2}|\!=|\|{1,2}|&amp;{1,2}|:{1,3}|\^|@|\$|~){2,}"/>	
			<RegExpr attribute="Operator" context="#stay" 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 is needed only to assist variable based indentation -->
			<DetectChar attribute="Symbol" context="#stay" char="[" />
			<DetectChar attribute="Symbol" context="#stay" char="]" />
		</context>
	</contexts>

	<itemDatas>
		<itemData name="Output" defStyleNum="dsOthers"/>
		<!-- KDE default colors: http://accessibility.kde.org/oxygen.php?color=white -->
		<itemData name="Normal Text" defStyleNum="dsNormal"/>
		<itemData name="Symbol" defStyleNum="dsNormal"/>
		<itemData name="Prompt" defStyleNum="dsNormal"/>
		<itemData name="Keyword" defStyleNum="dsKeyword"/>
		<itemData name="Identifier" defStyleNum="dsDataType"/>
		<itemData name="String" defStyleNum="dsString"/>
		<itemData name="Headline" defStyleNum="dsNormal" color="#b00000" selColor="#b00000" bold="1" italic="0"/> <!-- KDE default color: text 5 -->
		<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="dsNormal" color="#0000bf" selColor="#bfbf00"/> <!-- KDE default color: text 2 -->
		<itemData name="Reserved Words" defStyleNum="dsOthers"/>
		<itemData name="Error" defStyleNum="dsError"/>
		<itemData name="Operator" defStyleNum="dsNormal"  color="#803f00" selColor="#000077" bold="0" italic="0"/> <!-- KDE default color: focussed text -->
		<itemData name="String Char"  defStyleNum="dsChar"/>
		<itemData name="Float" defStyleNum="dsFloat"/>
		<itemData name="Int" defStyleNum="dsDecVal"/>
	</itemDatas>
</highlighting>

<general>
	<comments>
		<comment name="singleLine" start="#" end=""/>
	</comments>
	<keywords casesensitive="1" />
</general>
</language>
