Debian Codegraph @

manual/templates.xml

raw
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE chapter SYSTEM "docbook-dtd-45/docbookx.dtd">
3
4 <chapter id="templates">
5 <title>Templates</title>
6
7 <para>
8 Sets up templates of alternative contextual tests which can later be referred to by multiple rules or other templates.
9 Templates support the full syntax of contextual tests, including all other new CG-3 features.
10 Best way to document them that I can think of at the moment is to give examples of equivalent constructions.
11 </para>
12
13 <para>
14 For example, this construction
15 <screen>
16 TEMPLATE tmpl = 1 (a) LINK 1 B + C LINK 1 D - (e) ;
17 SELECT (tag) IF (T:tmpl) ;
18 </screen>
19 is equivalent to
20 <screen>
21 SELECT (tag) IF (1 (a) LINK 1 B + C LINK 1 D - (e)) ;
22 </screen>
23 </para>
24
25 <para>
26 But with the introduction of templates, CG-3 also allows alternative tests, so this construction
27 <screen>
28 TEMPLATE tmpl = (1 ASET LINK 1 BSET) OR (-1 BSET LINK -1 ASET) ;
29 SELECT (tag) IF (1 Before LINK T:tmpl LINK 1 After) ;
30 </screen>
31 is equivalent to
32 <screen>
33 # Yes, inline OR is allowed if you () the tests properly
34 SELECT (tag) IF (1 Before LINK (1 ASET LINK 1 BSET) OR (-1 BSET LINK -1 ASET) LINK 1 After) ;
35 </screen>
36 which in turn is equivalent to
37 <screen>
38 SELECT (tag) IF (1 Before LINK 1 ASET LINK 1 BSET LINK 1 After) ;
39 SELECT (tag) IF (1 Before LINK -1 BSET LINK -1 ASET LINK 1 After) ;
40 </screen>
41 </para>
42
43 <para>
44 For very simple lists of LINK 1 constructs, there is a further simplification:
45 <screen>
46 # Note the use of [] and , instead of ()
47 TEMPLATE tmpl = [(a), BSET, CSET - (d)] ;
48 </screen>
49 is equivalent to
50 <screen>
51 TEMPLATE tmpl = 1 (a) LINK 1 BSET LINK 1 CSET - (d) ;
52 </screen>
53 However, the [] construct is not directly allowed in OR constructions, so you cannot write
54 <screen>
55 TEMPLATE tmpl = [a, b, c] OR [e, f, g] ; # invalid
56 </screen>
57 but you can instead write
58 <screen>
59 TEMPLATE tmpl = ([a, b, c]) OR ([e, f, g]) ; # valid
60 </screen>
61 The [] construct can also be linked to and from, so
62 <screen>
63 TEMPLATE tmpl = [a, b, c] LINK 1* d BARRIER h LINK [e, f, g] ;
64 </screen>
65 is equivalent to
66 <screen>
67 TEMPLATE tmpl = 1 a LINK 1 b LINK 1 c LINK 1* d BARRIER h LINK 1 e LINK 1 f LINK 1 g ;
68 </screen>
69 </para>
70
71 <para>
72 Templates can be used in place of any normal contextual test, and can be both linked to and from, so
73 <screen>
74 TEMPLATE tmpl = 1 (donut) BARRIER (waffle) ;
75 SELECT (tag) IF (1 VSET LINK T:tmpl LINK 1* FSET) ;
76 </screen>
77 is equivalent to
78 <screen>
79 SELECT (tag) IF (1 VSET LINK 1 (donut) BARRIER (waffle) LINK 1* FSET) ;
80 </screen>
81 </para>
82
83 <section id="tmpl-override">
84 <title>Position Override</title>
85 <para>
86 It is also possible to override the position of a template, which changes their behavior. E.g:
87 <screen>
88 TEMPLATE tmpl = [N, CC, ADJ] ;
89 # ... or ...
90 TEMPLATE tmpl = 1 N LINK 1 CC LINK 1 ADJ ;
91 SELECT (tag) IF (-1 T:tmpl) ;
92 </screen>
93 is equivalent to
94 <screen>
95 SELECT (tag) IF (-1** N LINK 1 CC LINK 1 ADJ) ;
96 </screen>
97 but with a post-condition that the cohorts at the edges of the instantiated template must be at the position given relative to the origin.
98 In this case, a match of the template is only succesful if ADJ is in position -1 to the origin (tag).
99 This behavior is equivalent to how templates worked in Fred Karlsson's CG-1, but with more flexibility.
100 </para>
101 <para>
102 The post-condition check cannot currently inspect the actual edges of the space that the template touched to instantiate,
103 so it will perform the edge checks on the entry and exit cohorts only. A positive override will require that the leftmost
104 edge matches the position, while negative override will require rightmost edge matches. When linking from overridden
105 tests, a positive link will try to match from the rightmost edge, and negative link from the leftmost.
106 </para>
107 </section>
108
109 </chapter>