<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">

<language name="Logtalk" version="1.0" kateversion="2.2" section="Sources" extensions="*.lgt;*.loader;*.config" mimetype="text/x-logtalk">

    <highlighting>

        <contexts>

            <context name="normal" attribute="Normal" lineEndContext="#stay">
				<!-- Directives -->
                <RegExpr String = "^[\s]*:-" attribute="Normal" context="directive" />
				<!-- Event handlers -->
                <RegExpr String = "\b(after|before)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Method execution context -->
                <RegExpr String = "\b(parameter|this|self|sender)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Reflection -->
                <RegExpr String = "\b(current_predicate|predicate_property)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- DCGs -->
                <RegExpr String = "\bphrase(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Entity -->
                <RegExpr String = "\b(current_object|current_protocol|current_category)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(create_object|create_protocol|create_category)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(object_property|protocol_property|category_property)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(abolish_object|abolish_protocol|abolish_category)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Event handlers -->
                <RegExpr String = "\b(extends_object)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(extends_protocol|implements_protocol)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(instantiates_class|specializes_class)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(imports_category)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Events -->
                <RegExpr String = "\b(abolish_events|current_event|define_events)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Flags and compiler options -->
                <RegExpr String = "\b(current_logtalk_flag|set_logtalk_flag)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Compiling and loading -->
                <RegExpr String = "\b(logtalk_compile|logtalk_load)(?=[(])" attribute="Built-in" context="#stay" />

				<!-- Database -->
                <RegExpr String = "\b(abolish|asserta|assertz|clause|retract|retractall)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Control -->
                <RegExpr String = "\b(call|catch|throw)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(fail|true)\b" attribute="Built-in" context="#stay" />
				<!-- All solutions -->
                <RegExpr String = "\b(bagof|findall|forall|setof)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Term unification -->
                <RegExpr String = "\bunify_with_occurs_check(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Term creation and decomposition -->
                <RegExpr String = "\b(functor|arg|copy_term)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Evaluable functors -->
                <RegExpr String = "\b(rem|mod|abs|sign)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(float_integer_part|float_fractional_part|float)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(floor|truncate|round|ceiling)(?=[(])" attribute="Built-in" context="#stay" />
                <!-- Other arithemtic functors -->
                <RegExpr String = "\b(sin|cos|atan|exp|log|sqrt)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Term testing -->
                <RegExpr String = "\b(var|atom|integer|float|atomic|compound|nonvar|number)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Stream selection and control -->
                <RegExpr String = "\b(current_input|current_output)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(set_input|set_output)(?=[(])" attribute="Built-in" context="#stay" />
				<RegExpr String = "\b(open|close)(?=[(])" attribute="Built-in" context="#stay" />
				<RegExpr String = "\bflush_output\b" attribute="Built-in" context="#stay" />
				<RegExpr String = "\bflush_output(?=[(])" attribute="Built-in" context="#stay" />
				<RegExpr String = "\b(stream_property|at_end_of_stream|set_stream_position)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Character input/output -->
                <RegExpr String = "\b(get_char|get_code|peek_char|peek_code|put_char|put_code|nl)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Byte input/output -->
                <RegExpr String = "\b(get_byte|peek_byte|put_byte)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Term input/output -->
                <RegExpr String = "\b(read_term|read)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(write_term|write|writeq|write_canonical)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(op|current_op)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(char_conversion|current_char_conversion)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Atomic term processing -->
                <RegExpr String = "\b(atom_length|atom_concat|sub_atom)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(atom_chars|atom_codes|char_code)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\b(number_chars|number_codes)(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Implementation defined hooks functions -->
                <RegExpr String = "\b(set_prolog_flag|current_prolog_flag)(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\bhalt\b" attribute="Built-in" context="#stay" />
                <RegExpr String = "\bhalt(?=[(])" attribute="Built-in" context="#stay" />
				<!-- Variables -->
                <RegExpr String = "\b[A-Z_][A-Za-z0-9_]*" attribute = "Variable" context="#stay"/>
				<!-- Comments -->
                <DetectChar attribute="Comment" context="single line comment" char="%"/>
                <Detect2Chars attribute="Comment" context="multiline comment" char="/" char1="*"/>
				<!-- Strings and quoted atoms -->
                <DetectChar attribute="String" context="string" char="&quot;" />
                <RegExpr String = "'" attribute="String" context="atom" />
				<!-- Numbers -->
                <RegExpr String = "0'[A-Za-z0-9]" attribute = "Number" context="#stay"/>
                <RegExpr String = "0b[0-1]+" attribute = "Number" context="#stay"/>
                <RegExpr String = "0o[0-7]+" attribute = "Number" context="#stay"/>
                <RegExpr String = "0x[0-9a-fA-F]+" attribute = "Number" context="#stay"/>
                <RegExpr String = "[0-9]+(\.[0-9]+)?([eE][-+][0-9]+)?" attribute = "Number" context="#stay"/>
                <!-- Message sending operators -->
                <StringDetect String = "::" attribute="Operator" context="#stay" />
                <StringDetect String = "^^" attribute="Operator" context="#stay" />
				<!-- External call -->
                <DetectChar attribute="Operator" context="#stay" char="{" beginRegion="external" />
                <DetectChar attribute="Operator" context="#stay" char="}" endRegion="external" />
				<!-- Logic and control -->
                <RegExpr String = "\bonce(?=[(])" attribute="Built-in" context="#stay" />
                <RegExpr String = "\brepeat\b" attribute="Built-in" context="#stay" />
				<!-- Bitwise functors -->
                <StringDetect String = "&gt;&gt;" attribute="Operator" context="#stay" />
                <StringDetect String = "&lt;&lt;" attribute="Operator" context="#stay" />
                <StringDetect String = "/\" attribute="Operator" context="#stay" />
                <StringDetect String = "\/" attribute="Operator" context="#stay" />
                <StringDetect String = "\\" attribute="Operator" context="#stay" />
				<!-- Arithemtic evaluation -->
                <RegExpr String = "\bis\b" attribute="Operator" context="#stay" />
				<!-- Arithemtic comparison -->
                <StringDetect String = "=:=" attribute="Operator" context="#stay" />
                <StringDetect String = "=\=" attribute="Operator" context="#stay" />
                <StringDetect String = "&lt;" attribute="Operator" context="#stay" />
                <StringDetect String = "=&lt;" attribute="Operator" context="#stay" />
                <StringDetect String = "&gt;" attribute="Operator" context="#stay" />
                <StringDetect String = "&gt;=" attribute="Operator" context="#stay" />
				<!-- Term creation and decomposition -->
                <StringDetect String = "=.." attribute="Operator" context="#stay" />
				<!-- Term unification -->
                <StringDetect String = "=" attribute="Operator" context="#stay" />
                <StringDetect String = "\=" attribute="Operator" context="#stay" />
				<!-- Term comparison -->
                <StringDetect String = "==" attribute="Operator" context="#stay" />
				<StringDetect String = "\==" attribute="Operator" context="#stay" />
                <StringDetect String = "@=&lt;" attribute="Operator" context="#stay" />
                <StringDetect String = "@&lt;" attribute="Operator" context="#stay" />
                <StringDetect String = "@&gt;=" attribute="Operator" context="#stay" />
                <StringDetect String = "@&gt;" attribute="Operator" context="#stay" />
				<!-- Evaluable functors -->
                <StringDetect String = "+" attribute="Operator" context="#stay" />
                <StringDetect String = "-" attribute="Operator" context="#stay" />
                <StringDetect String = "*" attribute="Operator" context="#stay" />
                <StringDetect String = "//" attribute="Operator" context="#stay" />
                <StringDetect String = "/" attribute="Operator" context="#stay" />
                <RegExpr String = "\brem\b" attribute="Operator" context="#stay" />
                <RegExpr String = "\bmod\b" attribute="Operator" context="#stay" />
				<!-- Other arithemtic functors -->
                <StringDetect String = "**" attribute="Operator" context="#stay" />
				<!-- DCG rules -->
                <StringDetect String = "--&gt;" attribute="Operator" context="#stay" />
				<!-- Control constructs -->
                <StringDetect String = "!" attribute="Operator" context="#stay" />
                <StringDetect String = "-&gt;" attribute="Operator" context="#stay" />
                <StringDetect String = ";" attribute="Operator" context="#stay" />
				<!-- Logic and control -->
                <StringDetect String = "\+" attribute="Operator" context="#stay" />
				<!-- Mode operators -->
                <StringDetect String = "?" attribute="Operator" context="#stay" />
                <StringDetect String = "@" attribute="Operator" context="#stay" />
				<!-- Clause operator -->
                <StringDetect String = ":-" attribute="Normal" context="#stay" />
            </context>

            <context name="directive" attribute="Directive" lineEndContext="#stay">
        		<!-- Entity directives -->
                <RegExpr String = "\b(category|object|protocol)(?=[(])" attribute="Directive" context="entityrelations" />
                <RegExpr String = "\b(end_category|end_object|end_protocol)[.]" attribute="Directive" context="#pop" />
 				<!-- Predicate scope directives -->
                <RegExpr String = "\b(public|protected|private)(?=[(])" attribute="Directive" context="#pop" />
				<!-- Other directives -->
                <RegExpr String = "\binitialization(?=[(])" attribute="Directive" context="#pop" />
                <RegExpr String = "\b(info|mode)(?=[(])" attribute="Directive" context="#pop" />
                <RegExpr String = "\bdynamic[.]" attribute="Directive" context="#pop" />
				<RegExpr String = "\b(dynamic|discontiguous|metapredicate)(?=[(])" attribute="Directive" context="#pop" />
                <RegExpr String = "\bop(?=[(])" attribute="Directive" context="#pop" />
                <RegExpr String = "\b(calls|uses)(?=[(])" attribute="Directive" context="#pop" />
            </context>

            <context name="entityrelations" attribute="Normal" lineEndContext="#stay">
                <RegExpr String = "\b(extends|implements|imports|instantiates|specializes)(?=[(])" attribute="Directive" context="#stay" />
                <Detect2Chars attribute="Normal" context="normal" char=")" char1="." />
            </context>

            <context name="single line comment" attribute="Comment" lineEndContext="#pop" />

            <context name="multiline comment" attribute="Comment" lineEndContext="#stay">
                <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" />
            </context>

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

            <context name="atom" attribute="String" lineEndContext="#stay">
                <DetectChar attribute="String" context="#pop" char="'" />
            </context>

        </contexts>

		<itemDatas>
			<itemData name="Normal" defStyleNum="dsNormal" />
			<itemData name="Directive" defStyleNum="dsKeyword" />
			<itemData name="Built-in" defStyleNum="dsKeyword" />
			<itemData name="Operator" defStyleNum="dsDataType" />
			<itemData name="Comment" defStyleNum="dsComment" />
			<itemData name="Number" defStyleNum="dsDecVal" />
			<itemData name="String"  defStyleNum="dsString"/>
            <itemData name="Variable" defStyleNum="dsOthers"/>
		</itemDatas>

	</highlighting>

	<general>
		<comments>
			<comment name="singleLine" start="%" />
			<comment name="multiLine" start="/*" end="*/" />
		</comments>
		<keywords casesensitive="true" />
	</general>

</language>

