<?xml version="1.0" encoding="UTF-8"?>
<!--

 Author: Paulo Moura <pmoura@logtalk.org>
 Copyright (C) 2007 Paulo Moura <pmoura@logtalk.org>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.

-->
<language id="logtalk" _name="Logtalk" version="2.0" _section="Sources">

	<metadata>
		<property name="mimetypes">text/x-logtalk</property>
		<property name="globs">*.lgt</property>
		<property name="line-comment-start">%</property>
		<property name="block-comment-start">/*</property>
		<property name="block-comment-end">*/</property>
	</metadata>

	<styles>
		<style id="comment" _name="Comment" map-to="def:comment"/>
		<style id="operator" _name="Operator" map-to="def:operator"/>
		<style id="error" _name="Error" map-to="def:error"/>
		<style id="string" _name="String" map-to="def:string"/>
		<style id="entity" _name="Data type" map-to="def:type"/>
		<style id="directive" _name="Preprocessor directive" map-to="def:preprocessor"/>
		<style id="number" _name="Number" map-to="def:decimal"/>
		<style id="built-in" _name="Keyword" map-to="def:keyword"/>
		<style id="variable" _name="Variable" map-to="def:identifier"/>
	</styles>

	<definitions>

		<context id="string" style-ref="string" end-at-line-end="true">
			<start>"</start>
			<end>"</end>
		</context>
	
		<context id="quoted-atom" style-ref="string" end-at-line-end="true">
			<start>'</start>
			<end>'</end>
		</context>
	
		<context id="line-comment" style-ref="comment" end-at-line-end="true">
			<start>%</start>
			<include>
				<context ref="def:in-line-comment"/>
			</include>
		</context>
	
		<context id="block-comment" style-ref="comment">
			<start>/\*</start>
			<end>\*/</end>
			<include>
				<context ref="def:in-comment"/>
			</include>
		</context>

		<context id="close-comment-outside-comment" style-ref="error">
			<match>\*/(?!\*)</match>
		</context>

		<context id="entity-directives" style-ref="entity">
			<prefix>^\s*:-\s</prefix>
			<keyword>(object)(?=[(])</keyword>			
			<keyword>(protocol)(?=[(])</keyword>			
			<keyword>(category)(?=[(])</keyword>			
			<keyword>(end_(object|protocol|category))(?=[.])</keyword>			
		</context>

		<context id="entity-relations" style-ref="entity">
			<keyword>(specializes)(?=[(])</keyword>
			<keyword>(extends)(?=[(])</keyword>
			<keyword>(i(mp(orts|lements)|nstantiates))(?=[(])</keyword>
		</context>

		<context id="predicate-directives" style-ref="directive">
 			<prefix>^\s*:-\s</prefix>
			<!-- Scope directives -->
			<keyword>(p(ublic|r(otected|ivate)))(?=[(])</keyword>			
 			<!-- Multi-threading directives -->
			<keyword>(synchronized)(?=[(])</keyword>			
			<keyword>(synchronized)(?=[.])</keyword>			
			<keyword>(threaded)(?=[.])</keyword>			
			<!-- Other directives -->
			<keyword>(alias)(?=[(])</keyword>			
			<keyword>(e(ncoding|xport))(?=[(])</keyword>			
			<keyword>(in(itialization|fo))(?=[(])</keyword>			
			<keyword>(mod(e|ule))(?=[(])</keyword>			
			<keyword>(dynamic)(?=[(])</keyword>			
			<keyword>(dynamic)(?=[.])</keyword>			
			<keyword>(discontiguous)(?=[(])</keyword>			
			<keyword>(m(eta_predicate|ultifile))(?=[(])</keyword>			
			<keyword>(op)(?=[(])</keyword>			
			<keyword>(calls)(?=[(])</keyword>			
			<keyword>(use(s|_module))(?=[(])</keyword>			
		</context>

		<context id="built-in-methods" style-ref="built-in">
			<!-- Method execution context -->
			<keyword>(parameter)(?=[(])</keyword>
			<keyword>(se(lf|nder))(?=[(])</keyword>
			<keyword>(this)(?=[(])</keyword>
			<!-- Reflection -->
			<keyword>(current_predicate)(?=[(])</keyword>
			<keyword>(predicate_property)(?=[(])</keyword>
			<!-- Database -->
			<keyword>(a(bolish|ssert(a|z)))(?=[(])</keyword>
			<keyword>(clause)(?=[(])</keyword>
			<keyword>(retract(all)?)(?=[(])</keyword>
			<!-- All solutions -->
			<keyword>((bag|set)of)(?=[(])</keyword>
			<keyword>(f(ind|or)all)(?=[(])</keyword>
			<!-- Event handlers -->
			<keyword>(before)(?=[(])</keyword>
			<keyword>(after)(?=[(])</keyword>
			<!-- DCGs -->
			<keyword>(expand_term)(?=[(])</keyword>
			<keyword>(term_expansion)(?=[(])</keyword>
			<keyword>(phrase)(?=[(])</keyword>
		</context>

		<context id="built-in-predicates" style-ref="built-in">
			<!-- Entity -->
			<keyword>((abolish|c(reate|urrent))_(object|protocol|category))(?=[(])</keyword>
			<keyword>((object|protocol|category)_property)(?=[(])</keyword>
			<!-- Entity relations -->
			<keyword>(extends_(object|protocol))(?=[(])</keyword>
			<keyword>(imp(lements_protocol|orts_category))(?=[(])</keyword>
			<keyword>((instantiat|specializ)es_class)(?=[(])</keyword>
			<!-- Events -->
			<keyword>(current_event)(?=[(])</keyword>
			<keyword>((abolish|define)_events)(?=[(])</keyword>
			<!-- Flags -->
			<keyword>((se|curren)t_logtalk_flag)(?=[(])</keyword>
			<!-- Compiling, loading, and library paths -->
			<keyword>(logtalk_(compile|l(ibrary_path|oad)))(?=[(])</keyword>
			<!-- Multi-threading meta-predicates -->
			<keyword>(threaded(_(call|once|ignore|exit|peek|wait|notify))?)(?=[(])</keyword>
			<!-- All solutions -->
			<keyword>(forall)(?=[(])</keyword>
		</context>

		<context id="other-built-in-predicates" style-ref="built-in">
			<!-- Term unification -->
			<keyword>(unify_with_occurs_check)(?=[(])</keyword>
			<!-- Term testing -->
			<keyword>(atom(ic)?)(?=[(])</keyword>
			<keyword>(integer)(?=[(])</keyword>
			<keyword>(float)(?=[(])</keyword>
			<keyword>(compound)(?=[(])</keyword>
			<keyword>((non)?var)(?=[(])</keyword>
			<keyword>(number)(?=[(])</keyword>
			<!-- Term creation and decomposition -->
			<keyword>(functor)(?=[(])</keyword>
			<keyword>(arg)(?=[(])</keyword>
			<keyword>(copy_term)(?=[(])</keyword>
			<!-- Arithemtic evaluation -->
			<keyword>is</keyword>
			<!-- Evaluable functors -->
			<keyword>(rem)(?=[(])</keyword>
			<keyword>rem</keyword>
			<keyword>(mod)(?=[(])</keyword>
			<keyword>mod</keyword>
			<keyword>(abs)(?=[(])</keyword>
			<keyword>(sign)(?=[(])</keyword>
			<keyword>(float(_(integer|fractional)_part)?)(?=[(])</keyword>
			<keyword>(floor)(?=[(])</keyword>
			<keyword>(truncate)(?=[(])</keyword>
			<keyword>(round)(?=[(])</keyword>
			<keyword>(ceiling)(?=[(])</keyword>
			<!-- Other arithemtic functors -->
			<keyword>(sin)(?=[(])</keyword>
			<keyword>(cos)(?=[(])</keyword>
			<keyword>(atan)(?=[(])</keyword>
			<keyword>(exp)(?=[(])</keyword>
			<keyword>(log)(?=[(])</keyword>
			<keyword>(sqrt)(?=[(])</keyword>
			<!-- Stream selection and control -->
			<keyword>((current|set)_(in|out)put)(?=[(])</keyword>
			<keyword>(open)(?=[(])</keyword>
			<keyword>(close)(?=[(])</keyword>
			<keyword>(flush_output)(?=[(])</keyword>
			<keyword>flush_output</keyword>
			<keyword>(stream_property)(?=[(])</keyword>
			<keyword>(at_end_of_stream)(?=[(])</keyword>
			<keyword>at_end_of_stream</keyword>
			<keyword>(set_stream_position)(?=[(])</keyword>
			<!-- Character input/output -->
			<keyword>((get|p(eek|ut))_c(har|ode))(?=[(])</keyword>
			<keyword>(nl)(?=[(])</keyword>
			<keyword>nl</keyword>
			<!-- Byte input/output -->
			<keyword>((get|peek|put)_byte)(?=[(])</keyword>
			<!-- Term input/output -->
			<keyword>(read(_term)?)(?=[(])</keyword>
			<keyword>(write(q|_(canonical|term))?)(?=[(])</keyword>
			<keyword>((current_)?op)(?=[(])</keyword>
			<keyword>((current_)?char_conversion)(?=[(])</keyword>
			<!-- Logic and control -->
			<keyword>(once)(?=[(])</keyword>
			<keyword>(true|fail|repeat)(?![-!(^~])</keyword>
			<!-- Atomic term processing -->
			<keyword>(atom_(length|c(hars|o(ncat|des))))(?=[(])</keyword>
			<keyword>(sub_atom)(?=[(])</keyword>
			<keyword>(char_code)(?=[(])</keyword>
			<keyword>(number_c(hars|odes))(?=[(])</keyword>
			<!-- Implementation defined hooks functions -->
			<keyword>((set|current)_prolog_flag)(?=[(])</keyword>
			<keyword>(halt)(?=[(])</keyword>
			<keyword>halt</keyword>
		</context>

		<context id="built-in-operators" style-ref="built-in">
			<prefix></prefix>
			<suffix></suffix>
			<!-- Term unification -->
			<keyword>=</keyword>
			<keyword>\\=</keyword>
			<!-- Term comparison -->
			<keyword>==</keyword>
			<keyword>\\==</keyword>
			<keyword>@&lt;</keyword>
			<keyword>@=&lt;</keyword>
			<keyword>@&gt;=</keyword>
			<keyword>@&gt;</keyword>
			<!-- Term creation and decomposition -->
			<keyword>=\.\.</keyword>
			<!-- Arithemtic comparison -->
			<keyword>=:=</keyword>
			<keyword>=\\=</keyword>
			<keyword>&lt;</keyword>
			<keyword>=&lt;</keyword>
			<keyword>&gt;</keyword>
			<keyword>&gt;=</keyword>
			<!-- Evaluable functors -->
			<keyword>\+(?![,a-z])</keyword>
			<keyword>(?&lt;!:)(-)(?![,a-z])</keyword>
			<keyword>\*</keyword>
			<keyword>//</keyword>
			<keyword>/</keyword>
			<!-- Other arithemtic functors -->
			<keyword>\*\*</keyword>
			<!-- Bitwise functors -->
			<keyword>&gt;&gt;</keyword>
			<keyword>&lt;&lt;</keyword>
			<keyword>/\\</keyword>
			<keyword>\\/</keyword>
			<keyword>\\</keyword>
			<!-- Logic and control -->
			<keyword>(\\\+|!)</keyword>
		</context>
	
		<context id="number" style-ref="number">
			<match extended="true">
	        \b(0'.|0b[0-1]+|0o[0-7]+|0x[0-9a-fA-F]+|\d+(\.\d+)?([eE]([-+])?\d+)?)
			</match>
		</context>
	
		<context id="variable" style-ref="variable">
			<match extended="true">
			\b[A-Z_][a-zA-Z0-9_]*
			</match>
		</context>

		<context id="message-sending-operators" style-ref="built-in">
			<prefix></prefix>
			<suffix></suffix>
			<keyword>::</keyword>			
			<keyword>\^\^</keyword>
		</context>

		<context id="category-predicate-direct-call" style-ref="built-in">
			<prefix></prefix>
			<suffix></suffix>
			<keyword>:</keyword>			
		</context>

		<context id="external-call-operator" style-ref="built-in">
			<prefix></prefix>
			<suffix></suffix>
			<keyword>\{</keyword>			
			<keyword>\}</keyword>
		</context>
<!--
		<context id="mode-operators" style-ref="built-in">
			<prefix></prefix>
			<suffix></suffix>
			<keyword>\+</keyword>	
			<keyword>-</keyword>
			<keyword>\?</keyword>
			<keyword>@</keyword>
		</context>
-->
		<context id="logtalk">
			<include>
				<context ref="string"/>
				<context ref="quoted-atom"/>
				<context ref="line-comment"/>
				<context ref="block-comment"/>
				<context ref="close-comment-outside-comment"/>
				<context ref="entity-directives"/>
				<context ref="entity-relations"/>
				<context ref="predicate-directives"/>
				<context ref="built-in-methods"/>
				<context ref="built-in-predicates"/>
				<context ref="other-built-in-predicates"/>
				<context ref="built-in-operators"/>
				<context ref="number"/>
				<context ref="variable"/>
				<context ref="message-sending-operators"/>
				<context ref="category-predicate-direct-call"/>
				<context ref="external-call-operator"/>
<!--
				<context ref="mode-operators"/>
-->
			</include>
		</context>

	</definitions>

</language>