Debian Codegraph @

data/syntax/prolog.xml

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- [Purpose & Copyright]
3
4 Highlight ISO-Prolog texts or template/include for Prolog dialects
5 based on the ISO standard.
6
7 Includes detection of DCG since it is 'hooked' in the ISO standard.
8 Uses text style "Warning/ISO-bogus" where portability is likely to
9 fail.
10
11 This file is part of KDE's kate project.
12
13 copyright : (C) 2012 by Torsten Eichstädt
14
15 **********************************************************************
16 * This library is free software; you can redistribute it and/or *
17 * modify it under the terms of the GNU Library General Public *
18 * License as published by the Free Software Foundation; either *
19 * version 2 of the License, or (at your option) any later version. *
20 * *
21 * This library is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
24 * Library General Public License for more details. *
25 * *
26 * You should have received a copy of the GNU Library General Public *
27 * License along with this library; if not, write to the *
28 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
29 * Boston, MA 02110-1301, USA. *
30 **********************************************************************
31 -->
32 <!DOCTYPE language
33 [<!-- [Regular Expressions, Character Classes & Important Tokens]
34 E.g. the dot "." has so many different meanings (i.e. in an RegExpr 'any char',
35 'fullstop' of a clause, etc. pp.) that I decided it's usefull to write these out
36 to make the rules more expressive. -->
37
38 <!-- RegExpr for graphic tokens. Comment start "/*" is catched earlier. -->
39 <!ENTITY gr_char_iso "[#$&amp;*+\-./:&lt;=>?@^~\\]">
40
41 <!-- RegExpr: The highlighting engine always strips newline, so this ok: -->
42 <!ENTITY any_nw "[^ \t]">
43 <!ENTITY any ".">
44
45 <!-- RegExpr: we want to highlight some graphic tokens: Logic & Control
46 fullstop shall not be falsely detected if it is actually a list functor
47 comma is catched extra to highlight it as "Normal Text" in an arg_seq
48 (and the cut "!" is NOT an op) -->
49 <!ENTITY fullstop_iso "\.(?!(\(|&gr_char_iso;))">
50 <!ENTITY logic_control_ops_iso "(;|->|\\\+|:-|=|\\=)(?!&gr_char_iso;)">
51
52 <!-- RegExpr: DCG (not my idea it is not reversed and named 'reduction') -->
53 <!ENTITY dcg_production_iso "-->(?!&gr_char_iso;)">
54
55 <!-- RegExpr: partitioning of arithmetic operators:
56 - the 1st "arith_compare" always demand arithmetic evaluation
57 => highlight as "Arithmetics".
58 - the 2nd only at the right side of "is" or when an arith_compare applies.
59 They are used in other contexts as well, e.g. traditionally A-B is used
60 for 'a pair of something', the "^" in bagof/3 and setof/3.
61 => highlight as "Arithmetics" only in an arith_expr.
62 - the 3rd are true ISO Bogus: it is not specified whether it is arithmetic
63 or logical shift, and for bitwise AND, OR and NEG the integer format is
64 unspecified => not portable, depend on Prolog implementation. -->
65 <!ENTITY arith_compare_iso "(=:=|=\\=|=&lt;|&lt;|>=|>)(?!&gr_char_iso;)">
66 <!ENTITY arith_ops_mixed_iso "(\+|-|\*|\^)(?!&gr_char_iso;)">
67 <!ENTITY arith_ops_int_iso "//(?!&gr_char_iso;)">
68 <!ENTITY arith_ops_float_iso "(/|\*\*)(?!&gr_char_iso;)">
69 <!ENTITY arith_bogus_iso "(/\\|\\/|\\|&lt;&lt;|>>)(?!&gr_char_iso;)">
70
71 <!-- RegExpr: other predefined operators -->
72 <!ENTITY predefined_ops_iso "(\?-|==|\\==|@=&lt;|@&lt;|@>=|@>|=\.\.|@|:)(?!&gr_char_iso;)">
73
74 <!-- We treat a number as float if it includes a decimal dot or exponent -->
75 <!ENTITY float3_iso "[0-9]+E[+\-]?[0-9]+">
76 <!ENTITY float2_iso "[0-9]+\.[0-9]+">
77 <!ENTITY float1_iso "[0-9]+\.[0-9]+E[+\-]?[0-9]+">
78
79 <!-- RegExpr for esc'd char code in quoted 'strings' e.g. "\007\" -->
80 <!ENTITY esc_oct_iso "\\[0-7]+\\">
81 <!ENTITY esc_hex_iso "\\x[a-fA-F0-9]+\\">
82
83 <!-- Char classes for AnyChar, NOT RegExpr: no esc seqs, ranges, etc. pp. here!
84 Used to avoid expensive RegExpr whenever possible. -->
85 <!-- Not needed: any_alnum_under_iso: use "DetectIdentifier" instead -->
86 <!ENTITY any_lower_iso "abcdefghijklmnopqrstuvwxyz">
87 <!ENTITY any_upper_under_iso "ABCDEFGHIJKLMNOPQRSTUVWXYZ_">
88 <!ENTITY any_bin_iso "01">
89 <!ENTITY any_oct_iso "01234567">
90 <!ENTITY any_dec_iso "0123456789">
91 <!ENTITY any_hex_iso "0123456789abcdefABCDEF">
92 <!ENTITY any_graphic_iso "#$&amp;*+-./:&lt;=>?@^~\">
93
94 <!-- Common esc seq in quoted & char code (after "0'").
95 Tab is handled extra. Esc'd newline is catched earlier. -->
96 <!ENTITY any_esc_iso "abfnrtv\'`&quot;]">
97
98 <!ENTITY dot ".">
99
100 <!-- Some solo chars for DetectChar -->
101 <!ENTITY comma ",">
102 <!ENTITY cut "!">
103 <!ENTITY bar "|">
104 <!ENTITY tab "&#x9;">
105 <!ENTITY bs "\">
106 ]>
107 <language name="Prolog" section="Sources"
108 version="17" kateversion="5.62"
109 mimetype="text/x-prolog"
110 extensions="*.prolog;*.dcg;*.pro"
111 author="Torsten Eichstädt ([email protected])"
112 license="LGPLv2+">
113
114 <!-- [Terminology & Abbreviations In The Comments]
115 - Literal text is in double quotes "like this", single quotes sometimes used
116 for a 'terminus technicus'.
117 - "w/", "w/o", "s/t" mean 'with', 'without', and "sometimes" resp.
118 - Use "brace" instead of 'bracket'/'parenthesis' for any of "()[]{}"
119 - Specify "round", "list/squared", "curly", "opening" and "closing" brace.
120 - "quote/quoted/string" mean any of single-, double-, or back-quote(d)
121 - "seq" sequence, "nl" newline, "bs" backslash, "q" quote(d), "cc" char code
122 - "KISS" Keep it simple, stupid! (be pragmatic)
123 - "style" = "attribute" (the applied text style)
124 - Keep comments as short as possible and as descriptive as neccessary LOL
125 -->
126 <!-- [Documentation, Bugs, Limitations & Solutions, TODOs]
127 ################################################################################
128 All bugs except three by the author. !FOLD THIS AWAY if long comments annoy you.
129
130 BUG - Nobody's perfect - If I knew about the bug you found, it would have been
131 fixed already.
132 one- Indentation-based folding is not reliable (Kate; fixed in KDE 4.9?).
133 two- Folding is sometimes broken (Kate?). See SOLUTIONS below.
134 three- An optional leading sign is not highlighted as part of the number.
135 4 - A float w/o fractional part and exponent is highlighted as an integer.
136 5 - Detection of whitespace may not be 100% correct, only space/tab/newline.
137 6 - Handling inside arithmetic expressions might not be 100%. See "AL GUSTO".
138 inf- see TODOs below.
139
140 LIMITS of this parser
141 - Highlighting of syntax errors is as intuitive as possible, i.e. for an
142 invalid newline highlight the last token before and leading white of the
143 next line - but that's not always possible. Use your built-in problem
144 solver (between your ears) when you do not know what the exact error is.
145 - The parser knows nothing about currently defined dynamic ops, but has to
146 respect possible definitions of dynamic ops. That's why:
147 - Any sequence of 'graphic chars' (_incl. those containing a dot_) is taken
148 as _one_ graphic token, and not - as you might expect - your user-defined
149 operator followed by fullstop (or sequence of ops).
150 - A single dot in the outmost term of a clause is taken as a fullstop, even
151 if it is actually a user-defined operator.
152 - Else, a single dot is highlighted as "Warning" because it might be a
153 user-def'd op (usually an error, but can not decide w/o current_op/3).
154 - Detection of the fullstop relies upon the usual semantics of braces.
155 - Axioms of folding capabilities are: the literal fullstop as stop symbol
156 and the usual semantics of braces w/ pairs of opening and closing brace.
157 ?- period.
158 uncaught exception: error(existence_error(procedure,current_op/3),highlight/2)
159
160 SOLUTIONS
161 - Help the parser by puting whitespace (space/tab/nl) here and there, espc.
162 after the fullstop, or use quotes; e.g. '/*' does not begin a comment,
163 neither does '%', and ***'.' can be two operators.
164 Functored syntax should always do, e.g. */*(X,Y) is valid (and does not
165 begin a comment).
166 - Folding: s/t moving the mouse slightly below the marker shows what you
167 want, s/t an empty line helps (or removing an empty line), when it's
168 removed regions stay ok, or break auto-folding w/ non-white @begin of
169 line. Try a newer kate version.
170
171 AL GUSTO (simple changes):
172 - Change classification of built-in predicates: adjust the <list> below.
173 - Reminder for other changes: solo chars - DetectChar, graphic - RegExpr.
174 - bar "|" (solo) is highlighted as "other built-in operator" in lists, else
175 "Normal Text". You may safely remove/comment out the rules in contexts
176 "term/list/curly" below if you add in in context "operator" or "atomic".
177 If it shall be part of user-defined ops, it has to be added to "gr_char",
178 and a few rules need adjustment. Search for "&bar;". You may then safely
179 add it to "predefined_ops" above (don't forget to escape it).
180 - cut "!" (solo) can be adjusted like the bar.
181 - comma "," (solo) is "Normal Text" in lists, else "Logic & Control". You
182 may safely remove/comment out the rules in "term/nested/list/curly" below
183 and handle it in the context "operator".
184 - Disable arith_expr: replace "context="arith_expr"" w/ "context="#stay""
185 in the rules in contexts "atomic" and "operator" (two or three occurrences).
186 - Disable indentation-based folding: in the section "general"@EOF:"folding".
187 - General guidelines: Be nice to slow/old hardware: avoid RegExpr (start w/
188 a RegExpr, test, then find a replacement), else match a RegExpr as late as
189 possible - it's expensive, a context switch is relatively cheap.
190 Eat as much text as possible in one run, e.g. in comments and quoted we
191 use "DetectIdentifier", else the engine would try all rules of the context
192 (w/ failure) and eat only one char on each run.
193 If your modification is kind of general, upload it and drop me a note.
194
195 The simplified syntax below should highlight 99.999% of ISO-Prolog texts
196 correctly, as well as many non-ISO Prolog texts.
197 Else modify this file. Save with new name in your HOME directory to
198 .kde/share/apps/katepart/syntax/prolog-xy.xml You may read the NOTE at the end
199 of this file. WARNING: Be careful, though: the highlighting works according to
200 it's program code, not neccessarily it's documentation...
201
202 DONE- Parse (m)any (!) conforming Prolog texts w/ correct highlighting (LIMITS)
203 - Parse any erratic text w/o crash or endless loops and highlight errors
204 - Folding for multiline comments, clauses, nested terms, and quoted (LIMITS)
205 - Folding inside comments and of 1-line comments and clauses: indentation-
206 based like in Python, e.g.
207 my_pred(a). % w/ marker@left (western style; depends on your settings)
208 my_pred(b). % you can fold
209 my_pred(c). % these lines
210 Inside clauses (i.e. context "term" and below) only explicit folding for
211 braces and quotes applies, except comments. I did not find a better
212 solution, since the engine does not provide lookahead to the next line.
213 - Additionally, folding with %BEGIN ... %END (iff 1st nonwhite of the line).
214 - Classify built-ins (YMMV) for different highlighting, mainly:
215 - w/ side effects from 'outside world' (arithmetics, stream I/O,...)
216 - w/o side effects, only depend on user's program ('internal world')
217 - program logic & control constructs
218 - altering the clause knowledge base or Prolog state
219 - integer/float/mixed arithmetics, so one can see the type of the result
220 - Iff it's an arithmetic expression; else arith ops and built-ins
221 are highlighted normal.
222 - Incl. Sep2012 DRAFT Technical Corrigendum 2: Prolog - Part 1: General Core
223 - Incl. honourable Richard O'Keefe's remarks as warnings as "ISO Bogus".
224 - Detect 'shebang' shell scripts, see BUGs
225 - Includes alert.xml to highlight alert keywords in comments.
226 - Dot "." may be an _unquoted_ user-defined operator in nested terms (but is
227 highlighted as "Warning" 'cause it's more likely a typo than an user-def'd
228 op) and is only taken as fullstop and highlighted as "Logic & Control" in
229 the outmost term of a clause.
230 - Über-correct handling of quoted, escape seqs and "0'" (char code integer):
231 - detection of valid/invalid newline in quoted 'strings'.
232 - highlight whitespace after esc'd newline in quoted so it differs from
233 whitespace contained in the quoted 'string'.
234 - Highlight esc'd tab and tab in quoted as "Warning" because some text
235 editors may convert them to space and it is easy to use "\t" instead.
236 - Preliminary: most names end w/ ISO; prepared to be included in syntax
237 files adapted for Prolog dialects.
238 - The Shebang is highlighted only in the first line (with lineEmptyContext).
239
240 FIXME When katepart can supply line numbers, fix the "shebang" rule.
241
242 TODO sorted by priority
243 1 - [always] Cruise over all FIXMEs.
244 2 - Check if comma, cut & bar are really solo chars (where's the red book?).
245 3 - Check final Technical Corrigendum 2: Prolog - Part 1: General Core
246 4 - Buy ISO Prolog standard - Part 2: Modules. Likely only keywords. Need it
247 anyway.
248 5 - Make this strict-ISO and a "Prolog (portable)" that includes this file.
249 6 - Likewise, adopt for GNU & SWI Prolog and others.
250 8 - keywords 'phrase', streams depricated, etc.pp. ==> Prolog (portable).
251 9 - Likewise: shebang ==> Prolog (portable).
252 10 - Check if shebang can span multiple (escaped) lines.
253 11 - Check: all KB altering preds can have side effects (via resource_error)?
254 12 - For next two TODOs: ask katepart dev to provide lookahead to the next line
255 13 - Folding for consecutive one-line comments [easy? HARD! Impossible.]
256 14 - Likewise, folding for consecutive clauses [HARD! Impossible.]
257 I can live w/ indentation-based folding as a workaround. Not 100%, but ok.
258 15 - +arg_seq (and list): "," as normal text: Detect name( [no layout; easy]
259 16 - +Classify meta predicates.
260 18 - The dollar "$" is commonly used as the 1st char of (unquoted?) atoms to
261 indicate 'internal mode', e.g. to declare a predicate as compile-in.
262 Does this mean the dollar is used as if it were a prefix op or is it part
263 of the atom? Would be easy to implement.
264 19 - Bug #4: could be partly fixed, some built-ins take only float not integer.
265 20 - Bug them to better document weakDeliminators (and rename to delimiter ;)
266 21 - Adjust doxygen syntax for Prolog (e.g. adapt doxygen-lua), and include it.
267 22 - Check if vertical tab is white/layout; are there more non-printables?
268 ################################################################################
269 -->
270 <!-- [Facts & Implications Of The ISO Standard, as a reminder]
271 - 'layout' is whitespace (space/tab/newline) and/or comments.
272 - Braces (any of "(){}[]"), exclamation "!" (aka 'cut'), 'bar' "|", degree "°",
273 paragraph "§" and percent "%" are NOT 'graphic' chars, but 'solo' chars.
274 - The 'bar' "|" may be a predefined operator, and then a user-def'd op, too.
275 - There can only be (at most) one bar "|" in a list (written inside "[]"), and
276 no commata after it (after the bar).
277 - Graphic tokens are atoms (and solo chars are one-char atoms?).
278 - "{}" and "[]" are 'special atoms' (likewise "()"?).
279 - "{}" and "[]" shall not be operators (but round or single braces may be?).
280 - The fullstop "." is not a predefined postfix operator, and
281 - the list functor "." is not a predefined prefix operator.
282 - An unquoted graphic token shall not begin with "/*".
283 - Multiline comments shall not be nested.
284 - Floats are NOT written with lowercase "e" (i.e. not neccessarily an error if
285 e.g. "e" is a pre- or user-defined expr or op and the whole term is valid),
286 - and the fractional part and exponent of floats are optional (any and both).
287 - A leading minus immediately preceding a number is optional for all numbers
288 and then part of the number and not a prefix operator (currently beeing
289 clarified by the standard commitee if "immediately" includes layout, only
290 comments, or none of these at all ;) but
291 - the minus "-" is a predefined prefix- and infix operator...
292 - Terms are rewritten when read in, extendable by user-def'd rules (and these
293 may be dynamic), i.e. clauses are not restricted to the standard forms
294 (to the extent that the fullstop ending a clause may be omited at all) and
295 - the dot "." may be (solo or part of) an user-defined operator.
296 - A Prolog processor may use any character set, e.g. (multi-byte) Unicode.
297 - Virtually every token may be an (user- or predefined) operator, except a few
298 specifically excluded tokens (i.e. NOT just graphic and 'standard' atoms).
299 - All operators except the comma are dynamic (although the standard denotes
300 atoms as 'constants' ;), and
301 - (the comma may appear in a user-defined operator (beeing part of it)?).
302 (Now try to write syntax highlighting for Prolog w/o Prolog HAHAHA ;)
303 -->
304 <highlighting>
305 <!-- aka "guru meditation trigger" -->
306 <list name="error term ISO">
307 <item>error</item>
308 </list>
309 <list name="guru meditation terms ISO">
310 <item>instantiation_error</item>
311 <item>uninstantiation_error</item>
312 <item>type_error</item>
313 <item>domain_error</item>
314 <item>existence_error</item>
315 <item>permission_error</item>
316 <item>representation_error</item>
317 <item>evaluation_error</item>
318 <item>resource_error</item>
319 <item>syntax_error</item>
320 <item>system_error</item>
321 </list>
322
323 <!-- These are in fact bogus, DO NOT USE them and bug the ISO standard
324 commitee to abandon char_conversion/2 and to apply common sense to the
325 semantics of include/1 and ensure_loaded/1, i.e. to handle recursion.
326 Bomb them w/ e-mails! It's not the purpose of a standard to fixate
327 errors till eternity. -->
328 <list name="bogus ISO">
329 <item>char_conversion</item>
330 <item>current_char_conversion</item>
331 <item>include</item>
332 <item>ensure_loaded</item>
333 <!-- Use atan2 instead -->
334 <item>atan</item>
335 <!-- Unspecified integer representation/format -->
336 <item>xor</item>
337 </list>
338 <!-- including directive "initialization" -->
339 <list name="logic+control ISO">
340 <item>initialization</item>
341 <!-- <item>!</item> -->
342 <item>fail</item>
343 <item>repeat</item>
344 <item>call</item>
345 <item>catch</item>
346 <item>throw</item>
347 <item>true</item>
348 <item>false</item>
349 <item>once</item>
350 </list>
351
352 <!-- including directive "dynamic" -->
353 <list name="dyn clause mgmt ISO">
354 <item>dynamic</item>
355 <item>asserta</item>
356 <item>assertz</item>
357 <item>retractall</item>
358 <item>retract</item>
359 <item>abolish</item>
360 <item>clause</item>
361 <!-- <item>numbervars</item> -->
362 <!-- <item>current_predicate</item> -->
363 </list>
364 <list name="terms ISO">
365 <!-- keep tokens with same prefix sorted by length? -->
366 <item>atom_concat</item>
367 <item>atom_length</item>
368 <item>atom_chars</item>
369 <item>atom_codes</item>
370 <item>arg</item>
371 <item>subsumes_term</item>
372 <item>acyclic_term</item>
373 <item>char_code</item>
374 <item>compare</item>
375 <item>copy_term</item>
376 <item>functor</item>
377 <item>number_chars</item>
378 <item>number_codes</item>
379 <!--FIXME check if GNU or ISO <item>sub_atom</item> -->
380 <item>term_variables</item>
381 <item>unify_with_occurs_check</item>
382 </list>
383 <list name="DCG non-ISO">
384 <item>phrase</item>
385 </list>
386 <list name="streams ISO">
387 <item>open</item>
388 <!--GNU <item>current_stream</item>-->
389 <item>set_stream_position</item>
390 <item>get_char</item>
391 <item>get_code</item>
392 <item>peek_char</item>
393 <item>peek_code</item>
394 <item>get_byte</item>
395 <item>peek_byte</item>
396
397 <item>put_char</item>
398 <item>put_code</item>
399 <item>put_byte</item>
400 <item>nl</item>
401
402 <item>read_term</item>
403 <item>read</item>
404 <item>write_canonical</item>
405 <item>writeq</item>
406 <item>write</item>
407 </list>
408 <list name="arith eval ISO">
409 <item>is</item>
410 </list>
411 <list name="arith ops int ISO">
412 <item>rem</item>
413 <item>mod</item>
414 <item>div</item>
415 </list>
416 <list name="arith expr mixed ISO">
417 <!--GNU arith IF expr <item>inc</item> -->
418 <!--GNU arith IF expr <item>dec</item> -->
419 <item>abs</item>
420 <item>sign</item>
421 <item>min</item>
422 <item>max</item>
423 </list>
424 <list name="arith expr int ISO">
425 <!--GNU arith IF expr <item>inc</item> -->
426 <!--GNU arith IF expr <item>dec</item> -->
427 <item>ceiling</item>
428 <item>floor</item>
429 <item>round</item>
430 <item>truncate</item>
431 <!-- ISO Bogus <item>xor</item> -->
432 </list>
433 <list name="arith expr float ISO">
434 <item>pi</item>
435 <!--GNU (see pi) <item>e</item> -->
436 <!--GNU (see pi) <item>epsilon</item> -->
437 <item>sqrt</item>
438 <item>tan</item>
439 <item>cos</item>
440 <item>sin</item>
441 <item>atan2</item>
442 <item>acos</item>
443 <item>asin</item>
444 <item>exp</item>
445 <item>log</item>
446 <item>float</item>
447 <item>float_fractional_part</item>
448 <item>float_integer_part</item>
449 </list>
450
451 <!-- including directives "op/multifile/discontigous" -->
452 <list name="prolog state ISO">
453 <item>multifile</item>
454 <item>discontigous</item>
455 <item>op</item>
456 <item>set_prolog_flag</item>
457 </list>
458 <list name="types ISO">
459 <item>var</item>
460 <item>nonvar</item>
461 <item>atom</item>
462 <item>integer</item>
463 <item>float</item>
464 <item>number</item>
465 <item>atomic</item>
466 <item>compound</item>
467 <item>callable</item>
468 <item>ground</item>
469 </list>
470 <list name="built-ins ISO">
471 <item>current_op</item>
472 <item>current_prolog_flag</item>
473 <item>current_input</item>
474 <item>current_output</item>
475
476 <!-- These act on streams, but the permission_error is only thrown
477 if the programmer tries to set_input(S) when S is alread an output
478 stream and vice versa; so: not affected by 'outside world' -->
479 <item>set_input</item>
480 <item>set_output</item>
481
482 <!-- may throw a system_error in GNU -->
483 <item>close</item>
484
485 <item>flush_output</item>
486
487 <!-- may throw permission_error in GNU if S is an output stream -->
488 <item>at_end_of_stream</item>
489
490 <item>stream_property</item>
491 </list>
492
493 <!-- !FOLD the <context> rules & comments for an overview, then it's no magic. -->
494 <contexts>
495 <!-- Catch typos: style="Syntax Error" for all rules except comments and
496 quoted. This helps to catch bugs in the rules itself, too. Nice
497 debuging aid. Note that (naturally) some of the syntax rules given in
498 EBNF are simplified and do not describe 100% valid Prolog.
499
500 prolog text := shebang clause_seq | clause_seq
501 clause_seq := clause clause_seq | empty
502 clause := layout term_seq fullstop | term_seq fullstop
503 -->
504 <!-- shebang: ("#!") Detect shebang and fallthrough to clause_seq -->
505 <context name="shebang" lineEndContext="clause" lineEmptyContext="clause" attribute="Syntax Error" fallthroughContext="clause">
506 <!-- no way: fallthroughContext="clause_seq" > -->
507 <Detect2Chars column="0" char="#" char1="!" context="1-comment" attribute="% italic predicates: w/ side effects" />
508 <!-- else fallthrough (workaround broken fallthrough) -->
509 </context>
510
511 <!-- syntax error (Test & Debug Aid, too): it's enough to highlight next token -->
512 <context name="syntax_error" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
513 <DetectSpaces context="#pop" attribute="Syntax Error" />
514 <DetectIdentifier context="#pop" attribute="Syntax Error" />
515 <RegExpr String="&any;" context="#pop" attribute="Syntax Error" />
516 </context>
517
518 <!-- clause: Start a region for code folding and switch to term -->
519 <!-- <context name="clause" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" > -->
520 <context name="clause" lineEndContext="#stay" attribute="Syntax Error" >
521 <IncludeRules context="layout" />
522 <!-- KISS: do not force term to detect an empty clause as syntax error -->
523 <RegExpr String="&fullstop_iso;" context="#stay" attribute="Warning (!use background)" />
524 <!-- <RegExpr lookAhead="true" String="&any;" context="term" attribute="Syntax Error" /> -->
525 <RegExpr lookAhead="true" String="&any;" context="term" beginRegion="clause" attribute="Syntax Error" />
526 </context>
527
528 <!--term/nested/list/curly: the master/dispatcher -->
529 <!-- (abbreviated): term := var | atomic | compound | "(" term ")"
530
531 (term_seq := term "," term_seq | term Not needed: comma is an op)
532 term := layout solo layout | layout solo | solo layout | solo
533 solo := var | atomic | compound | "(" term ")"
534 compound := op term | term op | term op term | functored | list
535 functored := atom "(" arg_seq ")" | op "(" arg_seq ")"
536 list := "[" l_arg_seq "]" | double_quoted | "." "(" arg_seq ")"
537 (if semantics of double_quoted not changed by set_prolog_flag/2)
538 sorry I forgot curly: the DCG term but can not contain the fullstop.
539
540 Comments in 'term' apply to the others as well.
541 Note that eating layout once is enough, since we come back here.
542 Only end the clause in the outmost term, which can only be term. -->
543 <context name="term" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
544 <IncludeRules context="layout" />
545 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
546 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
547 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
548 <AnyChar String="&comma;&cut;" context="#stay" attribute="Logic &amp; Control" />
549 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
550 <!-- lookAhead to give different style to the dot and the brace -->
551 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Syntax Error" />
552 <!-- <RegExpr String="&fullstop_iso;" context="#pop" attribute="Logic &amp; Control" /> -->
553 <RegExpr String="&fullstop_iso;" context="#pop" endRegion="clause" attribute="Logic &amp; Control" />
554 <IncludeRules context="atomic" />
555 <!-- Default: anything not eaten here is a syntax error -->
556 </context>
557 <context name="nested" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
558 <IncludeRules context="layout" />
559 <DetectChar char=")" context="#pop" endRegion="nested" attribute="( ) [ ]" />
560 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
561 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
562 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
563 <AnyChar String="&cut;&comma;" context="#stay" attribute="Logic &amp; Control" />
564 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
565 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
566 <RegExpr String="&fullstop_iso;" context="#stay" attribute="Warning (!use background)" />
567 <IncludeRules context="atomic" />
568 </context>
569 <context name="list" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
570 <IncludeRules context="layout" />
571 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
572 <DetectChar char="]" context="#pop" endRegion="list" attribute="( ) [ ]" />
573 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
574 <DetectChar char="{" context="curly" beginRegion="curly" attribute="( ) [ ]" />
575 <AnyChar String="&comma;&cut;" context="#stay" attribute="Normal Text" />
576 <DetectChar char="&bar;" context="#stay" attribute="other built-in operator" />
577 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
578 <IncludeRules context="atomic" />
579 </context>
580 <context name="curly" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
581 <IncludeRules context="layout" />
582 <DetectChar char="(" context="nested" beginRegion="nested" attribute="( ) [ ]" />
583 <DetectChar char="[" context="list" beginRegion="list" attribute="( ) [ ]" />
584 <DetectChar char="}" context="#pop" endRegion="curly" attribute="{ DCG }" />
585 <DetectChar char="{" context="curly" beginRegion="curly" attribute="{ DCG }" />
586 <AnyChar String="&comma;&cut;" context="#stay" attribute="Logic &amp; Control" />
587 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
588 <Detect2Chars lookAhead="true" char="&dot;" char1="(" context="list_functor" attribute="Normal Text" />
589 <IncludeRules context="atomic" />
590 </context>
591
592 <!-- arith_expr := expr op expr | op expr | expr op | "(" expr ")"
593 expr := number_expr | var | arith_expr
594
595 This is only a goody to highlight arith ops and detect syntax errors.
596 If it causes problems, disable it: exchange context="arith_expr" in
597 "atomic" and "operator" below with context="#stay" (two or three occurrences) -->
598 <context name="arith_expr" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
599 <DetectChar char="(" context="nested_expr" beginRegion="nested" attribute="( ) [ ]" />
600 <!-- FIXME check if cut may be an op, else (and in any case 99.9% likely) it's a usual cut here -->
601 <!-- bar & dot could be a user-def'd op, pre-def'd ops could be
602 redef'd; but let's assume the default and just end the expr -->
603 <AnyChar lookAhead="true" String=")}]&bar;&cut;&comma;&bar;" context="#pop"/>
604 <RegExpr lookAhead="true" String="&fullstop_iso;|&logic_control_ops_iso;" context="#pop" attribute="Logic &amp; Control" />
605 <IncludeRules context="arith_expr_common" />
606 </context>
607 <context name="nested_expr" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
608 <DetectChar char="(" context="nested_expr" beginRegion="nested" attribute="( ) [ ]" />
609 <DetectChar char=")" context="#pop" endRegion="nested" attribute="( ) [ ]" />
610 <!-- FIXME check if cut may be an op, else it's a syntax error here -->
611 <DetectChar char="&cut;" context="#stay" attribute="Normal Text" />
612 <DetectChar char="&comma;" context="#stay" attribute="Syntax Error" />
613 <!-- bar & dot could be a user-def'd op, pre-def'd ops could be redef'd; else these were errors -->
614 <DetectChar char="&bar;" context="#stay" attribute="Normal Text" />
615 <RegExpr String="&logic_control_ops_iso;" context="#stay" attribute="other built-in operator" />
616 <IncludeRules context="arith_expr_common" />
617 </context>
618
619 <!-- list functor: assign style to the dot and let term/list/curly take the brace
620 (We have no style "built-in term", so take "Normal text" or "built-in predicate")
621 ASSERT 1st is the dot, else "Syntax Error" INTENTIONALLY -->
622 <context name="list_functor" lineEndContext="syntax_error" attribute="Syntax Error" >
623 <DetectChar char="&dot;" context="#pop" attribute="other built-in predicate" />
624 </context>
625
626 <!-- single/double/back-quoted: handle esc seq and closing quote
627 Comments in single-quoted apply to the others as well.
628 Entry point is single/double/back-quoted (only to handle syntax error:
629 nl after opening quote), sq/dq/bq is inside the string.
630 lineEndContext should be "syntax_error", but then we couldn't handle
631 a valid esc'd line continuation. So we do that 'in vitro' (took me
632 2 days w/ a plethora of useless rules to solve that puzzle LOL).
633 On error must not #stay, else the error isn't shown iff white or empty -->
634 <context name="sq" lineEndContext="#stay" attribute="'quo Ted'" noIndentationBasedFolding="true">
635 <!-- <context name="single-quoted" lineEndContext="#stay" attribute="'quo Ted'" > -->
636 <IncludeRules context="quoted_1st"/>
637 <!-- un-esc'd nl is a syntax error; match max seq (+), else the
638 error is only shown in the next line -->
639 <RegExpr String="(''|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^'\\]+)$"
640 context="syntax_error_sq" attribute="Syntax Error" />
641 <!-- Usual handling: -->
642 <Detect2Chars char="'" char1="'" context="#stay" attribute="escaped (!use background)" />
643 <DetectChar char="'" context="#pop#pop" endRegion="quoted" attribute="'quo Ted'" />
644 <IncludeRules context="quoted_last"/>
645 <!-- Default: literal content of the quoted string, context's style applies -->
646 </context>
647 <context name="dq" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" noIndentationBasedFolding="true" >
648 <!-- <context name="double-quoted" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" > -->
649 <IncludeRules context="quoted_1st"/>
650 <RegExpr String="(&quot;&quot;|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^&quot;\\]+)$"
651 context="syntax_error_dq" attribute="Syntax Error" />
652 <Detect2Chars char="&quot;" char1="&quot;" context="#stay" attribute="escaped (!use background)" />
653 <DetectChar char="&quot;" context="#pop#pop" endRegion="quoted" attribute="&quot;double-quoted&quot;" />
654 <IncludeRules context="quoted_last"/>
655 </context>
656 <context name="bq" lineEndContext="#stay" attribute="`back-quoted`" noIndentationBasedFolding="true" >
657 <!-- <context name="back-quoted" lineEndContext="#stay" attribute="`back-quoted`" > -->
658 <IncludeRules context="quoted_1st"/>
659 <RegExpr String="(``|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^`\\]+)$"
660 context="syntax_error_bq" attribute="Syntax Error" />
661 <Detect2Chars char="`" char1="`" attribute="escaped (!use background)" />
662 <DetectChar char="`" context="#pop#pop" endRegion="quoted" attribute="`back-quoted`" />
663 <IncludeRules context="quoted_last"/>
664 </context>
665 <context name="single-quoted" lineEndContext="#stay" attribute="'quo Ted'" >
666 <LineContinue char="'" context="sq" beginRegion="quoted" attribute="Syntax Error" />
667 <DetectChar char="'" context="sq" beginRegion="quoted" attribute="'quo Ted'" />
668 </context>
669 <context name="double-quoted" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" >
670 <LineContinue char="&quot;" context="dq" beginRegion="quoted" attribute="Syntax Error" />
671 <DetectChar char="&quot;" context="dq" beginRegion="quoted" attribute="&quot;double-quoted&quot;" />
672 </context>
673 <context name="back-quoted" lineEndContext="#stay" attribute="`back-quoted`" >
674 <LineContinue char="`" context="bq" beginRegion="quoted" attribute="Syntax Error" />
675 <DetectChar char="`" context="bq" beginRegion="quoted" attribute="`back-quoted`" />
676 </context>
677
678 <!-- syntax_error_q: highlight next token and proceed normal afterwards -->
679 <context name="syntax_error_sq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
680 <Detect2Chars char="\" char1="'" context="#pop" attribute="Syntax Error" />
681 <Detect2Chars char="'" char1="'" context="#pop" attribute="Syntax Error" />
682 <DetectChar char="'" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
683 <IncludeRules context="syntax_error"/>
684 </context>
685 <context name="syntax_error_dq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
686 <Detect2Chars char="\" char1="&quot;" context="#pop" attribute="Syntax Error" />
687 <Detect2Chars char="&quot;" char1="&quot;" context="#pop" attribute="Syntax Error" />
688 <DetectChar char="&quot;" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
689 <IncludeRules context="syntax_error"/>
690 </context>
691 <context name="syntax_error_bq" lineEndContext="#stay" attribute="Syntax Error" noIndentationBasedFolding="true" >
692 <Detect2Chars char="\" char1="`" context="#pop" attribute="Syntax Error" />
693 <Detect2Chars char="`" char1="`" context="#pop" attribute="Syntax Error" />
694 <DetectChar char="`" context="#pop#pop#pop" endRegion="quoted" attribute="Syntax Error" />
695 <IncludeRules context="syntax_error"/>
696 </context>
697
698 <!-- char_code (after "0'"): esc seq, singleq twice, or any other -->
699 <context name="char_code" lineEndContext="#pop" attribute="Syntax Error" >
700 <Detect2Chars char="'" char1="'" context="#pop" attribute="escaped (!use background)" />
701 <DetectChar char="'" context="#pop" attribute="Syntax Error" />
702 <DetectChar char="&bs;" context="esc_seq_cc" attribute="escaped (!use background)" />
703 <DetectChar char="&tab;" context="#pop" attribute="Warning (!use background)" />
704 <!-- Default _AND IF_ esc_seq #pops back here; we need this to #pop out -->
705 <RegExpr String="&any;" context="#pop" attribute="0'a (!use background)" />
706 </context>
707 <!-- "0'" or "0'\" at EOL is a syntax error, catched below. If
708 possible, highlight white @next line to make clear error is the nl -->
709 <context name="syntax_error_cc" lineEndContext="#stay" attribute="Syntax Error"
710 fallthroughContext="#pop" >
711 <DetectSpaces context="#pop" attribute="Syntax Error" />
712 </context>
713
714 <!-- esc_seq: it's not worth it to handle common for quoted and cc
715 esc_seq_q: handle only cc in bs (e.g. "\007\"), else -> esc_seq_q2
716 ASSERT esc'd newline is handled by the calling context
717 ASSERT we get the leading bs here to highlight the whole thing -->
718 <context name="esc_seq_q" lineEndContext="syntax_error" attribute="Syntax Error" >
719 <RegExpr String="&esc_oct_iso;|&esc_hex_iso;" context="#pop" attribute="0'a (!use background)" />
720 <DetectChar char="&bs;" context="esc_seq_q2" attribute="escaped (!use background)" />
721 </context>
722 <!-- esc_seq_cc: #pop#pop out of cc on std esc seq, else pass char back
723 ASSERT we do NOT need the leading bs here anymore -->
724 <context name="esc_seq_cc" fallthroughContext="#pop"
725 lineEndContext="#pop#pop" attribute="Syntax Error" >
726 <DetectChar char="&tab;" context="#pop#pop" attribute="Warning (!use background)" />
727 <AnyChar String="&any_esc_iso;" context="#pop#pop" attribute="escaped (!use background)" />
728 </context>
729 <!-- esc_seq_q2: Handle standard esc seq in quoted else pass char back
730 ASSERT we do NOT need the leading bs here anymore -->
731 <context name="esc_seq_q2" fallthroughContext="#pop#pop"
732 lineEndContext="syntax_error" attribute="Syntax Error" >
733 <DetectChar char="&tab;" context="#pop#pop" attribute="Warning (!use background)" />
734 <AnyChar String="&any_esc_iso;" context="#pop#pop" attribute="escaped (!use background)" />
735 </context>
736
737 <!-- id,var,graphic: ASSERT calling context ashured 1st char is ok
738 ASSERT we get the 1st char for id & var -->
739 <context name="id" attribute="Syntax Error" lineEndContext="#stay" >
740 <DetectIdentifier context="#pop" attribute="Normal Text" />
741 </context>
742 <context name="var" attribute="Syntax Error" lineEndContext="#stay" >
743 <DetectIdentifier context="#pop" attribute="_VARIABLE" />
744 </context>
745 <context name="graphic" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
746 <AnyChar String="&any_graphic_iso;" context="#stay" attribute="Normal Text" />
747 </context>
748
749 <!-- numbers (after "0[box]") -->
750 <context name="bin" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
751 <AnyChar String="&any_bin_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
752 </context>
753 <context name="oct" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
754 <AnyChar String="&any_oct_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
755 </context>
756 <context name="hex" lineEndContext="#pop" attribute="Syntax Error" fallthroughContext="#pop" >
757 <AnyChar String="&any_hex_iso;" context="#stay" attribute="0b1001 0o007 0xF1" />
758 </context>
759
760 <!-- comment-iso: multi-line comment, handle closing "*/" -->
761 <context name="comment-iso" lineEndContext="#stay" attribute="% italic predicates: w/ side effects" >
762 <!-- Nested comments are not allowed in strict ISO-Prolog - - >
763 <Detect2Chars char="/" char1="*" context="comment" beginRegion="comment"
764 attribute="% italic predicates: w/ side effects" />-->
765 <Detect2Chars char="*" char1="/" context="#pop" endRegion="comment"
766 attribute="% italic predicates: w/ side effects" />
767 <DetectSpaces />
768 <IncludeRules context="##Comments" />
769 <DetectIdentifier />
770 </context>
771
772 <!-- 1-line comment: #pop@EOL -->
773 <!-- Folding for consecutive 1-line comments: let indentation-based auto-folding work -->
774 <context name="1-comment" lineEndContext="#pop" attribute="% italic predicates: w/ side effects" >
775 <DetectSpaces />
776 <IncludeRules context="##Comments" />
777 <DetectIdentifier />
778 </context>
779 <context name="region_marker" lineEndContext="#pop" attribute="%BEGIN folding region" noIndentationBasedFolding="true" >
780 <IncludeRules context="1-comment" />
781 </context>
782 <context name="layout_fold" lineEndContext="#stay" attribute="Syntax Error"
783 fallthroughContext="#pop" >
784 <DetectSpaces attribute="Normal Text" />
785 <StringDetect String="%BEGIN" context="region_marker" attribute="%BEGIN folding region"
786 firstNonSpace="true" beginRegion="user_region" />
787 <StringDetect String="%END" context="region_marker" attribute="%BEGIN folding region"
788 firstNonSpace="true" endRegion="user_region" />
789 <DetectChar firstNonSpace="true" char="%" context="1-comment" attribute="% italic predicates: w/ side effects" />
790 </context>
791
792 <!--####### BEGIN sub rules to be included - <context> never taken -->
793
794 <!-- Common for all quoted: Handle line continuation, esc seq, and most other input efficiently -->
795 <context name="quoted_1st" lineEndContext="#stay" attribute="Syntax Error" >
796 <LineContinue attribute="escaped (!use background)" />
797 <DetectSpaces column="0" attribute="escaped (!use background)" />
798 </context>
799 <context name="quoted_last" lineEndContext="#stay" attribute="Syntax Error" >
800 <DetectChar lookAhead="true" char="&bs;" context="esc_seq_q" attribute="Syntax Error" />
801 <DetectChar char="&tab;" attribute="Warning (!use background)" />
802 <DetectIdentifier />
803 <DetectSpaces />
804 </context>
805
806 <!-- layout_seq := layout layout_seq
807 layout := " " | tab | nl | comment -->
808 <context name="layout" lineEndContext="#stay" attribute="Syntax Error" >
809 <DetectSpaces attribute="Normal Text" />
810 <Detect2Chars char="/" char1="*" context="comment-iso" attribute="% italic predicates: w/ side effects"
811 beginRegion="comment" />
812 <StringDetect String="%BEGIN" context="region_marker" attribute="%BEGIN folding region"
813 firstNonSpace="true" beginRegion="user_region" />
814 <StringDetect String="%END" context="region_marker" attribute="%BEGIN folding region"
815 firstNonSpace="true" endRegion="user_region" />
816 <DetectChar firstNonSpace="true" char="%" context="layout_fold" attribute="% italic predicates: w/ side effects"
817 lookAhead="true" />
818 <DetectChar firstNonSpace="false" char="%" context="1-comment" attribute="% italic predicates: w/ side effects" />
819 </context>
820
821 <!--atomic: the work horse -->
822 <!-- (simplified) atomic := atom | number | op | var -->
823 <context name="atomic" lineEndContext="#stay" attribute="Syntax Error" >
824 <!-- NOTE the order of rules is important... (as always)
825 Predefined 1st, unknown (user defined) last -->
826 <keyword String="logic+control ISO" context="#stay" attribute="Logic &amp; Control" />
827 <keyword String="types ISO" context="#stay" attribute="Type Checking" />
828 <keyword String="dyn clause mgmt ISO" context="#stay" attribute="Dynamic Clause Management" />
829 <keyword String="streams ISO" context="#stay" attribute="Stream I/O" />
830 <keyword String="terms ISO" context="#stay" attribute="other built-in predicate" />
831 <keyword String="prolog state ISO" context="#stay" attribute="Prolog State" />
832 <keyword String="DCG non-ISO" context="#stay" attribute="{ DCG }" />
833 <keyword String="arith eval ISO" context="arith_expr" attribute="Arithmetics" />
834 <!-- These are user predicates outside arit_expr -->
835 <!-- <keyword String="arith expr mixed ISO" context="#stay" attribute="other built-in predicate" /> -->
836 <!-- <keyword String="arith expr int ISO" context="#stay" attribute="other built-in predicate" /> -->
837 <!-- <keyword String="arith expr float ISO" context="#stay" attribute="other built-in predicate" /> -->
838 <keyword String="built-ins ISO" context="#stay" attribute="other built-in predicate" />
839 <keyword String="error term ISO" context="#stay" attribute="Guru Meditation" />
840 <keyword String="guru meditation terms ISO" context="#stay" attribute="Guru Meditation Terms" />
841 <keyword String="bogus ISO" context="#stay" attribute="ISO Bogus" />
842
843 <!-- Match char code before quoted and ops... -->
844 <IncludeRules context="number" />
845
846 <!-- these depend on current_prolog_flag/2 so can all return a term i.e. a list (of char codes) -->
847 <DetectChar lookAhead="true" char="'" context="single-quoted" attribute="'quo Ted'" />
848 <DetectChar lookAhead="true" char="`" context="back-quoted" attribute="`back-quoted`" />
849 <DetectChar lookAhead="true" char="&quot;" context="double-quoted" attribute="&quot;double-quoted&quot;" />
850
851 <!-- ...and ops before atoms, else "div", "is" etc. are usual atoms -->
852 <IncludeRules context="operator" />
853 <AnyChar lookAhead="true" String="&any_lower_iso;" context="id" attribute="Normal Text" />
854 <AnyChar lookAhead="true" String="&any_upper_under_iso;" context="var" attribute="_VARIABLE" />
855 <AnyChar String="&any_graphic_iso;" context="graphic" attribute="Normal Text" />
856 </context> <!-- atomic -->
857
858 <!-- [(mostly) "atomic" for] arith_expr := arith_op | number_expr | var
859 number_expr := number | built-in | user-def
860
861 This is only a goody to highlight arith ops and detect syntax errors.
862 If it causes problems, disable it: exchange context="arith_expr" in
863 contexts "atomic" and "operator" with context="#stay" -->
864 <context name="arith_expr_common" lineEndContext="#stay" attribute="Syntax Error" >
865 <IncludeRules context="layout" />
866 <IncludeRules context="number" />
867 <keyword String="bogus ISO" context="#stay" attribute="ISO Bogus" />
868 <keyword String="arith expr mixed ISO" context="#stay" attribute="Arithmetics" />
869 <keyword String="arith expr int ISO" context="#stay" attribute="Integer Arithmetics" />
870 <keyword String="arith expr float ISO" context="#stay" attribute="Float Arithmetics" />
871 <keyword String="arith ops int ISO" context="#stay" attribute="Integer Arithmetics" />
872 <RegExpr String="&arith_compare_iso;" context="#pop" attribute="Syntax Error" />
873 <RegExpr String="&arith_ops_mixed_iso;" context="#stay" attribute="Arithmetics" />
874 <RegExpr String="&arith_ops_int_iso;" context="#stay" attribute="Integer Arithmetics" />
875 <RegExpr String="&arith_ops_float_iso;" context="#stay" attribute="Float Arithmetics" />
876 <RegExpr String="&arith_bogus_iso;" context="#stay" attribute="ISO Bogus" />
877 <!-- do not miss user-def'd arithmetic expr and number expr-->
878 <IncludeRules context="operator" />
879 <AnyChar lookAhead="true" String="&any_lower_iso;" context="id" attribute="Normal Text" />
880 <AnyChar lookAhead="true" String="&any_upper_under_iso;" context="var" attribute="_VARIABLE" />
881 <AnyChar String="&any_graphic_iso;" context="graphic" attribute="Normal Text" />
882 </context>
883
884 <!-- number := float | integer
885 integer := decimal | baseN | "0'" char_code
886 baseN := "0b" [01]+ | "0o" [0-7]+ | "0x" [0-9a-fA-F]+ -->
887 <context name="number" lineEndContext="#pop" attribute="Syntax Error" >
888 <!-- Match integers after other numbers -->
889 <!-- FIXME a minus may precede all numbers and is part of the number! -->
890 <RegExpr String="0'\\?$" context="syntax_error_cc" attribute="Syntax Error" />
891 <Detect2Chars char="0" char1="'" context="char_code" attribute="0'a (!use background)" />
892
893 <!-- NOT: [box] could be a postfix op <RegExpr String="0[box]$" context="#stay" attribute="Syntax Error" /> -->
894 <Detect2Chars char="0" char1="b" context="bin" attribute="0b1001 0o007 0xF1" />
895 <Detect2Chars char="0" char1="o" context="oct" attribute="0b1001 0o007 0xF1" />
896 <Detect2Chars char="0" char1="x" context="hex" attribute="0b1001 0o007 0xF1" />
897
898 <RegExpr String="&float1_iso;|&float2_iso;|&float3_iso;" context="#stay" attribute="2.718281E-9" />
899 <Int context="#stay" attribute="1 2 3 42" />
900 </context>
901
902 <!-- operator := predefined_op | dynamic_op (which we can not detect)
903 comma, single dot & bar are catched earlier above in term/list/curly -->
904 <context name="operator" lineEndContext="#pop" attribute="Syntax Error" >
905 <keyword String="arith eval ISO" context="arith_expr" attribute="Arithmetics" />
906 <keyword String="arith ops int ISO" context="#stay" attribute="other built-in operator" />
907 <RegExpr String="&logic_control_ops_iso;" context="#stay" attribute="Logic &amp; Control" />
908 <RegExpr String="&predefined_ops_iso;" context="#stay" attribute="other built-in operator" />
909 <RegExpr String="&dcg_production_iso;" context="#stay" attribute="{ DCG }" />
910 <RegExpr String="&arith_compare_iso;" context="arith_expr" attribute="Arithmetics" />
911 <RegExpr String="&arith_ops_mixed_iso;|&arith_ops_int_iso;|&arith_ops_float_iso;" context="#stay" attribute="other built-in operator" />
912 <RegExpr String="&arith_bogus_iso;" context="#stay" attribute="ISO Bogus" />
913 </context>
914
915 <!--####### END sub rules to be included - <context> never taken -->
916 </contexts>
917
918 <!-- The idea is to give all predicates that may be affected by the
919 "outside world" a common style (italic). I.e. these can throw a
920 permission, evaluation, representation or resource_error, even though
921 the program itself is 100% correct. E.g. you get_char/2 a char code 1
922 from a text stream (representation_error): not your mistake, but you
923 have to deal with that, too. -->
924 <itemDatas>
925 <itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" />
926 <itemData name="_VARIABLE" defStyleNum="dsDataType" bold="false" spellChecking="false" />
927 <itemData name="'quo Ted'" defStyleNum="dsString" />
928 <itemData name="`back-quoted`" defStyleNum="dsString" italic="true" />
929 <!-- The standard wants double-quoted to be a list of char codes, but
930 e.g. GNU Prolog allows that to be set with set_prolog_flag/2 -->
931 <itemData name="&quot;double-quoted&quot;" defStyleNum="dsOthers" />
932 <itemData name="escaped (!use background)" defStyleNum="dsChar" spellChecking="false"
933 backgroundColor="#0C0C0C" selBackgroundColor="#FFFFFF" />
934
935 <!-- Numbers -->
936 <itemData name="2.718281E-9" defStyleNum="dsFloat" spellChecking="false" />
937 <itemData name="1 2 3 42" defStyleNum="dsDecVal" spellChecking="false" />
938 <itemData name="0b1001 0o007 0xF1" defStyleNum="dsBaseN" spellChecking="false" />
939 <itemData name="0'a (!use background)" defStyleNum="dsBaseN" spellChecking="false"
940 backgroundColor="#0C0C0C" selBackgroundColor="#FFFFFF" />
941
942 <itemData name="( ) [ ]" defStyleNum="dsNormal" spellChecking="false" />
943 <itemData name="{ DCG }" defStyleNum="dsKeyword" spellChecking="false" />
944 <itemData name="Prolog State" defStyleNum="dsFunction" bold="true" spellChecking="false" />
945 <itemData name="Type Checking" defStyleNum="dsDataType" spellChecking="false" />
946 <itemData name="Logic &amp; Control" defStyleNum="dsKeyword" spellChecking="false" />
947 <itemData name="other built-in operator" defStyleNum="dsFunction" spellChecking="false" />
948 <itemData name="other built-in predicate" defStyleNum="dsFunction" spellChecking="false" />
949
950 <!-- Comments (2nd not used, just a hint) -->
951 <itemData name="% italic predicates: w/ side effects" defStyleNum="dsComment" />
952
953 <!-- Predicates affected by 'outside world' -->
954 <itemData name="Dynamic Clause Management" defStyleNum="dsKeyword" italic="true" spellChecking="false" />
955 <itemData name="Stream I/O" defStyleNum="dsFunction" italic="true" spellChecking="false" />
956
957 <!-- arithmetics: get the color of ints/floats; includes ops & expressions like pi -->
958 <itemData name="Arithmetics" defStyleNum="dsDataType" bold="true" italic="true" spellChecking="false" />
959 <itemData name="Integer Arithmetics" defStyleNum="dsDecVal" bold="true" italic="true" spellChecking="false" />
960 <itemData name="Float Arithmetics" defStyleNum="dsFloat" bold="true" italic="true" spellChecking="false" />
961 <itemData name="ISO Bogus" defStyleNum="dsAlert" bold="true" italic="true" spellChecking="false" />
962
963 <!-- no way w/ buggy kate 3.8.5: get the color of default style dsError for error and terms -->
964 <itemData name="Guru Meditation" defStyleNum="dsNormal" spellChecking="false"
965 bold="true" italic="false" underline="false" color="#FF0000" selColor="#00FFFF" />
966 <itemData name="Guru Meditation Terms" defStyleNum="dsNormal" spellChecking="false"
967 bold="false" italic="true" underline="false" color="#FF0000" selColor="#00FFFF" />
968 <itemData name="Syntax Error" defStyleNum="dsError" spellChecking="false" />
969 <itemData name="Warning (!use background)" defStyleNum="dsAlert" spellChecking="false"
970 backgroundColor="#FC000C" selBackgroundColor="#03FFF3" />
971 <itemData name="%BEGIN folding region" defStyleNum="dsRegionMarker" spellChecking="false" />
972 </itemDatas>
973 </highlighting>
974 <general>
975 <keywords casesensitive="true" additionalDeliminator="$#'&quot;`" />
976 <!-- let indentationsensitive folding provide it's magic -->
977 <folding indentationsensitive="true" />
978 <!-- <EmptyLines> -->
979 <!-- <EmptyLine regexpr="^[ /t]*(?!%).*$" /> -->
980 <!-- </EmptyLines> -->
981 <comments>
982 <comment name="singleLine" start="%" position="afterwhitespace" />
983 <comment name="multiLine" start="/*" end="*/" region="comment" />
984 </comments>
985 </general>
986 </language>
987 <!--##### NOTE [HOWTO check your syntax file, extracted from language.dtd] #####
988
989 Copyright (c) 2001 Joseph Wenninger <[email protected]>
990 modified (c) 2002 Anders Lund <[email protected]>
991 modified (c) 2003 Simon Huerlimann <[email protected]>
992 modified (c) 2005 Dominik Haumann <[email protected]>
993 modified (c) 2008 Wilbert Berendsen <[email protected]>
994
995 You can validate your syntax files using checkXML from the development
996 package of kdelibs [author: i.e. kdelibs-dev]:
997
998 checkXML yourSyntax.xml [author: | grep -v 'no template matches']
999
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; -->