Warning, /frameworks/syntax-highlighting/data/syntax/prolog.xml is written in an unsupported language. File is not indexed.

0001 <?xml version="1.0" encoding="UTF-8"?>
0002 <!-- [Purpose & Copyright]
0003 
0004     Highlight ISO-Prolog texts or template/include for Prolog dialects
0005     based on the ISO standard.
0006 
0007     Includes detection of DCG since it is 'hooked' in the ISO standard.
0008     Uses text style "Warning/ISO-bogus" where portability is likely to
0009     fail.
0010 
0011     This file is part of KDE's kate project.
0012 
0013   copyright   : (C) 2012 by Torsten Eichstädt
0014 
0015  **********************************************************************
0016  * This library is free software; you can redistribute it and/or      *
0017  * modify it under the terms of the GNU Library General Public        *
0018  * License as published by the Free Software Foundation; either       *
0019  * version 2 of the License, or (at your option) any later version.   *
0020  *                                                                    *
0021  * This library is distributed in the hope that it will be useful,    *
0022  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
0024  * Library General Public License for more details.                   *
0025  *                                                                    *
0026  * You should have received a copy of the GNU Library General Public  *
0027  * License along with this library; if not, write to the              *
0028  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,   *
0029  * Boston, MA  02110-1301, USA.                                       *
0030  **********************************************************************
0031 -->
0032 <!DOCTYPE language
0033 [<!-- [Regular Expressions, Character Classes & Important Tokens]
0034 E.g. the dot "." has so many different meanings (i.e. in an RegExpr 'any char',
0035 'fullstop' of a clause, etc. pp.) that I decided it's usefull to write these out
0036 to make the rules more expressive. -->
0037 
0038 <!-- RegExpr for graphic tokens.  Comment start "/*" is catched earlier. -->
0039     <!ENTITY gr_char_iso        "[#$&amp;*+\-./:&lt;=>?@^~\\]">
0040 
0041 <!-- RegExpr: The highlighting engine always strips newline, so this ok: -->
0042     <!ENTITY any_nw         "[^ \t]">
0043     <!ENTITY any            ".">
0044 
0045 <!-- RegExpr: we want to highlight some graphic tokens: Logic & Control
0046     fullstop shall not be falsely detected if it is actually a list functor
0047     comma is catched extra to highlight it as "Normal Text" in an arg_seq
0048     (and the cut "!" is NOT an op) -->
0049     <!ENTITY fullstop_iso          "\.(?!(\(|&gr_char_iso;))">
0050     <!ENTITY logic_control_ops_iso "(;|->|\\\+|:-|=|\\=)(?!&gr_char_iso;)">
0051 
0052     <!-- RegExpr: DCG (not my idea it is not reversed and named 'reduction') -->
0053     <!ENTITY dcg_production_iso    "-->(?!&gr_char_iso;)">
0054 
0055     <!-- RegExpr: partitioning of arithmetic operators:
0056     - the 1st "arith_compare" always demand arithmetic evaluation
0057       => highlight as "Arithmetics".
0058     - the 2nd only at the right side of "is" or when an arith_compare applies.
0059       They are used in other contexts as well, e.g. traditionally A-B is used
0060       for 'a pair of something', the "^" in bagof/3 and setof/3.
0061       => highlight as "Arithmetics" only in an arith_expr.
0062     - the 3rd are true ISO Bogus: it is not specified whether it is arithmetic
0063       or logical shift, and for bitwise AND, OR and NEG the integer format is
0064       unspecified => not portable, depend on Prolog implementation. -->
0065     <!ENTITY arith_compare_iso  "(=:=|=\\=|=&lt;|&lt;|>=|>)(?!&gr_char_iso;)">
0066     <!ENTITY arith_ops_mixed_iso      "(\+|-|\*|\^)(?!&gr_char_iso;)">
0067     <!ENTITY arith_ops_int_iso      "//(?!&gr_char_iso;)">
0068     <!ENTITY arith_ops_float_iso      "(/|\*\*)(?!&gr_char_iso;)">
0069     <!ENTITY arith_bogus_iso  "(/\\|\\/|\\|&lt;&lt;|>>)(?!&gr_char_iso;)">
0070 
0071     <!-- RegExpr: other predefined operators -->
0072     <!ENTITY predefined_ops_iso "(\?-|==|\\==|@=&lt;|@&lt;|@>=|@>|=\.\.|@|:)(?!&gr_char_iso;)">
0073 
0074     <!-- We treat a number as float if it includes a decimal dot or exponent -->
0075     <!ENTITY float3_iso "[0-9]+E[+\-]?[0-9]+">
0076     <!ENTITY float2_iso "[0-9]+\.[0-9]+">
0077     <!ENTITY float1_iso "[0-9]+\.[0-9]+E[+\-]?[0-9]+">
0078 
0079 <!-- RegExpr for esc'd char code in quoted 'strings' e.g. "\007\" -->
0080     <!ENTITY esc_oct_iso        "\\[0-7]+\\">
0081     <!ENTITY esc_hex_iso        "\\x[a-fA-F0-9]+\\">
0082 
0083 <!-- Char classes for AnyChar, NOT RegExpr: no esc seqs, ranges, etc. pp. here!
0084      Used to avoid expensive RegExpr whenever possible. -->
0085     <!--  Not needed: any_alnum_under_iso:  use "DetectIdentifier" instead -->
0086     <!ENTITY any_lower_iso         "abcdefghijklmnopqrstuvwxyz">
0087     <!ENTITY any_upper_under_iso   "ABCDEFGHIJKLMNOPQRSTUVWXYZ_">
0088     <!ENTITY any_bin_iso           "01">
0089     <!ENTITY any_oct_iso           "01234567">
0090     <!ENTITY any_dec_iso           "0123456789">
0091     <!ENTITY any_hex_iso           "0123456789abcdefABCDEF">
0092     <!ENTITY any_graphic_iso       "#$&amp;*+-./:&lt;=>?@^~\">
0093 
0094     <!-- Common esc seq in quoted & char code (after "0'").
0095     Tab is handled extra.  Esc'd newline is catched earlier. -->
0096     <!ENTITY any_esc_iso                "abfnrtv\'`&quot;]">
0097 
0098     <!ENTITY dot        ".">
0099 
0100     <!-- Some solo chars for DetectChar -->
0101     <!ENTITY comma      ",">
0102     <!ENTITY cut        "!">
0103     <!ENTITY bar        "|">
0104     <!ENTITY tab        "&#x9;">
0105     <!ENTITY bs         "\">
0106 ]>
0107 <language name="Prolog" section="Sources"
0108           version="17" kateversion="5.62"
0109           mimetype="text/x-prolog"
0110           extensions="*.prolog;*.dcg;*.pro"
0111           author="Torsten Eichstädt (torsten.eichstaedt@web.de)"
0112           license="LGPLv2+">
0113 
0114 <!-- [Terminology & Abbreviations In The Comments]
0115     - Literal text is in double quotes "like this", single quotes sometimes used
0116       for a 'terminus technicus'.
0117     - "w/", "w/o", "s/t" mean 'with', 'without', and "sometimes" resp.
0118     - Use "brace" instead of 'bracket'/'parenthesis' for any of "()[]{}"
0119     - Specify "round", "list/squared", "curly", "opening" and "closing" brace.
0120     - "quote/quoted/string" mean any of single-, double-, or back-quote(d)
0121     - "seq" sequence, "nl" newline, "bs" backslash, "q" quote(d), "cc" char code
0122     - "KISS" Keep it simple, stupid! (be pragmatic)
0123     - "style" = "attribute" (the applied text style)
0124     - Keep comments as short as possible and as descriptive as neccessary LOL
0125 -->
0126 <!-- [Documentation, Bugs, Limitations & Solutions, TODOs]
0127 ################################################################################
0128 All bugs except three by the author. !FOLD THIS AWAY if long comments annoy you.
0129 
0130 BUG - Nobody's perfect - If I knew about the bug you found, it would have been
0131       fixed already.
0132  one- Indentation-based folding is not reliable (Kate; fixed in KDE 4.9?).
0133  two- Folding is sometimes broken (Kate?).  See SOLUTIONS below.
0134  three- An optional leading sign is not highlighted as part of the number.
0135   4 - A float w/o fractional part and exponent is highlighted as an integer.
0136   5 - Detection of whitespace may not be 100% correct, only space/tab/newline.
0137   6 - Handling inside arithmetic expressions might not be 100%.  See "AL GUSTO".
0138  inf- see TODOs below.
0139 
0140 LIMITS of this parser
0141     - Highlighting of syntax errors is as intuitive as possible, i.e. for an
0142       invalid newline highlight the last token before and leading white of the
0143       next line - but that's not always possible.  Use your built-in problem
0144       solver (between your ears) when you do not know what the exact error is.
0145     - The parser knows nothing about currently defined dynamic ops, but has to
0146       respect possible definitions of dynamic ops.  That's why:
0147     - Any sequence of 'graphic chars' (_incl. those containing a dot_) is taken
0148       as _one_ graphic token, and not - as you might expect - your user-defined
0149       operator followed by fullstop (or sequence of ops).
0150     - A single dot in the outmost term of a clause is taken as a fullstop, even
0151       if it is actually a user-defined operator.
0152       - Else, a single dot is highlighted as "Warning" because it might be a
0153         user-def'd op (usually an error, but can not decide w/o current_op/3).
0154     - Detection of the fullstop relies upon the usual semantics of braces.
0155     - Axioms of folding capabilities are: the literal fullstop as stop symbol
0156       and the usual semantics of braces w/ pairs of opening and closing brace.
0157    ?- period.
0158 uncaught exception: error(existence_error(procedure,current_op/3),highlight/2)
0159 
0160 SOLUTIONS
0161     - Help the parser by puting whitespace (space/tab/nl) here and there, espc.
0162       after the fullstop, or use quotes; e.g. '/*' does not begin a comment,
0163       neither does '%', and ***'.' can be two operators.
0164       Functored syntax should always do, e.g. */*(X,Y) is valid (and does not
0165       begin a comment).
0166     - Folding: s/t moving the mouse slightly below the marker shows what you
0167       want, s/t an empty line helps (or removing an empty line), when it's
0168       removed regions stay ok, or break auto-folding w/ non-white @begin of
0169       line.  Try a newer kate version.
0170 
0171 AL GUSTO (simple changes):
0172     - Change classification of built-in predicates: adjust the <list> below.
0173     - Reminder for other changes: solo chars - DetectChar, graphic - RegExpr.
0174     - bar "|" (solo) is highlighted as "other built-in operator" in lists, else
0175       "Normal Text".  You may safely remove/comment out  the rules in contexts
0176       "term/list/curly" below if you add in in context "operator" or "atomic".
0177       If it shall be part of user-defined ops, it has to be added to "gr_char",
0178       and a few rules need adjustment.  Search for "&bar;".  You may then safely
0179       add it to "predefined_ops" above (don't forget to escape it).
0180     - cut "!" (solo) can be adjusted like the bar.
0181     - comma "," (solo) is "Normal Text" in lists, else "Logic & Control".  You
0182       may safely remove/comment out the rules in "term/nested/list/curly" below
0183       and handle it in the context "operator".
0184     - Disable arith_expr: replace "context="arith_expr"" w/ "context="#stay""
0185       in the rules in contexts "atomic" and "operator" (two or three occurrences).
0186     - Disable indentation-based folding: in the section "general"@EOF:"folding".
0187     - General guidelines: Be nice to slow/old hardware: avoid RegExpr (start w/
0188       a RegExpr, test, then find a replacement), else match a RegExpr as late as
0189       possible - it's expensive, a context switch is relatively cheap.
0190       Eat as much text as possible in one run, e.g. in comments and quoted we
0191       use "DetectIdentifier", else the engine would try all rules of the context
0192       (w/ failure) and eat only one char on each run.
0193     If your modification is kind of general, upload it and drop me a note.
0194 
0195   The simplified syntax below should highlight 99.999% of ISO-Prolog texts
0196 correctly, as well as many non-ISO Prolog texts.
0197   Else modify this file.  Save with new name in your HOME directory to
0198 .kde/share/apps/katepart/syntax/prolog-xy.xml You may read the NOTE at the end
0199 of this file.  WARNING: Be careful, though: the highlighting works according to
0200 it's program code, not neccessarily it's documentation...
0201 
0202 DONE- Parse (m)any (!) conforming Prolog texts w/ correct highlighting (LIMITS)
0203     - Parse any erratic text w/o crash or endless loops and highlight errors
0204     - Folding for multiline comments, clauses, nested terms, and quoted (LIMITS)
0205     - Folding inside comments and of 1-line comments and clauses: indentation-
0206       based like in Python, e.g.
0207       my_pred(a).   % w/ marker@left (western style; depends on your settings)
0208         my_pred(b). % you can fold
0209         my_pred(c). % these lines
0210       Inside clauses (i.e. context "term" and below) only explicit folding for
0211       braces and quotes applies, except comments.  I did not find a better
0212       solution, since the engine does not provide lookahead to the next line.
0213     - Additionally, folding with %BEGIN ... %END (iff 1st nonwhite of the line).
0214     - Classify built-ins (YMMV) for different highlighting, mainly:
0215         - w/ side effects from 'outside world' (arithmetics, stream I/O,...)
0216         - w/o side effects, only depend on user's program ('internal world')
0217         - program logic & control constructs
0218         - altering the clause knowledge base or Prolog state
0219         - integer/float/mixed arithmetics, so one can see the type of the result
0220             - Iff it's an arithmetic expression; else arith ops and built-ins
0221               are highlighted normal.
0222     - Incl. Sep2012 DRAFT Technical Corrigendum 2: Prolog - Part 1: General Core
0223     - Incl. honourable Richard O'Keefe's remarks as warnings as "ISO Bogus".
0224     - Detect 'shebang' shell scripts, see BUGs
0225     - Includes alert.xml to highlight alert keywords in comments.
0226     - Dot "." may be an _unquoted_ user-defined operator in nested terms (but is
0227       highlighted as "Warning" 'cause it's more likely a typo than an user-def'd
0228       op) and is only taken as fullstop and highlighted as "Logic & Control" in
0229       the outmost term of a clause.
0230     - Über-correct handling of quoted, escape seqs and "0'" (char code integer):
0231         - detection of valid/invalid newline in quoted 'strings'.
0232         - highlight whitespace after esc'd newline in quoted so it differs from
0233           whitespace contained in the quoted 'string'.
0234         - Highlight esc'd tab and tab in quoted as "Warning" because some text
0235         editors may convert them to space and it is easy to use "\t" instead.
0236     - Preliminary: most names end w/ ISO; prepared to be included in syntax
0237       files adapted for Prolog dialects.
0238     - The Shebang is highlighted only in the first line (with lineEmptyContext).
0239 
0240 FIXME   When katepart can supply line numbers, fix the "shebang" rule.
0241 
0242 TODO sorted by priority
0243   1 - [always] Cruise over all FIXMEs.
0244   2 - Check if comma, cut & bar are really solo chars (where's the red book?).
0245   3  - Check final Technical Corrigendum 2: Prolog - Part 1: General Core
0246   4 - Buy ISO Prolog standard - Part 2: Modules.  Likely only keywords.  Need it
0247       anyway.
0248   5 - Make this strict-ISO and a "Prolog (portable)" that includes this file.
0249   6 - Likewise, adopt for GNU & SWI Prolog and others.
0250   8 - keywords 'phrase', streams depricated, etc.pp. ==> Prolog (portable).
0251   9 - Likewise: shebang ==> Prolog (portable).
0252  10 - Check if shebang can span multiple (escaped) lines.
0253  11 - Check: all KB altering preds can have side effects (via resource_error)?
0254  12 - For next two TODOs: ask katepart dev to provide lookahead to the next line
0255     13 - Folding for consecutive one-line comments [easy? HARD! Impossible.]
0256     14 - Likewise, folding for consecutive clauses [HARD! Impossible.]
0257     I can live w/ indentation-based folding as a workaround.  Not 100%, but ok.
0258  15 - +arg_seq (and list): "," as normal text: Detect name( [no layout; easy]
0259  16 - +Classify meta predicates.
0260  18 - The dollar "$" is commonly used as the 1st char of (unquoted?) atoms to
0261       indicate 'internal mode', e.g. to declare a predicate as compile-in.
0262       Does this mean the dollar is used as if it were a prefix op or is it part
0263       of the atom?  Would be easy to implement.
0264  19 - Bug #4: could be partly fixed, some built-ins take only float not integer.
0265  20 - Bug them to better document weakDeliminators (and rename to delimiter ;)
0266  21 - Adjust doxygen syntax for Prolog (e.g. adapt doxygen-lua), and include it.
0267  22 - Check if vertical tab is white/layout; are there more non-printables?
0268 ################################################################################
0269 -->
0270 <!-- [Facts & Implications Of The ISO Standard, as a reminder]
0271   - 'layout' is whitespace (space/tab/newline) and/or comments.
0272   - Braces (any of "(){}[]"), exclamation "!" (aka 'cut'), 'bar' "|", degree "°",
0273     paragraph "§" and percent "%" are NOT 'graphic' chars, but 'solo' chars.
0274   - The 'bar' "|" may be a predefined operator, and then a user-def'd op, too.
0275   - There can only be (at most) one bar "|" in a list (written inside "[]"), and
0276     no commata after it (after the bar).
0277   - Graphic tokens are atoms (and solo chars are one-char atoms?).
0278   - "{}" and "[]" are 'special atoms' (likewise "()"?).
0279   - "{}" and "[]" shall not be operators (but round or single braces may be?).
0280   - The fullstop "." is not a predefined postfix operator, and
0281   - the list functor "." is not a predefined prefix operator.
0282   - An unquoted graphic token shall not begin with "/*".
0283   - Multiline comments shall not be nested.
0284   - Floats are NOT written with lowercase "e" (i.e. not neccessarily an error if
0285     e.g. "e" is a pre- or user-defined expr or op and the whole term is valid),
0286   - and the fractional part and exponent of floats are optional (any and both).
0287   - A leading minus immediately preceding a number is optional for all numbers
0288     and then part of the number and not a prefix operator (currently beeing
0289     clarified by the standard commitee if "immediately" includes layout, only
0290     comments, or none of these at all ;) but
0291   - the minus "-" is a predefined prefix- and infix operator...
0292   - Terms are rewritten when read in, extendable by user-def'd rules (and these
0293     may be dynamic), i.e. clauses are not restricted to the standard forms
0294     (to the extent that the fullstop ending a clause may be omited at all) and
0295   - the dot "." may be (solo or part of) an user-defined operator.
0296   - A Prolog processor may use any character set, e.g. (multi-byte) Unicode.
0297   - Virtually every token may be an (user- or predefined) operator, except a few
0298     specifically excluded tokens (i.e. NOT just graphic and 'standard' atoms).
0299   - All operators except the comma are dynamic (although the standard denotes
0300     atoms as 'constants' ;), and
0301   - (the comma may appear in a user-defined operator (beeing part of it)?).
0302   (Now try to write syntax highlighting for Prolog w/o Prolog HAHAHA ;)
0303 -->
0304     <highlighting>
0305         <!-- aka "guru meditation trigger" -->
0306         <list name="error term ISO">
0307             <item>error</item>
0308         </list>
0309         <list name="guru meditation terms ISO">
0310             <item>instantiation_error</item>
0311             <item>uninstantiation_error</item>
0312             <item>type_error</item>
0313             <item>domain_error</item>
0314             <item>existence_error</item>
0315             <item>permission_error</item>
0316             <item>representation_error</item>
0317             <item>evaluation_error</item>
0318             <item>resource_error</item>
0319             <item>syntax_error</item>
0320             <item>system_error</item>
0321         </list>
0322 
0323         <!-- These are in fact bogus, DO NOT USE them and bug the ISO standard
0324         commitee to abandon char_conversion/2 and to apply common sense to the
0325         semantics of include/1 and ensure_loaded/1, i.e. to handle recursion.
0326         Bomb them w/ e-mails! It's not the purpose of a standard to fixate
0327         errors till eternity. -->
0328         <list name="bogus ISO">
0329             <item>char_conversion</item>
0330             <item>current_char_conversion</item>
0331             <item>include</item>
0332             <item>ensure_loaded</item>
0333             <!-- Use atan2 instead -->
0334             <item>atan</item>
0335             <!-- Unspecified integer representation/format -->
0336             <item>xor</item>
0337         </list>
0338         <!-- including directive "initialization" -->
0339         <list name="logic+control ISO">
0340             <item>initialization</item>
0341 <!--        <item>!</item> -->
0342             <item>fail</item>
0343             <item>repeat</item>
0344             <item>call</item>
0345             <item>catch</item>
0346             <item>throw</item>
0347             <item>true</item>
0348             <item>false</item>
0349             <item>once</item>
0350         </list>
0351 
0352         <!-- including directive "dynamic" -->
0353         <list name="dyn clause mgmt ISO">
0354             <item>dynamic</item>
0355             <item>asserta</item>
0356             <item>assertz</item>
0357             <item>retractall</item>
0358             <item>retract</item>
0359             <item>abolish</item>
0360             <item>clause</item>
0361 <!--        <item>numbervars</item> -->
0362 <!--        <item>current_predicate</item> -->
0363         </list>
0364         <list name="terms ISO">
0365             <!-- keep tokens with same prefix sorted by length? -->
0366             <item>atom_concat</item>
0367             <item>atom_length</item>
0368             <item>atom_chars</item>
0369             <item>atom_codes</item>
0370             <item>arg</item>
0371             <item>subsumes_term</item>
0372             <item>acyclic_term</item>
0373             <item>char_code</item>
0374             <item>compare</item>
0375             <item>copy_term</item>
0376             <item>functor</item>
0377             <item>number_chars</item>
0378             <item>number_codes</item>
0379 <!--FIXME check if GNU or ISO       <item>sub_atom</item> -->
0380             <item>term_variables</item>
0381             <item>unify_with_occurs_check</item>
0382         </list>
0383         <list name="DCG non-ISO">
0384             <item>phrase</item>
0385         </list>
0386         <list name="streams ISO">
0387             <item>open</item>
0388 <!--GNU     <item>current_stream</item>-->
0389             <item>set_stream_position</item>
0390             <item>get_char</item>
0391             <item>get_code</item>
0392             <item>peek_char</item>
0393             <item>peek_code</item>
0394             <item>get_byte</item>
0395             <item>peek_byte</item>
0396 
0397             <item>put_char</item>
0398             <item>put_code</item>
0399             <item>put_byte</item>
0400             <item>nl</item>
0401 
0402             <item>read_term</item>
0403             <item>read</item>
0404             <item>write_canonical</item>
0405             <item>writeq</item>
0406             <item>write</item>
0407         </list>
0408         <list name="arith eval ISO">
0409             <item>is</item>
0410         </list>
0411         <list name="arith ops int ISO">
0412             <item>rem</item>
0413             <item>mod</item>
0414             <item>div</item>
0415         </list>
0416         <list name="arith expr mixed ISO">
0417 <!--GNU arith IF expr    <item>inc</item> -->
0418 <!--GNU arith IF expr    <item>dec</item> -->
0419             <item>abs</item>
0420             <item>sign</item>
0421             <item>min</item>
0422             <item>max</item>
0423         </list>
0424         <list name="arith expr int ISO">
0425 <!--GNU arith IF expr    <item>inc</item> -->
0426 <!--GNU arith IF expr    <item>dec</item> -->
0427             <item>ceiling</item>
0428             <item>floor</item>
0429             <item>round</item>
0430             <item>truncate</item>
0431 <!-- ISO Bogus      <item>xor</item> -->
0432         </list>
0433         <list name="arith expr float ISO">
0434             <item>pi</item>
0435 <!--GNU (see pi)    <item>e</item> -->
0436 <!--GNU (see pi)    <item>epsilon</item> -->
0437             <item>sqrt</item>
0438             <item>tan</item>
0439             <item>cos</item>
0440             <item>sin</item>
0441             <item>atan2</item>
0442             <item>acos</item>
0443             <item>asin</item>
0444             <item>exp</item>
0445             <item>log</item>
0446             <item>float</item>
0447             <item>float_fractional_part</item>
0448             <item>float_integer_part</item>
0449         </list>
0450 
0451         <!-- including directives "op/multifile/discontigous" -->
0452         <list name="prolog state ISO">
0453             <item>multifile</item>
0454             <item>discontigous</item>
0455             <item>op</item>
0456             <item>set_prolog_flag</item>
0457         </list>
0458         <list name="types ISO">
0459             <item>var</item>
0460             <item>nonvar</item>
0461             <item>atom</item>
0462             <item>integer</item>
0463             <item>float</item>
0464             <item>number</item>
0465             <item>atomic</item>
0466             <item>compound</item>
0467             <item>callable</item>
0468             <item>ground</item>
0469         </list>
0470         <list name="built-ins ISO">
0471             <item>current_op</item>
0472             <item>current_prolog_flag</item>
0473             <item>current_input</item>
0474             <item>current_output</item>
0475 
0476             <!-- These act on streams, but the permission_error is only thrown
0477             if the programmer tries to set_input(S) when S is alread an output
0478             stream and vice versa; so: not affected by 'outside world' -->
0479             <item>set_input</item>
0480             <item>set_output</item>
0481 
0482             <!-- may throw a system_error in GNU -->
0483             <item>close</item>
0484 
0485             <item>flush_output</item>
0486 
0487             <!-- may throw permission_error in GNU if S is an output stream -->
0488             <item>at_end_of_stream</item>
0489 
0490             <item>stream_property</item>
0491         </list>
0492 
0493         <!-- !FOLD the <context> rules & comments for an overview, then it's no magic. -->
0494         <contexts>
0495         <!-- Catch typos: style="Syntax Error" for all rules except comments and
0496         quoted.  This helps to catch bugs in the rules itself, too.  Nice
0497         debuging aid.  Note that (naturally) some of the syntax rules given in
0498         EBNF are simplified and do not describe 100% valid Prolog.
0499 
0500             prolog text := shebang clause_seq | clause_seq
0501             clause_seq  := clause clause_seq | empty
0502             clause      := layout term_seq fullstop | term_seq fullstop
0503         -->
0504             <!-- shebang: ("#!") Detect shebang and fallthrough to clause_seq -->
0505             <context name="shebang" lineEndContext="clause" lineEmptyContext="clause" attribute="Syntax Error" fallthroughContext="clause">
0506                 <!-- no way: fallthroughContext="clause_seq" > -->
0507                 <Detect2Chars column="0" char="#" char1="!" context="1-comment" attribute="% italic predicates: w/ side effects" />
0508                 <!-- else fallthrough (workaround broken fallthrough) -->
0509             </context>
0510 
0511             <!-- syntax error (Test & Debug Aid, too): it's enough to highlight next token -->
0512             <context name="syntax_error" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0513                 <DetectSpaces context="#pop" attribute="Syntax Error" />
0514                 <DetectIdentifier context="#pop" attribute="Syntax Error" />
0515                 <RegExpr String="&any;" context="#pop" attribute="Syntax Error" />
0516             </context>
0517 
0518             <!-- clause: Start a region for code folding and switch to term -->
0519 <!--        <context name="clause" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" > -->
0520             <context name="clause" lineEndContext="#stay" attribute="Syntax Error" >
0521                 <IncludeRules context="layout" />
0522                 <!-- KISS: do not force term to detect an empty clause as syntax error -->
0523                 <RegExpr String="&fullstop_iso;" context="#stay" attribute="Warning (!use background)" />
0524 <!--            <RegExpr lookAhead="true" String="&any;" context="term" attribute="Syntax Error" /> -->
0525                 <RegExpr lookAhead="true" String="&any;" context="term" beginRegion="clause" attribute="Syntax Error" />
0526             </context>
0527 
0528             <!--term/nested/list/curly: the master/dispatcher -->
0529             <!-- (abbreviated): term := var | atomic | compound | "(" term ")"
0530 
0531             (term_seq := term "," term_seq | term    Not needed: comma is an op)
0532             term      := layout solo layout | layout solo | solo layout | solo
0533             solo      := var | atomic | compound | "(" term ")"
0534             compound  := op term | term op | term op term | functored | list
0535             functored := atom "(" arg_seq ")" | op "(" arg_seq ")"
0536             list      := "[" l_arg_seq "]" | double_quoted | "." "(" arg_seq ")"
0537             (if semantics of double_quoted not changed by set_prolog_flag/2)
0538             sorry I forgot curly: the DCG term but can not contain the fullstop.
0539 
0540             Comments in 'term' apply to the others as well.
0541             Note that eating layout once is enough, since we come back here.
0542             Only end the clause in the outmost term, which can only be term. -->
0543             <context name="term" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0544                 <IncludeRules context="layout" />
0545                 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
0546                 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
0547                 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
0548                 <AnyChar String="&comma;&cut;" context="#stay" attribute="Logic &amp; Control" />
0549                 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
0550                 <!-- lookAhead to give different style to the dot and the brace -->
0551                 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Syntax Error" />
0552 <!--            <RegExpr String="&fullstop_iso;" context="#pop" attribute="Logic &amp; Control" /> -->
0553                 <RegExpr String="&fullstop_iso;" context="#pop" endRegion="clause" attribute="Logic &amp; Control" />
0554                 <IncludeRules context="atomic" />
0555                 <!-- Default: anything not eaten here is a syntax error -->
0556             </context>
0557             <context name="nested" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0558                 <IncludeRules context="layout" />
0559                 <DetectChar char=")" context="#pop" endRegion="nested" attribute="( ) [ ]" />
0560                 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
0561                 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
0562                 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
0563                 <AnyChar String="&cut;&comma;" context="#stay" attribute="Logic &amp; Control" />
0564                 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
0565                 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
0566                 <RegExpr String="&fullstop_iso;" context="#stay" attribute="Warning (!use background)" />
0567                 <IncludeRules context="atomic" />
0568             </context>
0569             <context name="list" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0570                 <IncludeRules context="layout" />
0571                 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
0572                 <DetectChar char="]" context="#pop" endRegion="list" attribute="( ) [ ]" />
0573                 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
0574                 <DetectChar char="{" context="curly" beginRegion="curly" attribute="( ) [ ]" />
0575                 <AnyChar String="&comma;&cut;" context="#stay" attribute="Normal Text" />
0576                 <DetectChar char="&bar;" context="#stay" attribute="other built-in operator" />
0577                 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
0578                 <IncludeRules context="atomic" />
0579             </context>
0580             <context name="curly" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0581                 <IncludeRules context="layout" />
0582                 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
0583                 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
0584                 <DetectChar char="}" context="#pop" endRegion="curly" attribute="{ DCG }" />
0585                 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
0586                 <AnyChar String="&comma;&cut;" context="#stay" attribute="Logic &amp; Control" />
0587                 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
0588                 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
0589                 <IncludeRules context="atomic" />
0590             </context>
0591 
0592             <!--  arith_expr := expr op expr | op expr | expr op | "(" expr ")"
0593                         expr := number_expr | var | arith_expr
0594 
0595             This is only a goody to highlight arith ops and detect syntax errors.
0596             If it causes problems, disable it: exchange context="arith_expr" in
0597             "atomic" and "operator" below with context="#stay" (two or three occurrences) -->
0598             <context name="arith_expr" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0599                 <DetectChar char="(" context="nested_expr" beginRegion="nested" attribute="( ) [ ]" />
0600                 <!-- FIXME check if cut may be an op, else (and in any case 99.9% likely) it's a usual cut here -->
0601                 <!-- bar & dot could be a user-def'd op, pre-def'd ops could be
0602                 redef'd; but let's assume the default and just end the expr -->
0603                 <AnyChar lookAhead="true" String=")}]&bar;&cut;&comma;&bar;" context="#pop"/>
0604                 <RegExpr lookAhead="true" String="&fullstop_iso;|&logic_control_ops_iso;" context="#pop" attribute="Logic &amp; Control" />
0605                 <IncludeRules context="arith_expr_common" />
0606             </context>
0607             <context name="nested_expr" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0608                 <DetectChar char="(" context="nested_expr" beginRegion="nested" attribute="( ) [ ]" />
0609                 <DetectChar char=")" context="#pop" endRegion="nested" attribute="( ) [ ]" />
0610                 <!-- FIXME check if cut may be an op, else it's a syntax error here -->
0611                 <DetectChar char="&cut;" context="#stay" attribute="Normal Text" />
0612                 <DetectChar char="&comma;" context="#stay" attribute="Syntax Error" />
0613                 <!-- bar & dot could be a user-def'd op, pre-def'd ops could be redef'd; else these were errors -->
0614                 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
0615                 <RegExpr String="&logic_control_ops_iso;" context="#stay" attribute="other built-in operator" />
0616                 <IncludeRules context="arith_expr_common" />
0617             </context>
0618 
0619             <!-- list functor: assign style to the dot and let term/list/curly take the brace
0620             (We have no style "built-in term", so take "Normal text" or "built-in predicate")
0621             ASSERT 1st is the dot, else "Syntax Error" INTENTIONALLY -->
0622             <context name="list_functor" lineEndContext="syntax_error" attribute="Syntax Error" >
0623                 <DetectChar char="&dot;" context="#pop" attribute="other built-in predicate" />
0624             </context>
0625 
0626             <!-- single/double/back-quoted: handle esc seq and closing quote
0627             Comments in single-quoted apply to the others as well.
0628             Entry point is single/double/back-quoted (only to handle syntax error:
0629             nl after opening quote), sq/dq/bq is inside the string.
0630             lineEndContext should be "syntax_error", but then we couldn't handle
0631             a valid esc'd line continuation.  So we do that 'in vitro' (took me
0632             2 days w/ a plethora of useless rules to solve that puzzle LOL).
0633             On error must not #stay, else the error isn't shown iff white or empty -->
0634             <context name="sq" lineEndContext="#stay" attribute="'quo Ted'" noIndentationBasedFolding="true">
0635 <!--        <context name="single-quoted" lineEndContext="#stay" attribute="'quo Ted'" > -->
0636                 <IncludeRules context="quoted_1st"/>
0637                 <!-- un-esc'd nl is a syntax error; match max seq (+), else the
0638                 error is only shown in the next line -->
0639                 <RegExpr String="(''|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^'\\]+)$"
0640                         context="syntax_error_sq" attribute="Syntax Error" />
0641                 <!-- Usual handling: -->
0642                 <Detect2Chars char="'" char1="'" context="#stay" attribute="escaped (!use background)" />
0643                 <DetectChar char="'" context="#pop#pop" endRegion="quoted" attribute="'quo Ted'" />
0644                 <IncludeRules context="quoted_last"/>
0645                 <!-- Default: literal content of the quoted string, context's style applies -->
0646             </context>
0647             <context name="dq" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" noIndentationBasedFolding="true" >
0648 <!--        <context name="double-quoted" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" > -->
0649                 <IncludeRules context="quoted_1st"/>
0650                 <RegExpr String="(&quot;&quot;|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^&quot;\\]+)$"
0651                         context="syntax_error_dq" attribute="Syntax Error" />
0652                 <Detect2Chars char="&quot;" char1="&quot;" context="#stay" attribute="escaped (!use background)" />
0653                 <DetectChar char="&quot;" context="#pop#pop" endRegion="quoted" attribute="&quot;double-quoted&quot;" />
0654                 <IncludeRules context="quoted_last"/>
0655             </context>
0656             <context name="bq" lineEndContext="#stay" attribute="`back-quoted`" noIndentationBasedFolding="true" >
0657 <!--        <context name="back-quoted" lineEndContext="#stay" attribute="`back-quoted`" > -->
0658                 <IncludeRules context="quoted_1st"/>
0659                 <RegExpr String="(``|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^`\\]+)$"
0660                         context="syntax_error_bq" attribute="Syntax Error" />
0661                 <Detect2Chars char="`" char1="`" attribute="escaped (!use background)" />
0662                 <DetectChar char="`" context="#pop#pop" endRegion="quoted" attribute="`back-quoted`" />
0663                 <IncludeRules context="quoted_last"/>
0664             </context>
0665             <context name="single-quoted" lineEndContext="#stay" attribute="'quo Ted'" >
0666                 <LineContinue char="'" context="sq" beginRegion="quoted" attribute="Syntax Error" />
0667                 <DetectChar char="'" context="sq" beginRegion="quoted" attribute="'quo Ted'" />
0668             </context>
0669             <context name="double-quoted" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" >
0670                 <LineContinue char="&quot;" context="dq" beginRegion="quoted" attribute="Syntax Error" />
0671                 <DetectChar char="&quot;" context="dq" beginRegion="quoted" attribute="&quot;double-quoted&quot;" />
0672             </context>
0673             <context name="back-quoted" lineEndContext="#stay" attribute="`back-quoted`" >
0674                 <LineContinue char="`" context="bq" beginRegion="quoted" attribute="Syntax Error" />
0675                 <DetectChar char="`" context="bq" beginRegion="quoted" attribute="`back-quoted`" />
0676             </context>
0677 
0678             <!-- syntax_error_q: highlight next token and proceed normal afterwards -->
0679             <context name="syntax_error_sq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0680                 <Detect2Chars char="\" char1="'" context="#pop" attribute="Syntax Error" />
0681                 <Detect2Chars char="'" char1="'" context="#pop" attribute="Syntax Error" />
0682                 <DetectChar char="'" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
0683                 <IncludeRules context="syntax_error"/>
0684             </context>
0685             <context name="syntax_error_dq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0686                 <Detect2Chars char="\" char1="&quot;" context="#pop" attribute="Syntax Error" />
0687                 <Detect2Chars char="&quot;" char1="&quot;" context="#pop" attribute="Syntax Error" />
0688                 <DetectChar char="&quot;" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
0689                 <IncludeRules context="syntax_error"/>
0690             </context>
0691             <context name="syntax_error_bq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
0692                 <Detect2Chars char="\" char1="`" context="#pop" attribute="Syntax Error" />
0693                 <Detect2Chars char="`" char1="`" context="#pop" attribute="Syntax Error" />
0694                 <DetectChar char="`" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
0695                 <IncludeRules context="syntax_error"/>
0696             </context>
0697 
0698             <!-- char_code (after "0'"): esc seq, singleq twice, or any other -->
0699             <context name="char_code" lineEndContext="#pop" attribute="Syntax Error" >
0700                 <Detect2Chars char="'" char1="'" context="#pop" attribute="escaped (!use background)" />
0701                 <DetectChar char="'" context="#pop" attribute="Syntax Error" />
0702                 <DetectChar char="&bs;" context="esc_seq_cc" attribute="escaped (!use background)" />
0703                 <DetectChar char="&tab;" context="#pop" attribute="Warning (!use background)" />
0704                 <!-- Default _AND IF_ esc_seq #pops back here; we need this to #pop out -->
0705                 <RegExpr String="&any;" context="#pop" attribute="0'a (!use background)" />
0706             </context>
0707             <!-- "0'" or "0'\" at EOL is a syntax error, catched below.  If
0708             possible, highlight white @next line to make clear error is the nl -->
0709             <context name="syntax_error_cc" lineEndContext="#stay" attribute="Syntax Error"
0710                     fallthroughContext="#pop" >
0711                 <DetectSpaces context="#pop" attribute="Syntax Error" />
0712             </context>
0713 
0714             <!-- esc_seq: it's not worth it to handle common for quoted and cc
0715             esc_seq_q: handle only cc in bs (e.g. "\007\"), else -> esc_seq_q2
0716             ASSERT esc'd newline is handled by the calling context
0717             ASSERT we get the leading bs here to highlight the whole thing -->
0718             <context name="esc_seq_q" lineEndContext="syntax_error" attribute="Syntax Error" >
0719                 <RegExpr String="&esc_oct_iso;|&esc_hex_iso;" context="#pop" attribute="0'a (!use background)" />
0720                 <DetectChar char="&bs;" context="esc_seq_q2" attribute="escaped (!use background)" />
0721             </context>
0722             <!-- esc_seq_cc: #pop#pop out of cc on std esc seq, else pass char back
0723             ASSERT we do NOT need the leading bs here anymore -->
0724             <context name="esc_seq_cc" fallthroughContext="#pop"
0725                     lineEndContext="#pop#pop" attribute="Syntax Error" >
0726                 <DetectChar char="&tab;" context="#pop#pop" attribute="Warning (!use background)" />
0727                 <AnyChar String="&any_esc_iso;" context="#pop#pop" attribute="escaped (!use background)" />
0728             </context>
0729             <!-- esc_seq_q2: Handle standard esc seq in quoted else pass char back
0730             ASSERT we do NOT need the leading bs here anymore -->
0731             <context name="esc_seq_q2" fallthroughContext="#pop#pop"
0732                     lineEndContext="syntax_error" attribute="Syntax Error" >
0733                 <DetectChar char="&tab;" context="#pop#pop" attribute="Warning (!use background)" />
0734                 <AnyChar String="&any_esc_iso;" context="#pop#pop" attribute="escaped (!use background)" />
0735             </context>
0736 
0737             <!-- id,var,graphic: ASSERT calling context ashured 1st char is ok
0738                                  ASSERT we get the 1st char for id & var -->
0739             <context name="id" attribute="Syntax Error" lineEndContext="#stay" >
0740                 <DetectIdentifier context="#pop" attribute="Normal Text" />
0741             </context>
0742             <context name="var" attribute="Syntax Error" lineEndContext="#stay" >
0743                 <DetectIdentifier context="#pop" attribute="_VARIABLE" />
0744             </context>
0745             <context name="graphic" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
0746                 <AnyChar String="&any_graphic_iso;" context="#stay" attribute="Normal Text" />
0747             </context>
0748 
0749             <!-- numbers (after "0[box]") -->
0750             <context name="bin" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
0751                 <AnyChar String="&any_bin_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
0752             </context>
0753             <context name="oct" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
0754                 <AnyChar String="&any_oct_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
0755             </context>
0756             <context name="hex" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
0757                 <AnyChar String="&any_hex_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
0758             </context>
0759 
0760             <!-- comment-iso: multi-line comment, handle closing "*/" -->
0761             <context name="comment-iso" lineEndContext="#stay" attribute="% italic predicates: w/ side effects" >
0762             <!-- Nested comments are not allowed in strict ISO-Prolog - - >
0763                 <Detect2Chars char="/" char1="*" context="comment" beginRegion="comment"
0764                             attribute="% italic predicates: w/ side effects" />-->
0765                 <Detect2Chars char="*" char1="/" context="#pop" endRegion="comment"
0766                             attribute="% italic predicates: w/ side effects" />
0767                 <DetectSpaces />
0768                 <IncludeRules context="##Comments" />
0769                 <DetectIdentifier />
0770             </context>
0771 
0772             <!-- 1-line comment: #pop@EOL  -->
0773             <!-- Folding for consecutive 1-line comments: let indentation-based auto-folding work -->
0774             <context name="1-comment" lineEndContext="#pop" attribute="% italic predicates: w/ side effects" >
0775                 <DetectSpaces />
0776                 <IncludeRules context="##Comments" />
0777                 <DetectIdentifier />
0778             </context>
0779             <context name="region_marker" lineEndContext="#pop" attribute="%BEGIN folding region" noIndentationBasedFolding="true" >
0780                 <IncludeRules context="1-comment" />
0781             </context>
0782             <context name="layout_fold" lineEndContext="#stay" attribute="Syntax Error"
0783                     fallthroughContext="#pop" >
0784                 <DetectSpaces attribute="Normal Text" />
0785                 <StringDetect String="%BEGIN" context="region_marker" attribute="%BEGIN folding region"
0786                             firstNonSpace="true" beginRegion="user_region" />
0787                 <StringDetect String="%END" context="region_marker" attribute="%BEGIN folding region"
0788                             firstNonSpace="true" endRegion="user_region" />
0789                 <DetectChar firstNonSpace="true" char="%" context="1-comment" attribute="% italic predicates: w/ side effects" />
0790             </context>
0791 
0792 <!--####### BEGIN sub rules to be included - <context> never taken -->
0793 
0794             <!-- Common for all quoted: Handle line continuation, esc seq, and most other input efficiently -->
0795             <context name="quoted_1st" lineEndContext="#stay" attribute="Syntax Error" >
0796                 <LineContinue attribute="escaped (!use background)" />
0797                 <DetectSpaces column="0" attribute="escaped (!use background)" />
0798             </context>
0799             <context name="quoted_last" lineEndContext="#stay" attribute="Syntax Error" >
0800                 <DetectChar lookAhead="true" char="&bs;" context="esc_seq_q" attribute="Syntax Error" />
0801                 <DetectChar char="&tab;" attribute="Warning (!use background)" />
0802                 <DetectIdentifier />
0803                 <DetectSpaces />
0804             </context>
0805 
0806             <!-- layout_seq := layout layout_seq
0807                      layout := " " | tab | nl | comment -->
0808             <context name="layout" lineEndContext="#stay" attribute="Syntax Error" >
0809                 <DetectSpaces attribute="Normal Text" />
0810                 <Detect2Chars char="/" char1="*" context="comment-iso" attribute="% italic predicates: w/ side effects"
0811                             beginRegion="comment" />
0812                 <StringDetect String="%BEGIN" context="region_marker" attribute="%BEGIN folding region"
0813                             firstNonSpace="true" beginRegion="user_region" />
0814                 <StringDetect String="%END" context="region_marker" attribute="%BEGIN folding region"
0815                             firstNonSpace="true" endRegion="user_region" />
0816                 <DetectChar firstNonSpace="true" char="%" context="layout_fold" attribute="% italic predicates: w/ side effects"
0817                             lookAhead="true" />
0818                 <DetectChar firstNonSpace="false" char="%" context="1-comment" attribute="% italic predicates: w/ side effects" />
0819             </context>
0820 
0821             <!--atomic: the work horse -->
0822             <!-- (simplified) atomic := atom | number | op | var -->
0823             <context name="atomic" lineEndContext="#stay" attribute="Syntax Error" >
0824                 <!-- NOTE the order of rules is important... (as always)
0825                 Predefined 1st, unknown (user defined) last -->
0826                 <keyword String="logic+control ISO" context="#stay" attribute="Logic &amp; Control" />
0827                 <keyword String="types ISO" context="#stay" attribute="Type Checking" />
0828                 <keyword String="dyn clause mgmt ISO" context="#stay" attribute="Dynamic Clause Management" />
0829                 <keyword String="streams ISO" context="#stay" attribute="Stream I/O" />
0830                 <keyword String="terms ISO" context="#stay" attribute="other built-in predicate" />
0831                 <keyword String="prolog state ISO" context="#stay" attribute="Prolog State" />
0832                 <keyword String="DCG non-ISO" context="#stay" attribute="{ DCG }" />
0833                 <keyword String="arith eval ISO" context="arith_expr" attribute="Arithmetics" />
0834                 <!-- These are user predicates outside arit_expr -->
0835 <!--            <keyword String="arith expr mixed ISO" context="#stay" attribute="other built-in predicate" /> -->
0836 <!--            <keyword String="arith expr int ISO" context="#stay" attribute="other built-in predicate" /> -->
0837 <!--            <keyword String="arith expr float ISO" context="#stay" attribute="other built-in predicate" /> -->
0838                 <keyword String="built-ins ISO" context="#stay" attribute="other built-in predicate" />
0839                 <keyword String="error term ISO" context="#stay" attribute="Guru Meditation" />
0840                 <keyword String="guru meditation terms ISO" context="#stay" attribute="Guru Meditation Terms" />
0841                 <keyword String="bogus ISO" context="#stay" attribute="ISO Bogus" />
0842 
0843                 <!-- Match char code before quoted and ops... -->
0844                 <IncludeRules context="number" />
0845 
0846                 <!-- these depend on current_prolog_flag/2 so can all return a term i.e. a list (of char codes) -->
0847                 <DetectChar lookAhead="true" char="'" context="single-quoted" attribute="'quo Ted'" />
0848                 <DetectChar lookAhead="true" char="`" context="back-quoted" attribute="`back-quoted`" />
0849                 <DetectChar lookAhead="true" char="&quot;" context="double-quoted" attribute="&quot;double-quoted&quot;" />
0850 
0851                 <!-- ...and ops before atoms, else "div", "is" etc. are usual atoms -->
0852                 <IncludeRules context="operator" />
0853                 <AnyChar lookAhead="true" String="&any_lower_iso;" context="id" attribute="Normal Text" />
0854                 <AnyChar lookAhead="true" String="&any_upper_under_iso;" context="var" attribute="_VARIABLE" />
0855                 <AnyChar String="&any_graphic_iso;" context="graphic" attribute="Normal Text" />
0856             </context> <!-- atomic -->
0857 
0858             <!-- [(mostly) "atomic" for] arith_expr := arith_op | number_expr | var
0859                                       number_expr := number | built-in | user-def
0860 
0861             This is only a goody to highlight arith ops and detect syntax errors.
0862             If it causes problems, disable it: exchange context="arith_expr" in
0863             contexts "atomic" and "operator" with context="#stay" -->
0864             <context name="arith_expr_common" lineEndContext="#stay" attribute="Syntax Error" >
0865                 <IncludeRules context="layout" />
0866                 <IncludeRules context="number" />
0867                 <keyword String="bogus ISO" context="#stay" attribute="ISO Bogus" />
0868                 <keyword String="arith expr mixed ISO" context="#stay" attribute="Arithmetics" />
0869                 <keyword String="arith expr int ISO" context="#stay" attribute="Integer Arithmetics" />
0870                 <keyword String="arith expr float ISO" context="#stay" attribute="Float Arithmetics" />
0871                 <keyword String="arith ops int ISO" context="#stay" attribute="Integer Arithmetics" />
0872                 <RegExpr String="&arith_compare_iso;" context="#pop" attribute="Syntax Error" />
0873                 <RegExpr String="&arith_ops_mixed_iso;" context="#stay" attribute="Arithmetics" />
0874                 <RegExpr String="&arith_ops_int_iso;" context="#stay" attribute="Integer Arithmetics" />
0875                 <RegExpr String="&arith_ops_float_iso;" context="#stay" attribute="Float Arithmetics" />
0876                 <RegExpr String="&arith_bogus_iso;" context="#stay" attribute="ISO Bogus" />
0877                 <!-- do not miss user-def'd arithmetic expr and number expr-->
0878                 <IncludeRules context="operator" />
0879                 <AnyChar lookAhead="true" String="&any_lower_iso;" context="id" attribute="Normal Text" />
0880                 <AnyChar lookAhead="true" String="&any_upper_under_iso;" context="var" attribute="_VARIABLE" />
0881                 <AnyChar String="&any_graphic_iso;" context="graphic" attribute="Normal Text" />
0882             </context>
0883 
0884             <!-- number := float | integer
0885                 integer := decimal | baseN | "0'" char_code
0886                 baseN   := "0b" [01]+ | "0o" [0-7]+ | "0x" [0-9a-fA-F]+ -->
0887             <context name="number" lineEndContext="#pop" attribute="Syntax Error" >
0888                 <!-- Match integers after other numbers -->
0889                 <!-- FIXME a minus may precede all numbers and is part of the number! -->
0890                 <RegExpr String="0'\\?$" context="syntax_error_cc" attribute="Syntax Error" />
0891                 <Detect2Chars char="0" char1="'" context="char_code" attribute="0'a (!use background)" />
0892 
0893 <!-- NOT: [box] could be a postfix op <RegExpr String="0[box]$" context="#stay" attribute="Syntax Error" /> -->
0894                 <Detect2Chars char="0" char1="b" context="bin" attribute="0b1001 0o007 0xF1" />
0895                 <Detect2Chars char="0" char1="o" context="oct" attribute="0b1001 0o007 0xF1" />
0896                 <Detect2Chars char="0" char1="x" context="hex" attribute="0b1001 0o007 0xF1" />
0897 
0898                 <RegExpr String="&float1_iso;|&float2_iso;|&float3_iso;" context="#stay" attribute="2.718281E-9" />
0899                 <Int context="#stay" attribute="1  2  3  42" />
0900             </context>
0901 
0902             <!-- operator := predefined_op | dynamic_op (which we can not detect)
0903             comma, single dot & bar are catched earlier above in term/list/curly -->
0904             <context name="operator" lineEndContext="#pop" attribute="Syntax Error" >
0905                 <keyword String="arith eval ISO" context="arith_expr" attribute="Arithmetics" />
0906                 <keyword String="arith ops int ISO" context="#stay" attribute="other built-in operator" />
0907                 <RegExpr String="&logic_control_ops_iso;" context="#stay" attribute="Logic &amp; Control" />
0908                 <RegExpr String="&predefined_ops_iso;" context="#stay" attribute="other built-in operator" />
0909                 <RegExpr String="&dcg_production_iso;" context="#stay" attribute="{ DCG }" />
0910                 <RegExpr String="&arith_compare_iso;" context="arith_expr" attribute="Arithmetics" />
0911                 <RegExpr String="&arith_ops_mixed_iso;|&arith_ops_int_iso;|&arith_ops_float_iso;" context="#stay" attribute="other built-in operator" />
0912                 <RegExpr String="&arith_bogus_iso;" context="#stay" attribute="ISO Bogus" />
0913             </context>
0914 
0915 <!--####### END sub rules to be included - <context> never taken -->
0916         </contexts>
0917 
0918         <!-- The idea is to give all predicates that may be affected by the
0919         "outside world" a common style (italic).  I.e. these can throw a
0920         permission, evaluation, representation or resource_error, even though
0921         the program itself is 100% correct.  E.g. you get_char/2 a char code 1
0922         from a text stream (representation_error): not your mistake, but you
0923         have to deal with that, too. -->
0924         <itemDatas>
0925             <itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" />
0926             <itemData name="_VARIABLE" defStyleNum="dsDataType" bold="false" spellChecking="false" />
0927             <itemData name="'quo Ted'" defStyleNum="dsString" />
0928             <itemData name="`back-quoted`" defStyleNum="dsString" italic="true" />
0929             <!-- The standard wants double-quoted to be a list of char codes, but
0930             e.g. GNU Prolog allows that to be set with set_prolog_flag/2 -->
0931             <itemData name="&quot;double-quoted&quot;" defStyleNum="dsOthers" />
0932             <itemData name="escaped (!use background)" defStyleNum="dsChar" spellChecking="false"
0933                          backgroundColor="#0C0C0C" selBackgroundColor="#FFFFFF" />
0934 
0935             <!-- Numbers -->
0936             <itemData name="2.718281E-9" defStyleNum="dsFloat" spellChecking="false" />
0937             <itemData name="1  2  3  42" defStyleNum="dsDecVal" spellChecking="false" />
0938             <itemData name="0b1001 0o007 0xF1" defStyleNum="dsBaseN" spellChecking="false" />
0939             <itemData name="0'a (!use background)" defStyleNum="dsBaseN" spellChecking="false"
0940                          backgroundColor="#0C0C0C" selBackgroundColor="#FFFFFF" />
0941 
0942             <itemData name="( ) [ ]" defStyleNum="dsNormal" spellChecking="false" />
0943             <itemData name="{ DCG }" defStyleNum="dsKeyword" spellChecking="false" />
0944             <itemData name="Prolog State" defStyleNum="dsFunction" bold="true" spellChecking="false" />
0945             <itemData name="Type Checking" defStyleNum="dsDataType" spellChecking="false" />
0946             <itemData name="Logic &amp; Control" defStyleNum="dsKeyword" spellChecking="false" />
0947             <itemData name="other built-in operator" defStyleNum="dsFunction" spellChecking="false" />
0948             <itemData name="other built-in predicate" defStyleNum="dsFunction" spellChecking="false" />
0949 
0950             <!-- Comments (2nd not used, just a hint) -->
0951             <itemData name="% italic predicates: w/ side effects" defStyleNum="dsComment" />
0952 
0953             <!-- Predicates affected by 'outside world' -->
0954             <itemData name="Dynamic Clause Management" defStyleNum="dsKeyword" italic="true" spellChecking="false" />
0955             <itemData name="Stream I/O" defStyleNum="dsFunction" italic="true" spellChecking="false" />
0956 
0957             <!-- arithmetics: get the color of ints/floats; includes ops & expressions like pi -->
0958             <itemData name="Arithmetics" defStyleNum="dsDataType" bold="true" italic="true" spellChecking="false" />
0959             <itemData name="Integer Arithmetics" defStyleNum="dsDecVal" bold="true" italic="true" spellChecking="false" />
0960             <itemData name="Float Arithmetics" defStyleNum="dsFloat" bold="true" italic="true" spellChecking="false" />
0961             <itemData name="ISO Bogus" defStyleNum="dsAlert" bold="true" italic="true" spellChecking="false" />
0962 
0963             <!-- no way w/ buggy kate 3.8.5: get the color of default style dsError for error and terms -->
0964             <itemData name="Guru Meditation" defStyleNum="dsNormal" spellChecking="false"
0965                     bold="true" italic="false" underline="false" color="#FF0000" selColor="#00FFFF" />
0966             <itemData name="Guru Meditation Terms" defStyleNum="dsNormal" spellChecking="false"
0967                     bold="false" italic="true" underline="false" color="#FF0000" selColor="#00FFFF" />
0968             <itemData name="Syntax Error" defStyleNum="dsError" spellChecking="false" />
0969             <itemData name="Warning (!use background)" defStyleNum="dsAlert" spellChecking="false"
0970                         backgroundColor="#FC000C" selBackgroundColor="#03FFF3" />
0971             <itemData name="%BEGIN folding region" defStyleNum="dsRegionMarker" spellChecking="false" />
0972         </itemDatas>
0973     </highlighting>
0974     <general>
0975         <keywords casesensitive="true" additionalDeliminator="$#'&quot;`" />
0976         <!-- let indentationsensitive folding provide it's magic -->
0977         <folding indentationsensitive="true" />
0978 <!--    <EmptyLines> -->
0979 <!--        <EmptyLine regexpr="^[ /t]*(?!%).*$" /> -->
0980 <!--    </EmptyLines> -->
0981         <comments>
0982             <comment name="singleLine" start="%" position="afterwhitespace" />
0983             <comment name="multiLine" start="/*" end="*/" region="comment" />
0984         </comments>
0985     </general>
0986 </language>
0987 <!--##### NOTE [HOWTO check your syntax file, extracted from language.dtd] #####
0988 
0989         Copyright (c) 2001 Joseph Wenninger <jowenn@kde.org>
0990         modified (c) 2002 Anders Lund <anders@alweb.dk>
0991         modified (c) 2003 Simon Huerlimann <simon.huerlimann@access.unizh.ch>
0992         modified (c) 2005 Dominik Haumann <dhdev@gmx.de>
0993         modified (c) 2008 Wilbert Berendsen <info@wilbertberendsen.nl>
0994 
0995     You can validate your syntax files using checkXML from the development
0996     package of kdelibs [author: i.e. kdelibs-dev]:
0997 
0998         checkXML yourSyntax.xml [author: | grep -v 'no template matches']
0999 
1000     If you see any 'validity error' lines, you should fix them. If you get
1001     a lot of 'No template matches' lines, everything's just fine. You've
1002     produced a valid syntax file!
1003 
1004     It's also possible to use the (much faster) xmllint which comes with the
1005     GNOME (oops:-) XML Library libxml2:
1006 
1007         xmllint - -dtdvalid language.dtd yourSyntax.xml
1008         (don't use a space between the two - [author: dashes/minus]
1009         That's just because XML comments don't allow that:-(
1010 
1011     To use your syntax file, copy it to .kde/share/apps/katepart/syntax/ in
1012     your home directory. You have to open a new instance of kwrite/kate to use
1013     the new syntax file.
1014 -->
1015 <!-- kate: replace-tabs off; -->