<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
	<!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 -->
]>

<!--
  Syntax Highlighting Definition of Logcat, for the KDE's KSyntaxHighlighting Framework
  ==========================================================================================
   This file is part of the KDE's KSyntaxHighlighting framework.

   Copyright (c) 2018-2019 Nibaldo González S. (nibgonz@gmail.com)

   Permission is hereby granted, free of charge, to any person obtaining a copy of this
   software and associated documentation files (the "Software"), to deal in the Software
   without restriction, including without limitation the rights to use, copy, modify, merge,
   publish, distribute, sublicense, and/or sell copies of the Software, and to permit
   persons to whom the Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
   COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  ==========================================================================================

  Last update: October 25, 2019 (v5)
-->

<language name="Logcat"
          version="5"
          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;" />
				<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="##Alerts" />
				<IncludeRules context="##Modelines" />
			</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" />
				<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" />
			<itemData name="Verbose Message" defStyleNum="dsNormal"         bold="0" />
			<itemData name="Debug Tag"       defStyleNum="dsAttribute"      bold="1" />
			<itemData name="Debug Message"   defStyleNum="dsAttribute"      bold="0" />
			<itemData name="Info Tag"        defStyleNum="dsPreprocessor"   bold="1" />
			<itemData name="Info Message"    defStyleNum="dsPreprocessor"   bold="0" />
			<itemData name="Warning Tag"     defStyleNum="dsInformation"    bold="1" />
			<itemData name="Warning Message" defStyleNum="dsInformation"    bold="0" />
			<itemData name="Assert Tag"      defStyleNum="dsChar"           bold="1" />
			<itemData name="Assert Message"  defStyleNum="dsChar"           bold="0" />
			<itemData name="Silent Tag"      defStyleNum="dsBuiltIn"        bold="1" />
			<itemData name="Silent Message"  defStyleNum="dsBuiltIn"        bold="0" />
			<itemData name="Error Tag"       defStyleNum="dsError"          bold="1" underline="0" />
			<itemData name="Error Message"   defStyleNum="dsError"          bold="0" underline="0" />
			<itemData name="Fatal"           defStyleNum="dsAlert"          bold="1" />
		</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; -->
