
Description="Logtalk"

-- Syntax file created by Paulo Moura

Categories = {"source"}

Keywords={
  { Id=1, --conditional compilation directives
    Regex=[[^\s*:-\s((el)?if)(?=[(])]],
    Group=1,
  },
  { Id=1, --conditional compilation directives
    Regex=[[^\s*:-\s(e(lse|ndif))(?=\.)]],
    Group=1,
  },
  { Id=2, --variables
    Regex=[[(?<!0')[A-Z_]\w*]],
  },
  { Id=3, -- event handlers
    Regex=[[(after|before)(?=[(])]],
    Group=1,
  },
  { Id=3, -- forward message handler
    Regex=[[(forward)(?=[(])]],
    Group=1,
  },

  { Id=1, --encapsulation directives
    Regex=[[ ^\s*:-\s(category|protocol|object)(?=[(]) ]],
    Group=1,
  },
  { Id=1,
    Regex=[[ ^\s+((extend|i(mp(or|lemen)t|nstantiate)|specialize)s)(?=[(]) ]],
    Group=1,
  },
  { Id=1,
    Regex=[[ ^\s*:-\s(end_(protocol|category|object))(?=\.) ]],
    Group=1,
  },
  { Id=1, -- entity and predicate directives
    Regex=[[ ^\s*:-\s(calls|coinductive|public|protected|private|encoding|ensure_loaded|export|in(clude|fo|itialization)|alias|dynamic|discontiguous|meta_(non_terminal|predicate)|mode|module|multifile|reexport|set_(logtalk|prolog)_flag|synchronized|op|uses|use_module)(?=[(]) ]],
    Group=1,
  },
  { Id=1,
    Regex=[[ ^\s*:-\s(built_in|dynamic|synchronized|threaded)(?=\.) ]],
    Group=1,
  },
  { Id=3, --event handlers
    Regex=[[ (after|before)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (context|parameter|this|se(lf|nder))(?=[(]) ]],
    Group=1
  },
  { Id=3, --reflection
    Regex=[[ (current_predicate|predicate_property)(?=[(]) ]],
    Group=1
  },
  { Id=3, --dcgs
    Regex=[[ (expand_(goal|term))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ ((?:goal|term)_expansion|phrase)(?=[(]) ]],
    Group=1
  },
  { Id=3, --entity
    Regex=[[ ((abolish|c(reate|urrent))_(object|protocol|category))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ ((object|protocol|category)_property)(?=[(]) ]],
    Group=1
  },
  { Id=3, --entity relations
    Regex=[[ (co(mplements_object|nforms_to_protocol))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (extends_(object|protocol|category))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (imp(lements_protocol|orts_category))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ ((instantiat|specializ)es_class)(?=[(]) ]],
    Group=1
  },
  { Id=3, --events
    Regex=[[ (current_event|(abolish|define)_events)(?=[(]) ]],
    Group=1
  },
  { Id=3, --flags
    Regex=[[ ((create|current|set)_logtalk_flag)(?=[\(]) ]],
    Group=1
  },
  { Id=3, --compiling, loading, and library paths
    Regex=[[ (logtalk_(compile|l(ibrary_path|oad|oad_context)|make(_target_action)?))(?=[(]) ]],
    Group=1
  },
  { Id=3, --compiling, loading, and library paths
    Regex=[[ (logtalk_make) ]],
    Group=1
  },
  { Id=3, --database
    Regex=[[ (clause|retract(all)?)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (a(bolish|ssert(a|z)))(?=[(])  ]],
    Group=1
  },
  { Id=3, --control
    Regex=[[ (call|catch|throw|(type|domain|existence|permission|representation|evaluation|resource|syntax)_error)(?=[(]) ]],
    Group=1
  },
  { Id=3, --control
    Regex=[[ (fa(il|lse|)|true|(instantiation|system)_error) ]],
    Group=1
  },
  { Id=3, --all solutions
    Regex=[[ (bagof|setof|findall|forall)(?=[(]) ]],
    Group=1
  },
  { Id=3, --multi-threading predicates
    Regex=[[ (threaded(_(call|once|ignore|exit|peek|wait|notify))?)(?=[(]) ]],
    Group=1
  },
  { Id=3, --engine predicates
    Regex=[[ (threaded_engine(_(create|destroy|self|next|next_reified|yield|post|fetch))?)(?=[(]) ]],
    Group=1
  },
  { Id=3, --term unification
    Regex=[[ (subsumes_term|unify_with_occurs_check)(?=[(]) ]],
    Group=1
  },
  { Id=3, -- term creation and decomposition
    Regex=[[ (functor|arg|copy_term|numbervars|term_variables)(?=[(]) ]],
    Group=1
  },
  { Id=3, -- term comparision
    Regex=[[ (compare)(?=[(]) ]],
    Group=1
  },
  { Id=3, --evaluable functors
    Regex=[[ (div|rem|mod|abs|sign)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (float(_(integer|fractional)_part)?)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (floor|truncate|round|ceiling)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (cos|a(cos|sin|tan|tan2)|exp|log|s(in|qrt)|tan|xor)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (max|min)(?=[(]) ]],
    Group=1
  },
  { Id=3, --term testing
    Regex=[[ (var|atomic|atom|integer|float|callable|compound|nonvar|number|ground|acyclic_term)(?=[(]) ]],
    Group=1
  },
  { Id=3, -- stream selection and control
    Regex=[[ ((curren|se)t_(in|out)put)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (open|close)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (flush_output)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ \b(flush_output)\b ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (stream_property|at_end_of_stream|set_stream_position)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (at_end_of_stream) ]],
    Group=1
  },
  { Id=3, -- character and byte input/output
    Regex=[[ (nl|(get|peek|put)_(byte|char|code))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (nl) ]],
    Group=1
  },
  { Id=3, -- term input/output
    Regex=[[ (read(_term)?)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (write(q|_(canonical|term))?)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ ((current_)?op)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ ((current_)?char_conversion)(?=[(]) ]],
    Group=1
  },
  { Id=3, --atomic term processing
    Regex=[[ (atom_(length|c(hars|o(ncat|des))))(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (char_code|sub_atom)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (number_c(har|ode)s)(?=[(]) ]],
    Group=1
  },
  { Id=3, --implementation defined hooks functions
    Regex=[[ ((?:se|curren)t_prolog_flag)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (halt) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (halt)(?=[(]) ]],
    Group=1
  },
  { Id=3, --logic and control
    Regex=[[ (once|ignore)(?=[(]) ]],
    Group=1
  },
  { Id=3,
    Regex=[[ (repeat) ]],
    Group=1
  },
  { Id=3, --sorting
    Regex=[[ (keysort|sort)(?=[(]) ]],
    Group=1
  },

  { Id=4, --Logtalk message sending operators
    Regex=[[ (::|\^\^|<<|:(?!\-)) ]],
  },
  { Id=4, --Logtalk external-call control construct
    Regex=[[ ([{}]) ]],
  },
  { Id=4, --Logtalk predicate aliases operator
    Regex=[[ \b(as)\b ]],
  },
  { Id=4, --arithmetic evaluation operator
    Regex=[[ \b(is)\b ]],
  },
  { Id=4, --arithmetic functions
    Regex=[[ \b(div|mod|rem|e|pi)\b ]],
  },
  { Id=4, --operators
    Regex=[[ (\\\+|-->|->|=\.\.|;|!|:-|\^) ]],
  },
  { Id=4,
    Regex=[[ (=<|<|=:=|=\\=|>=|>) ]],
  },
  { Id=4,
    Regex=[[ (@<|@=<|==|\\==|@>|@>=) ]],
  },
  { Id=4,
    Regex=[[ (=|\\=) ]],
  },
  { Id=4,
    Regex=[[ (\?|@) ]],
  },
  { Id=4,
    Regex=[[ (/\\|\\/|>>|\\) ]],
  },
  { Id=5,
    Regex=[[ (0['][\\].) ]],
  },
  { Id=5,
    Regex=[[ (0['].) ]],
  },
  { Id=5,
    Regex=[[ (0b[0-1]+|0o[0-7]+) ]],
  },
  { Id=5,
    Regex=[=[0x[[:xdigit:]]+]=],
  },
  { Id=5,
    Regex=[[ ([:digit:]+(\.[:digit:]+)?([eE][+-]?[:digit:]+)?) ]],
  },
}


-- disable highlighting of numbers
Digits = Identifiers


Strings={
  Delimiter=[["|']],
  Escape=[=[ \\[0-7]+\\|\\x[[:xdigit:]]+\\|\\[abfnrtv\\\'"] ]=]
}

IgnoreCase=false

Comments={
  { Block=false,
    Delimiter= { [[%]] },
  },
  { Block=true,
    Nested=false,
    Delimiter= { [[\/\*]],[[\*\/]],}
  }
}
