1 % (c) 2018-2024 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
2 % Heinrich Heine Universitaet Duesseldorf
3 % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
4
5
6 :- module(tools_matching,
7 [fuzzy_match_codes_lower_case/2,
8 fuzzy_match_codes/2,
9 codes_to_lower_case/2, % to lower case, also performs Unicode simplifications
10 get_current_keywords/1, get_current_expr_keywords/1,
11 is_b_keyword/2,
12 get_all_svg_attributes/1, is_svg_number_attribute/2, is_svg_color_attribute/1, is_svg_attribute/1,
13 is_svg_color_name/1,
14 get_all_dot_attributes/1, is_dot_attribute/1,
15 dot2svg_synonym/2,
16 get_possible_preferences/1, get_possible_preferences_matches_msg/2,
17 get_possible_top_level_event_matches_msg/2,
18 get_possible_fuzzy_matches_msg/3,
19 get_possible_completions_msg/3,
20 get_possible_fuzzy_matches_and_completions_msg/3 % both in one
21 ]).
22
23 :- use_module(error_manager).
24 :- use_module(self_check).
25 :- use_module(library(lists)).
26
27 :- use_module(module_information).
28
29 :- module_info(group,infrastructure).
30 :- module_info(description,'A few utilities for fuzzy matching and completion.').
31
32 :- set_prolog_flag(double_quotes, codes).
33
34
35 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("a","A")).
36 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("aBcD","ABCd")).
37 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("aBcD","ABxCd")).
38 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("aBxcD","ABCd")).
39 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("aBcD","ABCdx")).
40 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("aBcDx","ABCd")).
41 :- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("a_Bc_D","AB__Cd")).
42 %:- assert_must_succeed(tools_matching:fuzzy_match_codes_lower_case("äÄ","aA")).
43 :- assert_must_fail(tools_matching:fuzzy_match_codes_lower_case("abc","cba")).
44
45
46 fuzzy_match_codes_lower_case(Codes1,Codes2) :-
47 codes_to_lower_case(Codes1,LCodes1),
48 codes_to_lower_case(Codes2,LCodes2),
49 ? fuzzy_match_codes(LCodes1,LCodes2).
50
51 :- assert_must_succeed(tools_matching:fuzzy_match_codes("aBcD","aBcD")).
52 :- assert_must_succeed(tools_matching:fuzzy_match_codes("aBxcD","aBcD")).
53 :- assert_must_succeed(tools_matching:fuzzy_match_codes("aBcD","aBcxD")).
54 :- assert_must_succeed(tools_matching:fuzzy_match_codes("aBcD","aBcDx")).
55 :- assert_must_succeed(tools_matching:fuzzy_match_codes("xaBcD","aBcD")).
56 :- assert_must_succeed(tools_matching:fuzzy_match_codes("aBcD","xaBcD")).
57 :- assert_must_succeed(tools_matching:fuzzy_match_codes("version","verison")).
58 :- assert_must_fail(tools_matching:fuzzy_match_codes("abc","ABC")).
59
60 fuzzy_match_codes([],[]).
61 ?fuzzy_match_codes([H|T1],[H|T2]) :- !,fuzzy_match_codes(T1,T2).
62 fuzzy_match_codes([_|T],[_|T]) :- !. % one character rewritten
63 fuzzy_match_codes([H1|T1],L2) :- possible_skip_char(H1),!, % underscore _
64 ? fuzzy_match_codes(T1,L2).
65 fuzzy_match_codes(L1,[H2|T2]) :- possible_skip_char(H2),!,
66 ? fuzzy_match_codes(L1,T2).
67 fuzzy_match_codes([_|T],T) :- !. % one character too much
68 fuzzy_match_codes(T,[_|T]) :- !. % one character too few
69 fuzzy_match_codes([H1,H2|T],[H2,H1|T]) :- !. % swapping of two characters
70
71
72 %:- assert_must_succeed(tools_matching:codes_to_lower_case("äÄöAa","aaoaa")).
73
74 codes_to_lower_case(Codes,LC) :- maplist(code_to_lower_case,Codes,LC).
75 % TO DO: normalise more UNICODE symbols, ...
76
77 code_to_lower_case(Char,LC_Char) :- Char >= 65, Char =< 90,!, LC_Char is Char+32.
78 code_to_lower_case(Char,LC_Char) :- Char >= 8320, Char =< 8329,!, LC_Char is Char-8272. % Unicode Subscripts
79 code_to_lower_case(8242,R) :- !, R=8242. % Unicode Prime
80 code_to_lower_case(8216,R) :- !, R=8242.
81 code_to_lower_case(8217,R) :- !, R=8242.
82 code_to_lower_case(Char,R) :- Char >= 192, Char =< 197,!, R=97. % upper-case a
83 code_to_lower_case(Char,R) :- Char >= 224, Char =< 229,!, R=97. % lower-case a
84 code_to_lower_case(Char,R) :- Char >= 200, Char =< 203,!, R=101. % upper-case e
85 code_to_lower_case(Char,R) :- Char >= 232, Char =< 235,!, R=101. % lower-case e
86 code_to_lower_case(Char,R) :- Char >= 204, Char =< 207,!, R=105. % upper-case i
87 code_to_lower_case(Char,R) :- Char >= 236, Char =< 239,!, R=105. % lower-case i
88 code_to_lower_case(Char,R) :- Char >= 210, Char =< 214,!, R=111. % upper-case o
89 code_to_lower_case(Char,R) :- Char >= 242, Char =< 246,!, R=111. % lower-case o
90 code_to_lower_case(Char,R) :- Char >= 217, Char =< 220,!, R=117. % upper-case u
91 code_to_lower_case(Char,R) :- Char >= 249, Char =< 252,!, R=117. % lower-case u
92 code_to_lower_case(253,R) :- !, R=121. % ý -> y
93 code_to_lower_case(209,R) :- !, R=110. % Ñ -> n
94 code_to_lower_case(241,R) :- !, R=110. % ñ -> n
95 code_to_lower_case(231,R) :- !, R=99. % ç -> c
96 code_to_lower_case(223,R) :- !, R=115. % ß -> s
97 code_to_lower_case(C,C).
98
99 % use_module(library(between)), between(150,255,R), atom_codes(A,[R]), format("~w : ~w~n",[R,A]),fail.
100
101 possible_skip_char(95). % _
102
103 :- use_module(specfile,[b_or_z_mode/0, csp_mode/0, xtl_mode/0, animation_minor_mode/1, classical_b_mode/0]).
104
105 get_current_expr_keywords(List) :-
106 get_current_keywords([expr,external_funs,pragma,predicate],List).
107 get_current_keywords(List) :-
108 get_current_keywords([expr,external_funs,pragma,predicate,prob_definitions,section,subst],List).
109
110 get_current_keywords(Types,List) :- b_or_z_mode,!,
111 (animation_minor_mode(Minor)
112 -> (classical_b_mode
113 % e.g., for rules_dsl allow both B and rules_dsl keywords at the moment, TODO: remove sections
114 -> get_keywords(Minor,Types,List1),
115 get_keywords(b,Types,List2),
116 append(List1,List2,List)
117 ; get_keywords(Minor,Types,List))
118 ; get_keywords(b,Types,List)).
119 get_current_keywords(_,List) :- csp_mode,!,
120 findall(Def,csp_keyword(Def),List).
121 get_current_keywords(_,List) :- xtl_mode,!,
122 findall(Def,xtl_keyword(Def),List).
123 get_current_keywords(_,[]).
124
125 % -----------------
126
127 csp_keyword(and).
128 csp_keyword(card).
129 csp_keyword(channel).
130 csp_keyword(datatype).
131 csp_keyword(diff).
132 csp_keyword(elem).
133 csp_keyword(empty).
134 csp_keyword(false).
135 csp_keyword(head).
136 csp_keyword(inter).
137 csp_keyword(length).
138 csp_keyword(let).
139 csp_keyword(member).
140 csp_keyword(mod).
141 csp_keyword(nametype).
142 csp_keyword(not).
143 csp_keyword(null).
144 csp_keyword(or).
145 csp_keyword(set).
146 csp_keyword(subtype).
147 csp_keyword(tail).
148 csp_keyword(true).
149 csp_keyword(union).
150 csp_keyword(within).
151 csp_keyword('CHAOS').
152 csp_keyword('Inter').
153 csp_keyword('Seq').
154 csp_keyword('Set').
155 csp_keyword('SKIP').
156 csp_keyword('STOP').
157 csp_keyword('Union').
158
159
160 xtl_keyword(prop).
161 xtl_keyword(start).
162 xtl_keyword(trans).
163 xtl_keyword(animation_image).
164 xtl_keyword(animation_image_click_transition).
165 xtl_keyword(animation_image_right_click_transition).
166 xtl_keyword(animation_function_result).
167 xtl_keyword(heuristic_function_active).
168 xtl_keyword(heuristic_function_result).
169 xtl_keyword(prob_game_info).
170 xtl_keyword(prob_pragma_string).
171
172 % -----------------
173
174 get_keywords(Mode,Types,List) :-
175 (Mode=b,select(prob_definitions,Types,Types1)
176 -> findall(Def,prob_special_def(Def),Ids1)
177 ; Ids1=[], Types1=Types
178 ),
179 ? (Mode=b,select(external_funs,Types1,Types2)
180 -> findall(Def,prob_external_fun(Def),Ids2,Ids1)
181 ; Ids2=Ids1, Types2=Types1
182 ),
183 findall(ID,(keyword(ID,Type,Modes), member(Mode,Modes), member(Type,Types2)),Ids,Ids2),
184 sort(Ids,List).
185
186 :- use_module(external_function_declarations,[external_function_library/2]).
187 ?prob_external_fun(Fun) :- external_function_library(Fun,File),
188 member(File,['LibraryStrings.def']). % ideally we want to only show the included libraries
189
190 prob_special_def(Def) :- special_definitions(Def,_).
191 prob_special_def(Def) :- set_pref_keyword(Def,_).
192 prob_special_def(Def) :- operation_pref_keyword(Def).
193
194 special_definitions('ASSERT_CTL',model_check).
195 special_definitions('ASSERT_LTL',model_check).
196 special_definitions('GOAL',model_check).
197 special_definitions('HEURISTIC_FUNCTION',model_check).
198 special_definitions('SCOPE',model_check).
199 special_definitions('CUSTOM_GRAPH',dot).
200 special_definitions('CUSTOM_GRAPH_EDGES',dot).
201 special_definitions('CUSTOM_GRAPH_NODES',dot).
202 special_definitions('VISB_JSON_FILE',visb).
203 special_definitions('VISB_SVG_BOX',visb).
204 special_definitions('VISB_SVG_CONTENTS',visb).
205 special_definitions('VISB_SVG_EVENTS',visb).
206 special_definitions('VISB_SVG_FILE',visb).
207 special_definitions('VISB_SVG_HOVERS',visb).
208 special_definitions('VISB_SVG_OBJECTS',visb).
209 special_definitions('VISB_SVG_UPDATES',visb).
210 % this is a local identifier available inside event predicates: VISB_CLICK_META_INFOS
211 special_definitions('ANIMATION_CLICK',tkanim).
212 special_definitions('ANIMATION_EXPRESSION',tkanim).
213 special_definitions('ANIMATION_FUNCTION',tkanim).
214 special_definitions('ANIMATION_FUNCTION_DEFAULT',tkanim).
215 special_definitions('ANIMATION_IMG',tkanim).
216 special_definitions('ANIMATION_RIGHT_CLICK',tkanim).
217 special_definitions('ANIMATION_STR',tkanim).
218 special_definitions('ANIMATION_STR_JUSTIFY_LEFT',tkanim).
219 special_definitions('ANIMATION_STR_JUSTIFY_RIGHT',tkanim).
220 special_definitions('GAME_MCTS_RUNS',mcts).
221 special_definitions('GAME_MCTS_TIMEOUT',mcts).
222 special_definitions('GAME_MCTS_CACHE_LAST_TREE',mcts).
223 special_definitions('GAME_OVER',mcts).
224 special_definitions('GAME_PLAYER',mcts).
225 special_definitions('GAME_VALUE',mcts).
226 special_definitions('PROB_REQUIRED_VERSION',general).
227 % TODO: scope_, FORCE_SYMMETRY_, for sets
228
229 :- use_module(bmachine,[b_top_level_operation/1]).
230 operation_pref_keyword(OpPrefAtom) :-
231 b_top_level_operation(Top),
232 op_prefix(Prefix),
233 atom_concat(Prefix,Top,OpPrefAtom).
234 op_prefix('MAX_OPERATIONS_').
235 op_prefix('OPERATION_REUSE_OFF_').
236 op_prefix('SEQUENCE_CHART_').
237
238 set_pref_keyword(SetPrefAtom,Pref) :-
239 get_possible_preferences(Prefs),
240 member(Pref,Prefs),
241 atom_concat('SET_PREF_',Pref,SetPrefAtom).
242
243 is_b_keyword(ID,Type) :- keyword(ID,Type,L), member(b,L).
244
245 % list of language specific and context specific keywords
246 keyword(not,predicate,[b,eventb]).
247 keyword(or,predicate,[b,eventb]).
248 keyword('true',expr,[eventb]). % truth in Rodin parser
249 keyword('false',expr,[eventb]). % falsity in Rodin parser
250 keyword('TRUE',expr,[b,eventb,tla]).
251 keyword('FALSE',expr,[b,eventb,tla]).
252 keyword('BOOL',expr,[b,eventb]).
253 keyword('bool',expr,[b,eventb]).
254 keyword('POW',expr,[b,eventb]).
255 keyword('POW1',expr,[b,eventb]).
256 keyword('FIN',expr,[b,eventb]).
257 keyword('FIN1',expr,[b,eventb]).
258 keyword('union',expr,[b,eventb]).
259 keyword('inter',expr,[b,eventb]).
260 keyword('UNION',expr,[b,eventb]).
261 keyword('INTER',expr,[b,eventb]).
262 keyword('INTEGER',expr,[b]).
263 keyword('NATURAL',expr,[b]).
264 keyword('NATURAL1',expr,[b]).
265 keyword('INT',expr,[b,eventb]).
266 keyword('NAT',expr,[b,eventb]).
267 keyword('NAT1',expr,[b,eventb]).
268 keyword('MININT',expr,[b]).
269 keyword('MAXINT',expr,[b]).
270 keyword('min',expr,[b,eventb]).
271 keyword('max',expr,[b,eventb]).
272 keyword('SIGMA',expr,[b]).
273 keyword('PI',expr,[b]).
274 keyword('STRING',expr,[b,tla]).
275 keyword('card',expr,[b,eventb]).
276 keyword('finite',expr,[eventb]).
277 keyword('@finite',expr,[b]).
278 keyword('dom',expr,[b,eventb]).
279 keyword('ran',expr,[b,eventb]).
280 keyword('id',expr,[b,eventb]).
281 keyword('@partition',expr,[b]).
282 keyword('partition',expr,[eventb]).
283 keyword('prj1',expr,[b,eventb]).
284 keyword('prj2',expr,[b,eventb]).
285 keyword('@prj1',expr,[b]).
286 keyword('@prj2',expr,[b]).
287 keyword('pred',expr,[b,eventb]).
288 keyword('succ',expr,[b,eventb]).
289 keyword('closure',expr,[b]).
290 keyword('closure1',expr,[b]).
291 keyword('iterate',expr,[b]).
292 keyword('fnc',expr,[b]). % also Event-B ?
293 keyword('rel',expr,[b]).
294
295 keyword('seq',expr,[b]).
296 keyword('seq1',expr,[b]).
297 keyword('iseq',expr,[b]).
298 keyword('iseq1',expr,[b]).
299 keyword('perm',expr,[b]).
300 keyword('size',expr,[b]).
301 keyword('rev',expr,[b]).
302 keyword('first',expr,[b]).
303 keyword('last',expr,[b]).
304 keyword('front',expr,[b]).
305 keyword('tail',expr,[b]).
306 keyword('conc',expr,[b]).
307 keyword('struct',expr,[b]).
308 keyword('rec',expr,[b]).
309 keyword('STRING',expr,[b]).
310
311 % TREE keywords
312 keyword('arity',expr,[b]).
313 keyword('bin',expr,[b]).
314 keyword('btree',expr,[b]).
315 keyword('const',expr,[b]).
316 keyword('father',expr,[b]).
317 keyword('infix',expr,[b]).
318 keyword('left',expr,[b]).
319 keyword('mirror',expr,[b]).
320 keyword('prefix',expr,[b]).
321 keyword('postfix',expr,[b]).
322 keyword('rank',expr,[b]).
323 keyword('right',expr,[b]).
324 keyword('sizet',expr,[b]).
325 keyword('son',expr,[b]).
326 keyword('sons',expr,[b]).
327 keyword('subtree',expr,[b]).
328 keyword('top',expr,[b]).
329 keyword('tree',expr,[b]).
330
331
332 % REAL keywords
333 keyword('floor',expr,[b]).
334 keyword('ceiling',expr,[b]).
335 keyword('real',expr,[b]).
336 keyword('REAL',expr,[b]).
337 keyword('FLOAT',expr,[b]).
338
339 % ---
340
341 keyword('btrue',predicate,[b]).
342 keyword('bfalse',predicate,[b]).
343
344 keyword('skip',subst,[b]).
345 keyword('ANY',subst,[b]).
346 keyword('ASSERT',subst,[b]).
347 keyword('BEGIN',subst,[b]).
348 keyword('CASE',subst,[b,tla]).
349 keyword('CHOICE',subst,[b]).
350 keyword('DO',subst,[b]).
351 keyword('EITHER',subst,[b]).
352 keyword('OR',subst,[b]).
353 keyword('OF',subst,[b]).
354 keyword('PRE',subst,[b]).
355 keyword('SELECT',subst,[b]).
356 keyword('WHERE',subst,[b]).
357 keyword('WHILE',subst,[b]).
358 keyword('WITH',subst,[b,tla]).
359
360 % --
361
362 keyword('ABSTRACT_CONSTANTS',section,[b]).
363 keyword('ABSTRACT_VARIABLES',section,[b]).
364 keyword('ASSERTIONS',section,[b]).
365 keyword('CONCRETE_CONSTANTS',section,[b]).
366 keyword('CONCRETE_VARIABLES',section,[b]).
367 keyword('CONSTANTS',section,[b,tla]).
368 keyword('CONSTRAINTS',section,[b]).
369 keyword('DEFINITIONS',section,[b]).
370 keyword('EVENT',section,[b]).
371 keyword('EXTENDS',section,[b,tla]).
372 keyword('IMPLEMENTATION',section,[b]).
373 keyword('IMPORTS',section,[b]).
374 keyword('INCLUDES',section,[b]).
375 keyword('INITIALISATION',section,[b]).
376 keyword('INITIALIZATION',section,[b]).
377 keyword('INVARIANT',section,[b]).
378 keyword('LOCAL_OPERATIONS',section,[b]).
379 keyword('MACHINE',section,[b]).
380 keyword('MODEL',section,[b]).
381 keyword('OPERATIONS',section,[b]).
382 keyword('PROMOTES',section,[b]).
383 keyword('PROPERTIES',section,[b]).
384 keyword('REFINEMENT',section,[b]).
385 keyword('REFINES',section,[b]).
386 keyword('SEES',section,[b]).
387 keyword('SYSTEM',section,[b]).
388 keyword('USES',section,[b]).
389 keyword('VALUES',section,[b]).
390 keyword('VARIABLES',section,[b,tla]).
391 keyword('VARIANT',section,[b]).
392
393 % rules-dsl sections
394 keyword('ACTIVATION',section,[rules_dsl]).
395 keyword('BODY',section,[rules_dsl]).
396 keyword('CLASSIFICATION',section,[rules_dsl]).
397 keyword('COMPUTATION',section,[rules_dsl]).
398 keyword('COUNTEREXAMPLE',section,[rules_dsl]).
399 keyword('DEPENDS_ON_COMPUTATION',section,[rules_dsl]).
400 keyword('DEPENDS_ON_RULE',section,[rules_dsl]).
401 keyword('DEFINE',section,[rules_dsl]).
402 keyword('DUMMY_VALUE',section,[rules_dsl]).
403 keyword('ERROR_TYPE',section,[rules_dsl]).
404 keyword('ERROR_TYPES',section,[rules_dsl]).
405 keyword('FOR',section,[rules_dsl]).
406 keyword('FUNCTION',section,[rules_dsl]).
407 keyword('ON_SUCCESS',section,[rules_dsl]).
408 keyword('POSTCONDITION',section,[rules_dsl]).
409 keyword('PRECONDITION',section,[rules_dsl]).
410 keyword('REFERENCES',section,[rules_dsl]).
411 keyword('REPLACES',section,[rules_dsl]).
412 keyword('RULE_FAIL',section,[rules_dsl]).
413 keyword('RULE_FORALL',section,[rules_dsl]).
414 keyword('RULE',section,[rules_dsl]).
415 keyword('RULEID',section,[rules_dsl]).
416 keyword('RULES_MACHINE',section,[rules_dsl]).
417 keyword('TAGS',section,[rules_dsl]).
418 keyword('TYPE',section,[rules_dsl]).
419 keyword('VALUE',section,[rules_dsl]).
420
421
422 % TODO: check if these below are available within expressions:
423 keyword('DISABLED_RULE',section,[rules_dsl]).
424 keyword('FAILED_RULE',section,[rules_dsl]).
425 keyword('FAILED_RULE_ERROR_TYPE',section,[rules_dsl]).
426 keyword('FAILED_RULE_ALL_ERROR_TYPES',section,[rules_dsl]).
427 keyword('GET_RULE_COUNTEREXAMPLES',section,[rules_dsl]).
428 keyword('NOT_CHECKED_RULE',section,[rules_dsl]).
429 keyword('STRING_FORMAT',section,[rules_dsl]).
430 keyword('SUCCEEDED_RULE',section,[rules_dsl]).
431 keyword('SUCCEEDED_RULE_ERROR_TYPE',section,[rules_dsl]).
432
433
434 keyword('@desc',pragma,[b]).
435 keyword('@file',pragma,[b]).
436 keyword('@generated',pragma,[b]).
437 keyword('@import-package',pragma,[b]).
438 keyword('@label',pragma,[b]).
439 keyword('@package',pragma,[b]).
440 keyword('@symbolic',pragma,[b]).
441
442 % TLA sections
443 keyword('ASSUME',section,[tla]).
444 keyword('ASSUMPTION',section,[tla]).
445 keyword('AXIOM',section,[tla]).
446 keyword('CONSTANT',section,[tla]).
447 keyword('LOCAL',section,[tla]).
448 keyword('INSTANCE',section,[b,tla]).
449 keyword('MODULE',section,[tla]).
450 keyword('THEOREM',section,[tla]).
451
452 keyword('IF',_,[b,tla]).
453 keyword('THEN',_,[b,tla]).
454 keyword('ELSE',_,[b,tla]).
455 keyword('ELSIF',_,[b]).
456 keyword('LET',_,[b,tla]).
457 keyword('BE',_,[b]).
458 keyword('IN',_,[b,tla]).
459 keyword('END',_,[b,tla]).
460
461 % TLA expression keywords
462 keyword('BOOLEAN',expr,[tla]).
463 keyword('Cardinality',expr,[tla]).
464 keyword('CHOOSE',expr,[tla]).
465 keyword('DOMAIN',expr,[tla]).
466 keyword('ENABLED',expr,[tla]).
467 keyword('EXCEPT',expr,[tla]).
468 keyword('SUBSET',expr,[tla]).
469 keyword('UNCHANGED',expr,[tla]).
470 keyword('UNION',expr,[tla]).
471
472 % Alloy sections
473 keyword('abstract',section,[alloy]).
474 keyword('assert',section,[alloy]).
475 keyword('check',section,[alloy]).
476 keyword('extends',section,[alloy]).
477 keyword('fact',section,[alloy]).
478 keyword('fun',section,[alloy]).
479 keyword('module',section,[alloy]).
480 keyword('open',section,[alloy]).
481 keyword('pred',section,[alloy]).
482 keyword('run',section,[alloy]).
483 keyword('sig',section,[alloy]).
484
485
486 keyword('div',expr,[alloy]).
487 keyword('minus',expr,[alloy]).
488 keyword('else',expr,[alloy]).
489 keyword('iden',expr,[alloy]).
490 keyword('let',expr,[alloy]).
491 keyword('mul',expr,[alloy]).
492 keyword('plus',expr,[alloy]).
493 keyword('rem',expr,[alloy]).
494 keyword('sum',expr,[alloy]).
495 keyword('univ',expr,[alloy]).
496
497 keyword('all',predicate,[alloy]).
498 keyword('disjoint',predicate,[alloy]).
499 keyword('iff',predicate,[alloy]).
500 keyword('implies',predicate,[alloy]).
501 keyword('lone',predicate,[alloy]).
502 keyword('not',predicate,[alloy]).
503 keyword('no',predicate,[alloy]).
504 keyword('none',predicate,[alloy]).
505 keyword('one',predicate,[alloy]).
506 keyword('or',predicate,[alloy]).
507 keyword('some',predicate,[alloy]).
508 keyword('set',expr,[alloy]).
509
510 % SVG
511
512 get_all_svg_attributes(SList) :- findall(A,is_svg_attribute(A),List), sort(List,SList).
513
514 % first list of svg attributes which are not number or color attributes
515 is_svg_attribute(children). % virtual attribute of VisB
516 is_svg_attribute(class).
517 is_svg_attribute('clip-path').
518 is_svg_attribute('clip-rule').
519 is_svg_attribute('color-rendering').
520 is_svg_attribute(cursor).
521 is_svg_attribute(display).
522 is_svg_attribute('dominant-baseline').
523 is_svg_attribute('fill-opacity').
524 is_svg_attribute('fill-rule').
525 is_svg_attribute('flood-opacity').
526 is_svg_attribute('font-family').
527 is_svg_attribute('font-style'). % normal | italic | oblique
528 is_svg_attribute('font-variant').
529 is_svg_attribute('font-weight'). % normal | bold | bolder | lighter | <number>
530 is_svg_attribute(from).
531 is_svg_attribute(group_id). % virtual attribute of VisB
532 is_svg_attribute('href'). % use
533 is_svg_attribute(id).
534 is_svg_attribute('marker-end').
535 is_svg_attribute('marker-start').
536 is_svg_attribute(mask).
537 % Note: name is a deprecated SVG attribute
538 is_svg_attribute(path).
539 is_svg_attribute('pointer-events').
540 is_svg_attribute(points). % polyline, polygon
541 is_svg_attribute(radius).
542 is_svg_attribute(repeatDur).
543 is_svg_attribute(restart).
544 is_svg_attribute(rotate).
545 is_svg_attribute(scale).
546 is_svg_attribute(seed).
547 is_svg_attribute('shape-rendering').
548 is_svg_attribute(startoffset).
549 is_svg_attribute(stdDeviation).
550 is_svg_attribute(stitchTiles).
551 is_svg_attribute(stroke).
552 is_svg_attribute('stroke-dasharray').
553 is_svg_attribute('stroke-dashoffset').
554 is_svg_attribute('stroke-linecap'). % butt (default), round, square
555 is_svg_attribute('stroke-linejoin').
556 is_svg_attribute('stroke-miterlimit').
557 is_svg_attribute(style).
558 is_svg_attribute(surfaceScale).
559 is_svg_attribute(systemLanguage).
560 is_svg_attribute(tableValues).
561 is_svg_attribute(text).
562 is_svg_attribute('text-anchor').
563 is_svg_attribute('text-decoration').
564 is_svg_attribute('text-rendering').
565 is_svg_attribute(textLength).
566 is_svg_attribute(title). % virtual attribute of VisB
567 is_svg_attribute(to).
568 is_svg_attribute(transform).
569 is_svg_attribute(type).
570 is_svg_attribute(visibility).
571 is_svg_attribute('vector-effect').
572 is_svg_attribute('word-spacing').
573 is_svg_attribute('xlink:href').
574 is_svg_attribute(X) :- is_svg_number_attribute(X,_).
575 is_svg_attribute(X) :- is_svg_color_attribute(X).
576 % TODO: complete
577
578 is_svg_color_attribute(color). % can be applied to any element; provides currentcolor value
579 is_svg_color_attribute(fill). % can be applied to [circle,ellipse,path,polygon,polyline,rect,text,tref,tspan]).
580 is_svg_color_attribute(stroke). % can also be applied to all shapes we use circle, ...
581 is_svg_color_attribute('flood-color').
582 is_svg_color_attribute('lighting-color').
583 is_svg_color_attribute('stop-color').
584
585 is_svg_number_attribute(cx,[circle, ellipse, radialGradient]).
586 is_svg_number_attribute(cy,[circle, ellipse, radialGradient]).
587 is_svg_number_attribute(dx,_).
588 is_svg_number_attribute(dy,_).
589 is_svg_number_attribute(opacity,_).
590 is_svg_number_attribute(pathLength,_).
591 is_svg_number_attribute(x,[foreignObject,image,rect,svg,text,tspan,use]). % many more: cursor, image, mask, pattern, ...
592 is_svg_number_attribute(y,[foreignObject,image,rect,svg,text,tspan,use]).
593 is_svg_number_attribute(x1,[line,linearGradient]).
594 is_svg_number_attribute(x2,[line,linearGradient]).
595 is_svg_number_attribute(y1,[line,linearGradient]).
596 is_svg_number_attribute(y2,[line,linearGradient]).
597 is_svg_number_attribute('font-size',_).
598 is_svg_number_attribute('stop-opacity',_).
599 is_svg_number_attribute('stroke-opacity',_).
600 is_svg_number_attribute('stroke-width',_).
601 is_svg_number_attribute(height,[foreignObject,image,rect,svg]). % others like mask ,...
602 is_svg_number_attribute(width, [foreignObject,image,rect,svg]).
603 is_svg_number_attribute(r,[circle, radialGradient]).
604 is_svg_number_attribute(rx,[ellipse,rect]).
605 is_svg_number_attribute(ry,[ellipse,rect]).
606 is_svg_number_attribute(tabindex,_).
607 is_svg_number_attribute(z,_).
608
609 is_svg_color_name(aliceblue).
610 is_svg_color_name(antiquewhite).
611 is_svg_color_name(aqua).
612 is_svg_color_name(aquamarine).
613 is_svg_color_name(azure).
614 is_svg_color_name(beige).
615 is_svg_color_name(bisque).
616 is_svg_color_name(black).
617 is_svg_color_name(blanchedalmond).
618 is_svg_color_name(blue).
619 is_svg_color_name(blueviolet).
620 is_svg_color_name(brown).
621 is_svg_color_name(burlywood).
622 is_svg_color_name(cadetblue).
623 is_svg_color_name(chartreuse).
624 is_svg_color_name(chocolate).
625 is_svg_color_name(coral).
626 is_svg_color_name(cornflowerblue).
627 is_svg_color_name(cornsilk).
628 is_svg_color_name(crimson).
629 is_svg_color_name(cyan).
630 is_svg_color_name(darkblue).
631 is_svg_color_name(darkcyan).
632 is_svg_color_name(darkgoldenrod).
633 is_svg_color_name(darkgray).
634 is_svg_color_name(darkgreen).
635 is_svg_color_name(darkgrey).
636 is_svg_color_name(darkkhaki).
637 is_svg_color_name(darkmagenta).
638 is_svg_color_name(darkolivegreen).
639 is_svg_color_name(darkorange).
640 is_svg_color_name(darkorchid).
641 is_svg_color_name(darkred).
642 is_svg_color_name(darksalmon).
643 is_svg_color_name(darkseagreen).
644 is_svg_color_name(darkslateblue).
645 is_svg_color_name(darkslategray).
646 is_svg_color_name(darkslategrey).
647 is_svg_color_name(darkturquoise).
648 is_svg_color_name(darkviolet).
649 is_svg_color_name(deeppink).
650 is_svg_color_name(deepskyblue).
651 is_svg_color_name(dimgray).
652 is_svg_color_name(dimgrey).
653 is_svg_color_name(dodgerblue).
654 is_svg_color_name(firebrick).
655 is_svg_color_name(floralwhite).
656 is_svg_color_name(forestgreen).
657 is_svg_color_name(fuchsia).
658 is_svg_color_name(gainsboro).
659 is_svg_color_name(ghostwhite).
660 is_svg_color_name(gold).
661 is_svg_color_name(goldenrod).
662 is_svg_color_name(gray).
663 is_svg_color_name(green).
664 is_svg_color_name(greenyellow).
665 is_svg_color_name(grey).
666 is_svg_color_name(honeydew).
667 is_svg_color_name(hotpink).
668 is_svg_color_name(indianred).
669 is_svg_color_name(indigo).
670 is_svg_color_name(ivory).
671 is_svg_color_name(khaki).
672 is_svg_color_name(lavender).
673 is_svg_color_name(lavenderblush).
674 is_svg_color_name(lawngreen).
675 is_svg_color_name(lemonchiffon).
676 is_svg_color_name(lightblue).
677 is_svg_color_name(lightcoral).
678 is_svg_color_name(lightcyan).
679 is_svg_color_name(lightgoldenrodyellow).
680 is_svg_color_name(lightgray).
681 is_svg_color_name(lightgreen).
682 is_svg_color_name(lightgrey).
683 is_svg_color_name(lightpink).
684 is_svg_color_name(lightsalmon).
685 is_svg_color_name(lightseagreen).
686 is_svg_color_name(lightskyblue).
687 is_svg_color_name(lightslategray).
688 is_svg_color_name(lightslategrey).
689 is_svg_color_name(lightsteelblue).
690 is_svg_color_name(lightyellow).
691 is_svg_color_name(lime).
692 is_svg_color_name(limegreen).
693 is_svg_color_name(linen).
694 is_svg_color_name(magenta).
695 is_svg_color_name(maroon).
696 is_svg_color_name(mediumaquamarine).
697 is_svg_color_name(mediumblue).
698 is_svg_color_name(mediumorchid).
699 is_svg_color_name(mediumpurple).
700 is_svg_color_name(mediumseagreen).
701 is_svg_color_name(mediumslateblue).
702 is_svg_color_name(mediumspringgreen).
703 is_svg_color_name(mediumturquoise).
704 is_svg_color_name(mediumvioletred).
705 is_svg_color_name(midnightblue).
706 is_svg_color_name(mintcream).
707 is_svg_color_name(mistyrose).
708 is_svg_color_name(moccasin).
709 is_svg_color_name(navajowhite).
710 is_svg_color_name(navy).
711 is_svg_color_name(oldlace).
712 is_svg_color_name(olive).
713 is_svg_color_name(olivedrab).
714 is_svg_color_name(orange).
715 is_svg_color_name(orangered).
716 is_svg_color_name(orchid).
717 is_svg_color_name(palegoldenrod).
718 is_svg_color_name(palegreen).
719 is_svg_color_name(paleturquoise).
720 is_svg_color_name(palevioletred).
721 is_svg_color_name(papayawhip).
722 is_svg_color_name(peachpuff).
723 is_svg_color_name(peru).
724 is_svg_color_name(pink).
725 is_svg_color_name(plum).
726 is_svg_color_name(powderblue).
727 is_svg_color_name(purple).
728 is_svg_color_name(red).
729 is_svg_color_name(rosybrown).
730 is_svg_color_name(royalblue).
731 is_svg_color_name(saddlebrown).
732 is_svg_color_name(salmon).
733 is_svg_color_name(sandybrown).
734 is_svg_color_name(seagreen).
735 is_svg_color_name(seashell).
736 is_svg_color_name(sienna).
737 is_svg_color_name(silver).
738 is_svg_color_name(skyblue).
739 is_svg_color_name(slateblue).
740 is_svg_color_name(slategray).
741 is_svg_color_name(slategrey).
742 is_svg_color_name(snow).
743 is_svg_color_name(springgreen).
744 is_svg_color_name(steelblue).
745 is_svg_color_name(tan).
746 is_svg_color_name(teal).
747 is_svg_color_name(thistle).
748 is_svg_color_name(tomato).
749 is_svg_color_name(turquoise).
750 is_svg_color_name(violet).
751 is_svg_color_name(wheat).
752 is_svg_color_name(white).
753 is_svg_color_name(whitesmoke).
754 is_svg_color_name(yellow).
755 is_svg_color_name(yellowgreen).
756
757 % ----------------------------
758
759 % DOT
760 get_all_dot_attributes(SList) :- findall(A,is_dot_attribute(A),List), sort(List,SList).
761
762 % list of known synonyms of Dot attributes and how to translate them to SVG object attributes
763 dot2svg_synonym(fillcolor,color).
764 dot2svg_synonym(fontname,'font-family').
765 dot2svg_synonym(fontcolor,fill). % one should probably use fill to colour text
766 dot2svg_synonym(fontcolour,fill).
767 dot2svg_synonym('font-color',fill). % not really a dot attribute, but a
768 dot2svg_synonym('font-colour',fill).
769
770 % see https://graphviz.org/docs/nodes/, comments taken from there
771 is_dot_attribute(area).
772 is_dot_attribute(class). % Classnames to attach to the node, edge, graph, or cluster's SVG element. For svg only.
773 is_dot_attribute(color). % Basic drawing color for graphics, not text.
774 is_dot_attribute(colorscheme). % A color scheme namespace: the context for interpreting color names.
775 is_dot_attribute(comment). % Comments are inserted into output.
776 is_dot_attribute(distortion). % Distortion factor for shape=polygon.
777 is_dot_attribute(fillcolor). % Color used to fill the background of a node or cluster.
778 is_dot_attribute(fixedsize).
779 is_dot_attribute(fontcolor). % Color used for text.
780 is_dot_attribute(fontname). % Font used for text.
781 is_dot_attribute(fontsize). % Font size, in points, used for text.
782 is_dot_attribute(gradientangle). % If a gradient fill is being used, this determines the angle of the fill.
783 is_dot_attribute(group). % Name for a group of nodes, for bundling edges avoiding crossings. For dot only.
784 is_dot_attribute(height). % Height of node, in inches.
785 is_dot_attribute(href). % Synonym for URL. For map, postscript, svg only.
786 is_dot_attribute(id). % Identifier for graph objects. For map, postscript, svg only.
787 is_dot_attribute(image).
788 is_dot_attribute(imagepos).
789 is_dot_attribute(imagescale).
790 is_dot_attribute(label). % Text label attached to objects.
791 is_dot_attribute(labelloc). % Vertical placement of labels for nodes, root graphs and clusters.
792 is_dot_attribute(layer). % Specifies layers in which the node, edge or cluster is present.
793 %is_dot_attribute(margin). % For graphs, this sets x and y margins of canvas, in inches.
794 is_dot_attribute(nojustify). % Whether to justify multiline text vs the previous text line (rather than the side of the container).
795 is_dot_attribute(ordering). % default, out, in Constrains the left-to-right ordering of node edges. For dot only.
796 is_dot_attribute(orientation).% node shape rotation angle, or graph orientation.
797 is_dot_attribute(penwidth). % Specifies the width of the pen, in points, used to draw lines and curves.
798 is_dot_attribute(peripheries). % Set number of peripheries used in polygonal shapes and cluster boundaries.
799 is_dot_attribute(pin).
800 is_dot_attribute(pos).
801 is_dot_attribute(rects).
802 is_dot_attribute(regular).
803 is_dot_attribute(root).
804 is_dot_attribute(samplepoints). % Gives the number of points used for a circle/ellipse node.
805 is_dot_attribute(shape). % Sets the shape of a node.
806 is_dot_attribute(shapefile).
807 is_dot_attribute(showboxes). % Print guide boxes for debugging. For dot only.
808 is_dot_attribute(style). % Set style information for components of the graph.
809 is_dot_attribute(skew). % Skew factor for shape=polygon.
810 is_dot_attribute(sides). % Number of sides when shape=polygon.
811 is_dot_attribute(sortv). % Sort order of graph components for ordering packmode packing.
812 is_dot_attribute(target). % If the object has a URL, this attribute determines which window of the browser is used for the URL. For map, svg only.
813 is_dot_attribute(tooltip). % Tooltip (mouse hover text) attached to the node, edge, cluster, or graph
814 is_dot_attribute('URL').
815 is_dot_attribute(vertices).
816 is_dot_attribute(width). % Width of node, in inches.
817 is_dot_attribute(xlabel). % External label for a node or edge.
818 is_dot_attribute(xlp). % Position of an exterior label, in points. For write only.
819 is_dot_attribute(z). % Z-coordinate value for 3D layouts and displays.
820
821 % additional edge attributes from https://graphviz.org/docs/edges/
822 is_dot_attribute(arrowhead). % Style of arrowhead on the head node of an edge.
823 is_dot_attribute(arrowsize). % Multiplicative scale factor for arrowheads.
824 is_dot_attribute(arrowtail). % Style of arrowhead on the tail node of an edge.
825 is_dot_attribute(constraint). % If false, the edge is not used in ranking the nodes. For dot only.
826 is_dot_attribute(decorate). % Whether to connect the edge label to the edge with a line.
827 is_dot_attribute(dir). % Edge type for drawing arrowheads. (forward, back, both, none)
828 is_dot_attribute(headlabel). % Text label to be placed near head of edge.
829 is_dot_attribute(headport). % Indicates where on the head node to attach the head of the edge.
830 is_dot_attribute(labelangle).
831 is_dot_attribute(labeldistance).
832 is_dot_attribute(labelfloat).
833 is_dot_attribute(labelfontcolor). % Color used for headlabel and taillabel.
834 is_dot_attribute(labelfontname). % Font for headlabel and taillabel.
835 is_dot_attribute(labelfontsize). % Font size of headlabel and taillabel.
836 is_dot_attribute(len).
837 is_dot_attribute(lhead). % Logical head of an edge. For dot only.
838 is_dot_attribute(minlen). % Minimum edge length (rank difference between head and tail). For dot only.
839 is_dot_attribute(taillabel). % Text label to be placed near tail of edge.
840 is_dot_attribute(tailport). % Indicates where on the tail node to attach the tail of the edge.
841 is_dot_attribute(weight). % Weight of edge. In dot, the heavier the weight, the shorter, straighter and more vertical the edge is.
842
843 % for graphs:
844 is_dot_attribute(bgcolor).
845 % https://graphviz.org/doc/info/colors.html#brewer
846 % ex: accent8, blue9, brbg11, bugn9, bupu9, dark28, gnbu9, greeens9, greys9, oranges9, set312, set39, spectral11
847 % does not work as graph attribute, needs to be set as default node/edge attribute or added to nodes/edges
848 is_dot_attribute(compound). % If true, allow edges between clusters. For dot only, relevant for lhead/ltail edge attrs
849 is_dot_attribute(concentrate). % If true, use edge concentrators.
850 is_dot_attribute(landscape). % If true, the graph is rendered in landscape mode.
851 is_dot_attribute(layout). % Which layout engine to use. dot, neato, circo, fdp, sfdp, twopi, patchwork, nop, nop2
852 is_dot_attribute(mode). % Technique for optimizing the layout
853 %is_dot_attribute(ordering). % declared for nodes above, Constrains the left-to-right ordering of node edges. For dot only. out, in
854 %is_dot_attribute(orientation). % declared for nodes above, node shape rotation angle, or graph orientation
855 is_dot_attribute(outputorder). % Specify order in which nodes and edges are drawn
856 is_dot_attribute(overlap). % Determines if and how node overlaps should be removed
857 is_dot_attribute(rankdir). % Sets direction of graph layout. For dot only. TB, BT, LR, RL
858 is_dot_attribute(ranksep). % Specifies separation between ranks. For dot, twopi only.
859 is_dot_attribute(ratio). % Sets the aspect ratio (drawing height/drawing width) for the drawing.
860 is_dot_attribute(scale). % Scales layout by the given factor after the initial layout
861 is_dot_attribute(size). % Maximum width and height of drawing, in inches
862 is_dot_attribute(splines).
863
864 is_dot_attribute(directed). % virtual attribute -> influences whether dot_graph_generator writes digraph or graph
865 is_dot_attribute(strict). % virtual attribute -> influences whether dot_graph_generator writes strict digraph/graph
866
867 % -------------
868
869
870 % translate_keywords:classical_b_keyword(K), \+ tools_matching:keyword(K,_,_). % Note: items is not a B keyword
871 % TO DO: complete keywords for Alloy, TLA, Z minor modes; possibly add VisB/SVG and CUSTOM_GRAPH/GraphViz attributes
872
873 :- use_module(preferences,[eclipse_preference/2]).
874 get_possible_preferences(SPrefs) :-
875 findall(Pref,eclipse_preference(Pref,_),P),
876 sort(P,SPrefs).
877
878 get_possible_preferences_matches_msg(String,FuzzyMatchMsg) :-
879 get_possible_preferences(Prefs),
880 if(get_possible_fuzzy_matches_and_completions_msg(String,Prefs,FuzzyMatchMsg),
881 true,
882 get_possible_inner_matches_msg(String,Prefs,FuzzyMatchMsg)). % also look for inner matches
883
884 :- use_module(specfile,[get_possible_language_specific_top_level_event/3]).
885 :- use_module(bmachine,[b_is_operation_name/1]).
886 get_possible_top_level_event_matches_msg(String,FuzzyMatchMsg) :-
887 findall(Op,get_possible_language_specific_top_level_event(Op,_,_),Ops), sort(Ops,SOps),
888 if(get_possible_fuzzy_matches_and_completions_msg(String,SOps,FuzzyMatchMsg),
889 true,
890 get_possible_inner_matches_msg(String,SOps,FuzzyMatchMsg)). % also look for inner matches
891
892
893 get_possible_fuzzy_matches_and_completions_msg(String,AllIds,FuzzyMatchMsg) :-
894 (get_possible_fuzzy_matches_msg(String,AllIds,FuzzyMatchMsg) ;
895 get_possible_completions_msg(String,AllIds,FuzzyMatchMsg)).
896
897 get_possible_fuzzy_matches(ID,AllIDs,FuzzyMatches) :-
898 atom_codes(ID,IDCodes),
899 findall(Target,(member(Target,AllIDs),atom_codes(Target,TargetCodes),
900 fuzzy_match_codes_lower_case(IDCodes,TargetCodes)),FuzzyMatches).
901
902 % get possible matches as atom which can be used after phrase: Did you mean:
903 get_possible_fuzzy_matches_msg(ID,AllIDs,Msg) :-
904 get_possible_fuzzy_matches(ID,AllIDs,FuzzyMatches),
905 get_match_msg(FuzzyMatches,Msg).
906
907 get_match_msg(FuzzyMatches,Msg) :-
908 length(FuzzyMatches,Nr), Nr>0,
909 get_msg(FuzzyMatches,Nr,Msg).
910
911 :- use_module(tools_strings,[ajoin/2,ajoin_with_sep/3]).
912 get_msg([Match],1,Res) :- !, Res=Match.
913 get_msg(List,Nr,Msg) :- Nr < 6, !,
914 ajoin_with_sep(List,',',Msg).
915 get_msg([First|_],Nr,Msg) :- N1 is Nr-1,
916 ajoin([First,' (',N1,' more matches)'],Msg).
917
918
919
920 % get possible completions as atom which can be used after phrase: Did you mean:
921 get_possible_completions_msg(ID,SortedAllIDs,Msg) :-
922 atom_codes(ID,IDCodes0),
923 codes_to_lower_case(IDCodes0,IDCodes),
924 findall(Target,(member(Target,SortedAllIDs),atom_codes(Target,TargetCodes),
925 codes_to_lower_case(TargetCodes,TC2),
926 prefix(TC2,IDCodes) % IDCodes is a prefix of the target
927 ),Completions),
928 get_match_msg(Completions,Msg).
929
930
931 % get possible interior matches as atom which can be used after phrase: Did you mean:
932 get_possible_inner_matches_msg(ID,SortedAllIDs,Msg) :-
933 atom_codes(ID,IDCodes0),
934 length(IDCodes0,Len), Len>3, % only do this if the string is long enough
935 codes_to_lower_case(IDCodes0,IDCodes),
936 findall(Target,(member(Target,SortedAllIDs),atom_codes(Target,TargetCodes),
937 codes_to_lower_case(TargetCodes,TC2),
938 % format('Looking for ~s inside ~s or vice-versa~n',[IDCodes,TC2]),
939 (sublist(IDCodes,TC2,_Before) -> true
940 ; sublist(TC2,IDCodes,_))
941 ),Completions),
942 get_match_msg(Completions,Msg).
943
944