<?xml version='1.0' encoding='UTF-8'?>
<!--
 [ʞ] cortav.xml
  ~ lexi hale <lexi@hale.su>
  © AGPLv3
  ? Kate/kwrite-compatible syntax definition for the cortav markup format
  > ln cortav.xml $HOME/.local/share/org.kde.syntax-highlighting/syntax/
-->
<language name='Cortav' version='1' kateversion='2.4' section='Markup' extensions='*.ct'>
	<highlighting>
		<list name='extension-directives'>
			<item>uses</item>
			<item>needs</item>
			<item>inhibits</item>
		</list>
		<list name='renderer-directives'>
			<item>html</item>
			<item>groff</item>
			<item>ps</item>
			<item>tex</item>
			<item>plaintext</item>
			<item>rtf</item>
			<item>svg</item>
		</list>
		<contexts>
			<context name='init' attribute='Normal Text' lineEndContext='#pop' fallthroughContext='text'>
				<RegExpr String='\\.' attribute='Escaped Char'/>
				<RegExpr attribute='Section Cue' context='sec-ident' String='(#|§)+' firstNonSpace='true' />
				<StringDetect String='~~~' attribute='Literal Block Cue' firstNonSpace='true' context='literal-block-cue'/>
				<RegExpr attribute='List' String='[\*:]+' firstNonSpace='true' context='text' />
				<Detect2Chars char='%' char1='!' attribute='Critical Directive Cue' context='directive'/>
				<DetectChar char='%' attribute='Directive Cue' context='directive'/>
				<DetectChar char='&#9;' attribute='Normal Text' context='refdef-id'/>
			</context>

			<context name='sec-ident' attribute='Identifier' lineEndContext='#pop'>
				<DetectSpaces context='#pop!sec' attribute='Normal Text'/>
			</context>

			<context name='sec' attribute='Header' lineEndContext='#pop'>
				<IncludeRules context='text'/>
			</context>

			<context name='refdef-id' attribute='Identifier' lineEndContext='#pop'>
				<DetectChar char=':' attribute='Normal Text' context='#pop!refdef'/>
			</context>
			<context name='refdef' attribute='Styled Text' lineEndContext='#pop'>
			</context>

			<context name='directive' attribute='Directive' lineEndContext='#pop'>
				<keyword attribute='Extension Directive' String='extension-directives'/>
				<keyword attribute='Renderer Directive' String='renderer-directives'/>
			</context>

			<context name='text' attribute='Normal Text' lineEndContext='#pop'>
				<RegExpr String='\\.' attribute='Escaped Char'/>
				<DetectChar attribute='Span Delimiter' context='span-cue' char='['/>
				<DetectChar attribute='Macro Delimiter' context='macro' char='{'/>
			</context>

			<context name='span' attribute='Styled Text' lineEndContext='#pop'>
				<IncludeRules context='text'/>
				<DetectChar attribute='Span Delimiter' context='#pop' char=']'/>
			</context>

			<context name='macro' attribute='Macro' lineEndContext='#pop'>
				<DetectSpaces context='#pop!macro-body'/>
				<DetectChar attribute='Macro Delimiter' char='}' context='#pop'/>
			</context>

			<context name='macro-body' attribute='Styled Text' lineEndContext='#pop'>
				<RegExpr String='\\.' attribute='Escaped Char'/>
				<DetectChar attribute='Field Delimiter' char='|'/>
				<DetectChar attribute='Macro Delimiter' char='}' context='#pop'/>
				<IncludeRules context='span'/>
			</context>

			<context name='span-emph' attribute='Emphatic Text' lineEndContext='#pop'>
				<IncludeRules context='span'/>
			</context>

			<context name='span-strong' attribute='Strong Text' lineEndContext='#pop'>
				<IncludeRules context='span'/>
			</context>

			<context name='span-del' attribute='Deleted Text' lineEndContext='#pop'>
				<IncludeRules context='span'/>
			</context>

			<context name='span-cue' attribute='Span Cue' lineEndContext='#pop'>
				<StringDetect attribute='Span Cue' String='$\' context='#pop!flat-span' />

				<DetectChar   attribute='Span Cue' char='!' context='#pop!span-emph' />
				<DetectChar   attribute='Span Cue' char='*' context='#pop!span-strong' />
				<DetectChar   attribute='Span Cue' char='~' context='#pop!span-del' />

				<AnyChar      attribute='Span Cue' String='$+🔒' context='#pop!span' />
				<StringDetect attribute='Span Cue' String='→' context='#pop!ref' />
				<StringDetect attribute='Span Cue' String='🔗' context='#pop!ref' />
				<DetectChar   attribute='Span Cue' char='>' context='#pop!ref' />
				<DetectChar   attribute='Span Cue' char='&amp;' context='#pop!ref' />
				<DetectChar   attribute='Span Cue' char='#' context='#pop!var-ref' />
				<DetectChar   attribute='Span Cue' char='\' context='#pop!flat-span' />
			</context>

			<context name='flat-span' attribute='Unstyled Text' lineEndContext='#pop'>
				<Detect2Chars attribute='Escaped Char' context='#stay' char='\' char1=']'/>
				<DetectChar attribute='Span Delimiter' context='#pop' char=']'/>
			</context>

			<context name='ref' attribute='Reference' lineEndContext='#pop'>
				<DetectSpaces context='#pop!span'/>
			</context>

			<context name='var-ref' attribute='Reference' lineEndContext='#pop'>
				<WordDetect String="cortav" attribute='Standard Namespace'/>
				<WordDetect String="env" attribute='Standard Namespace'/>
				<DetectChar attribute='Span Delimiter' context='#pop' char=']'/>
			</context>

			<context name='literal-block-cue' attribute='Literal Block Cue' lineEndContext='#pop!literal-block'>
				<RegExpr String='\[[^\]]+\]' attribute='External Reference'/>
				<RegExpr String='#[^\s]+' attribute='Identifier'/>
				<RegExpr String='~~~$' attribute='Literal Block Cue'/>
				<RegExpr String='[^\s]+' attribute='Header'/>
			</context>
			<context name='literal-block' attribute='Literal Block' lineEndContext='#stay'>
				<RegExpr String='~~~$' attribute='Literal Block Cue' firstNonSpace='true' context='#pop'/>
			</context>
		</contexts>
		<itemDatas>
			<itemData name='Normal Text' defStyleNum='dsNormal'/>
			<itemData name='Styled Text' defStyleNum='dsNormal'/>
			<itemData name='Emphatic Text' defStyleNum='dsNormal' italic='true'/>
			<itemData name='Strong Text' defStyleNum='dsNormal' bold='true'/>
			<itemData name='Deleted Text' defStyleNum='dsNormal' strikeout='true'/>
				
			<itemData name='Section Cue' defStyleNum='dsKeyword' bold='true'/>
			<itemData name='Header' defStyleNum='dsControlFlow' underline='true'/>
			<itemData name='Identifier' defStyleNum='dsVariable'/>

			<itemData name='Unstyled Text' defStyleNum='dsVerbatimString'/>
			<itemData name='Escaped Char' defStyleNum='dsSpecialChar'/>
			<itemData name='Reference' defStyleNum='dsControlFlow' underline='true'/>
			<itemData name='Span Cue' defStyleNum='dsKeyword' bold='true'/>
			<itemData name='Span Delimiter' defStyleNum='dsKeyword'/>
			<itemData name='Directive' defStyleNum='dsAttribute' bold='true'/>
			<itemData name='Directive Cue' defStyleNum='dsAttribute'/>
			<itemData name='Critical Directive Cue' defStyleNum='dsImport' bold='true'/>
			<itemData name='Extension Directive' defStyleNum='dsImport' bold='true'/>
			<itemData name='Renderer Directive' defStyleNum='dsExtension' bold='true'/>
			<itemData name='Standard Namespace' defStyleNum='dsBuiltIn' bold='true'/>
			<itemData name='Comment' defStyleNum='dsComment'/>
			<itemData name='Macro' defStyleNum='dsPreprocessor' bold='true'/>
			<itemData name='Macro Delimiter' defStyleNum='dsPreprocessor'/>
			<itemData name='Field Delimiter' defStyleNum='dsPreprocessor' bold='true'/>
			<itemData name='List' defStyleNum='dsOperator'/>

			<itemData name='Literal Block' defStyleNum='dsSpecialString'/>
			<itemData name='Literal Block Cue' defStyleNum='dsPreprocessor' bold='true'/>

			<itemData name='External Reference' defStyleNum='dsImport'/>
		</itemDatas>
	</highlighting>
	<general>
		<comments>
			<comment name='singleLine' start='%%' />
		</comments>
		<keywords weakDeliminator='-+:/' />
	</general>
</language>
