<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language
[
	<!ENTITY datetime "(?:(?:.\[)?(?:\d{1,2};){2}\d{1,3}m\s*)?(?:(?:\d{4}\-)?\d{2}\-\d{2}\s\d{2}(?:\:\d{2}){2}\.\d{3,6}(?:\s[\-\+]\d{4})?|\d+\.\d{3,6})\:?">
	<!ENTITY priority_tag "(?:[/\s][^:\(]*(?:\([^\)]+\))?:|\([^\)]+\):?)"> <!-- Tag/PID/Threads -->
	<!ENTITY delim        "[/\(\s]"> <!-- Delimiter between priority and tag -->
]>

<!--
   Logcat Syntax Highlighting Definition
  ===========================================================================

   This file is part of the KDE's KSyntaxHighlighting framework.

   SPDX-FileCopyrightText: 2018-2020 Nibaldo González S. <nibgonz@gmail.com>

   SPDX-License-Identifier: MIT

  ===========================================================================

  Last update: September 30, 2020 (v6)
-->

<language name="Logcat"
          version="9"
          kateversion="5.0"
          section="Other"
          extensions="*.logcat"
          mimetype="text/x-logcat"
          priority="5"
          author="Nibaldo González (nibgonz@gmail.com)"
          license="MIT">

	<highlighting>

		<contexts>

			<context name="Normal" attribute="Normal Text" lineEndContext="#stay">
				<DetectChar   context="CommentLine" attribute="Comment" char="#" firstNonSpace="true" />
				<StringDetect context="CommentLine" attribute="Comment" String="---------" firstNonSpace="true" />
				<RegExpr      context="#stay"       attribute="Comment" String="^\*\s.+\s\*$" column="0" />

				<RegExpr context="#stay" attribute="DateTime" String="&datetime;" firstNonSpace="true" />

				<!-- Priority & Tag -->
				<RegExpr context="VerboseMsg" attribute="Verbose Tag" String="(?:^|\s)[V\?](?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="DebugMsg"   attribute="Debug Tag"   String="(?:^|\s)D(?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="InfoMsg"    attribute="Info Tag"    String="(?:^|\s)I(?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="WarningMsg" attribute="Warning Tag" String="(?:^|\s)W(?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="AssertMsg"  attribute="Assert Tag"  String="(?:^|\s)A(?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="SilentMsg"  attribute="Silent Tag"  String="(?:^|\s)S(?:&priority_tag;|(?=&delim;))" />
				<RegExpr context="ErrorMsg"   attribute="Error Tag"   String="(?:^|\s)E(?:&priority_tag;|(?=&delim;))" />

				<RegExpr context="#stay"      attribute="Error Tag"   String="\sF&delim;.*\033\[\d{1,3}m$" />
				<RegExpr context="FatalMsg"   attribute="Fatal"       String="^F&delim;" column="0" />
				<RegExpr context="FatalMsg"   attribute="Normal Text" String="\s(?=F&delim;)" />

				<!-- For "-v long" -->
				<DetectChar context="LongLog" attribute="Normal Text" char="[" column="0" />
			</context>

			<context name="CommentLine" attribute="Comment" lineEndContext="#pop">
				<DetectSpaces />
				<IncludeRules context="##Comments" />
			</context>

			<context name="VerboseMsg" attribute="Verbose Message" lineEndContext="#pop" />
			<context name="DebugMsg"   attribute="Debug Message"   lineEndContext="#pop" />
			<context name="InfoMsg"    attribute="Info Message"    lineEndContext="#pop" />
			<context name="WarningMsg" attribute="Warning Message" lineEndContext="#pop" />
			<context name="AssertMsg"  attribute="Assert Message"  lineEndContext="#pop" />
			<context name="SilentMsg"  attribute="Silent Message"  lineEndContext="#pop" />
			<context name="ErrorMsg"   attribute="Error Message"   lineEndContext="#pop" />
			<context name="FatalMsg"   attribute="Fatal"           lineEndContext="#pop" />

			<!-- Long Format -->

			<context name="LongLog" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
				<RegExpr context="#pop!LongLogTag" attribute="DateTime" String="\s+&datetime;(?=\s.+\s\]$)" />
			</context>
			<context name="LongLogTag" attribute="Normal Text" lineEndContext="#pop">
				<RegExpr context="#pop!LongLogVerbose" attribute="Verbose Tag" String="\s[V\?]&delim;" />
				<RegExpr context="#pop!LongLogDebug"   attribute="Debug Tag"   String="\sD&delim;" />
				<RegExpr context="#pop!LongLogInfo"    attribute="Info Tag"    String="\sI&delim;" />
				<RegExpr context="#pop!LongLogWarning" attribute="Warning Tag" String="\sW&delim;" />
				<RegExpr context="#pop!LongLogAssert"  attribute="Assert Tag"  String="\sA&delim;" />
				<RegExpr context="#pop!LongLogSilent"  attribute="Silent Tag"  String="\sS&delim;" />
				<RegExpr context="#pop!LongLogError"   attribute="Error Tag"   String="\sE&delim;" />
				<RegExpr context="#pop!LongLogFatal"   attribute="Normal Text" String="\s(?=F&delim;)" />
			</context>

			<context name="LongLogVerbose" attribute="Verbose Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogVerboseMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogDebug" attribute="Debug Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogDebugMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogInfo" attribute="Info Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogInfoMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogWarning" attribute="Warning Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogWarningMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogAssert" attribute="Assert Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogAssertMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogSilent" attribute="Silent Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogSilentMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogError" attribute="Error Tag" lineEndContext="#pop">
				<LineContinue context="#pop!LongLogErrorMsg" attribute="Normal Text" char="]" />
			</context>
			<context name="LongLogFatal" attribute="Fatal" lineEndContext="#pop">
				<RegExpr context="#pop!LongLogFatalMsg" attribute="Normal Text" String="\s*\]$" />
			</context>

			<context name="LongLogVerboseMsg" attribute="Verbose Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogDebugMsg" attribute="Debug Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogInfoMsg" attribute="Info Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogWarningMsg" attribute="Warning Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogAssertMsg" attribute="Assert Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogSilentMsg" attribute="Silent Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogErrorMsg" attribute="Error Message" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="LongLogFatalMsg" attribute="Fatal" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<IncludeRules context="DefaultLongLogMsg" />
			</context>
			<context name="DefaultLongLogMsg" attribute="Normal Text" lineEndContext="#stay" lineEmptyContext="EmptyLine">
				<StringDetect context="#pop!CommentLine" attribute="Comment" String="---------" firstNonSpace="true" />
				<RegExpr context="#pop" attribute="Comment" String="^\*\s.+\s\*$" column="0" />
				<RegExpr context="#pop!LongLog" attribute="Normal Text" String="^\[(?=\s+&datetime;\s.+\s\]$)" column="0" />
				<RegExpr context="EmptyLine" attribute="Normal Text" String="^\s*$" column="0" />
			</context>
			<context name="EmptyLine" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
				<DetectChar context="#pop#pop!CommentLine" attribute="Comment" char="#" firstNonSpace="true" />
				<RegExpr context="#pop#pop!LongLog" attribute="Normal Text" String="^\[(?=\s.+\s\]$)" column="0" />
				<!-- In a normal Log this is not necessary, but probably some people put items of Logs
				     of different formats in a single file. -->
				<RegExpr context="#pop#pop" attribute="DateTime" String="&datetime;" firstNonSpace="true" />
				<!-- NOTE: Use "^\s*" with lookAhead, not firstNonSpace -->
				<RegExpr context="#pop#pop" attribute="Normal Text" String="^\s*[VDIWASEF\?]&priority_tag;" column="0" lookAhead="true" minimal="1" />
				<DetectSpaces />
			</context>

		</contexts>

		<itemDatas>
			<itemData name="Normal Text" defStyleNum="dsNormal"  spellChecking="false" />
			<itemData name="Comment"     defStyleNum="dsComment" italic="1" />
			<itemData name="DateTime"    defStyleNum="dsComment" italic="0" underline="0" spellChecking="false" />

			<itemData name="Verbose Tag"     defStyleNum="dsNormal"         bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Verbose Message" defStyleNum="dsNormal"         bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Debug Tag"       defStyleNum="dsAttribute"      bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Debug Message"   defStyleNum="dsAttribute"      bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Info Tag"        defStyleNum="dsPreprocessor"   bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Info Message"    defStyleNum="dsPreprocessor"   bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Warning Tag"     defStyleNum="dsInformation"    bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Warning Message" defStyleNum="dsInformation"    bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Assert Tag"      defStyleNum="dsChar"           bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Assert Message"  defStyleNum="dsChar"           bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Silent Tag"      defStyleNum="dsBuiltIn"        bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Silent Message"  defStyleNum="dsBuiltIn"        bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Error Tag"       defStyleNum="dsError"          bold="1" italic="0" underline="0" strikeOut="0" />
			<itemData name="Error Message"   defStyleNum="dsError"          bold="0" italic="0" underline="0" strikeOut="0" />
			<itemData name="Fatal"           defStyleNum="dsAlert"          bold="1" italic="0" underline="0" strikeOut="0" />
		</itemDatas>

	</highlighting>

	<general>
		<comments>
			<comment name="singleLine" start="#" />
		</comments>

		<emptyLines>
			<emptyLine regexpr="\s+"/>
		</emptyLines>
	</general>

</language>
<!-- kate: replace-tabs off; remove-trailing-spaces mod; dynamic-word-wrap off; -->
