1
2 /******************************************************************************
3 * MODULE : concat_inactive.cpp
4 * DESCRIPTION: Typesetting of inactive markup
5 * COPYRIGHT : (C) 1999 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12 #include "concater.hpp"
13 #include "analyze.hpp"
14
15 /******************************************************************************
16 * Subroutine for syntactic coloring
17 ******************************************************************************/
18
19 void
typeset_blue(tree t,path ip)20 concater_rep::typeset_blue (tree t, path ip) {
21 tree old_mode= env->local_begin (MODE, "src");
22 tree old_col = env->local_begin (COLOR, "blue");
23 tree old_fam = env->local_begin (FONT_FAMILY, "ss");
24 typeset (t, ip);
25 env->local_end (FONT_FAMILY, old_fam);
26 env->local_end (COLOR, old_col);
27 env->local_end (MODE, old_mode);
28 }
29
30 /******************************************************************************
31 * Rendering of source tree tags
32 ******************************************************************************/
33
34 void
typeset_src_open(tree t,path ip,string extra)35 concater_rep::typeset_src_open (tree t, path ip, string extra) {
36 bool visual_open=
37 // Visually speaking, the tag is an opening tag
38 (L(t) == INLINE_TAG) || (L(t) == OPEN_TAG) ||
39 (env->src_close == CLOSE_REPEAT);
40 bool visual_close=
41 // Visually speaking, the tag is a closing tag
42 (L(t) == INLINE_TAG) || (L(t) == CLOSE_TAG) ||
43 (env->src_close == CLOSE_REPEAT);
44
45 if (visual_open)
46 if ((L(t) != INLINE_TAG) && (env->src_close == CLOSE_MINIMAL)) {
47 typeset_blue (t[0], descend (ip, 0));
48 if (N(t) > 1) {
49 penalty_min (0);
50 print (env->fn->spc);
51 }
52 return;
53 }
54
55 if (visual_open) {
56 path dip= descend (ip, 0);
57 path nip= descend (descend (ip, 0), right_index (t[0]));
58 switch (env->src_style) {
59 case STYLE_ANGULAR:
60 ghost ("<", dip);
61 ghost (extra, dip);
62 typeset_blue (t[0], descend (ip, 0));
63 break;
64 case STYLE_SCHEME:
65 ghost ("(", dip);
66 ghost (extra, dip);
67 typeset_blue (t[0], descend (ip, 0));
68 break;
69 case STYLE_LATEX:
70 //ghost ("\\", dip);
71 //if (extra == "\\") ghost ("begin", dip);
72 //else if (extra == "|") ghost ("continue", dip);
73 //else if (extra == "/") ghost ("end", dip);
74 //if (extra != "") ghost ("{", dip);
75 ghost (extra, dip);
76 typeset_blue (t[0], descend (ip, 0));
77 //if (extra != "") ghost ("}", nip);
78 break;
79 case STYLE_FUNCTIONAL:
80 ghost (extra, dip);
81 typeset_blue (t[0], descend (ip, 0));
82 break;
83 }
84 }
85
86 if (visual_close && (N(t) == 1))
87 // No arguments or block arguments follow
88 return;
89
90 path dip = descend (descend (ip, 1), 0);
91 if (N(t) == 1) dip= descend (descend (ip, 0), right_index (t[0]));
92 if (visual_open) {
93 if (env->src_style == STYLE_LATEX) ghost ("{", dip);
94 else if (env->src_style == STYLE_FUNCTIONAL) {
95 print (env->fn->spc / 2);
96 ghost ("(", dip);
97 }
98 else typeset_src_middle (t, ip, 1);
99 }
100 else typeset_src_middle (t, ip, 1);
101 }
102
103 void
typeset_src_middle(tree t,path ip,int i)104 concater_rep::typeset_src_middle (tree t, path ip, int i) {
105 path pip= descend (descend (ip, i-1), right_index (t[i-1]));
106 path dip= descend (descend (ip, i), 0);
107 if (i == N(t)) dip= pip;
108 switch (env->src_style) {
109 case STYLE_ANGULAR:
110 print (space (0, 0, env->fn->spc->max));
111 ghost ("|", dip);
112 penalty_min (0);
113 print (space (0, 0, env->fn->spc->max));
114 break;
115 case STYLE_SCHEME:
116 penalty_min (0);
117 print (env->fn->spc);
118 break;
119 case STYLE_LATEX:
120 if ((L(t) != INLINE_TAG) && (env->src_close == CLOSE_MINIMAL)) {
121 ghost (",", dip);
122 penalty_min (0);
123 print (env->fn->spc / 2);
124 }
125 else {
126 ghost ("}", pip);
127 penalty_min (0);
128 ghost ("{", dip);
129 }
130 break;
131 case STYLE_FUNCTIONAL:
132 ghost (",", dip);
133 penalty_min (0);
134 print (env->fn->spc / 2);
135 break;
136 }
137 }
138
139 void
typeset_src_close(tree t,path ip)140 concater_rep::typeset_src_close (tree t, path ip) {
141 path dip= descend (descend (ip, N(t)-1), right_index (t[N(t)-1]));
142 switch (env->src_style) {
143 case STYLE_ANGULAR:
144 ghost (">", dip);
145 break;
146 case STYLE_SCHEME:
147 ghost (")", dip);
148 break;
149 case STYLE_LATEX:
150 ghost ("}", dip);
151 break;
152 case STYLE_FUNCTIONAL:
153 ghost (")", dip);
154 break;
155 }
156 }
157
158 void
typeset_src_args(tree t,path ip)159 concater_rep::typeset_src_args (tree t, path ip) {
160 int i, n= N(t);
161 for (i=1; i<n; i++) {
162 if (i>1) typeset_src_middle (t, ip, i);
163 typeset (t[i], descend (ip, i));
164 }
165 }
166
167 void
typeset_src_tag(tree t,path ip)168 concater_rep::typeset_src_tag (tree t, path ip) {
169 if (N(t) == 0) { typeset_error (t, ip); return; }
170 int n= N(t);
171 marker (descend (ip, 0));
172 if ((L(t) == INLINE_TAG) || (env->src_close == CLOSE_REPEAT)) {
173 string extra;
174 if (L(t) == OPEN_TAG) extra= "\\";
175 else if (L(t) == MIDDLE_TAG) extra= "|";
176 else if (L(t) == CLOSE_TAG) extra= "/";
177 typeset_src_open (t, ip, extra);
178 typeset_src_args (t, ip);
179 if ((n>1) ||
180 (env->src_style == STYLE_ANGULAR) || (env->src_style == STYLE_SCHEME))
181 typeset_src_close (t, ip);
182 }
183 else {
184 typeset_src_open (t, ip, "");
185 typeset_src_args (t, ip);
186 if ((n>1) || (L(t) == CLOSE_TAG))
187 if ((L(t) == MIDDLE_TAG) || (env->src_close != CLOSE_MINIMAL)) {
188 if (L(t) == CLOSE_TAG) typeset_src_close (t, ip);
189 else typeset_src_middle (t, ip, n);
190 }
191 }
192 marker (descend (ip, 1));
193 }
194
195 /******************************************************************************
196 * Inactive and erroneous markup
197 ******************************************************************************/
198
199 void
typeset_inactive(tree t,path ip)200 concater_rep::typeset_inactive (tree t, path ip) {
201 tree m (MACRO, "x", tree (REWRITE_INACTIVE, tree (ARG, "x"), "once"));
202 typeset_auto (t, ip, m);
203 }
204
205 void
typeset_error(tree t,path ip)206 concater_rep::typeset_error (tree t, path ip) {
207 tree m (MACRO, "x", tree (REWRITE_INACTIVE, tree (ARG, "x"), "error"));
208 marker (descend (ip, 0));
209 typeset_auto (attach_right (t, ip), m);
210 marker (descend (ip, 1));
211 }
212