Back to index

texmacs  1.0.7.15
concat_inactive.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : concat_inactive.cpp
00004 * DESCRIPTION: Typesetting of inactive markup
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "concater.hpp"
00013 #include "analyze.hpp"
00014 
00015 /******************************************************************************
00016 * Subroutine for syntactic coloring
00017 ******************************************************************************/
00018 
00019 void
00020 concater_rep::typeset_blue (tree t, path ip) {
00021   tree old_mode= env->local_begin (MODE, "src");
00022   tree old_col = env->local_begin (COLOR, "blue");
00023   tree old_fam = env->local_begin (FONT_FAMILY, "ss");
00024   typeset (t, ip);
00025   env->local_end (FONT_FAMILY, old_fam);
00026   env->local_end (COLOR, old_col);
00027   env->local_end (MODE, old_mode);
00028 }
00029 
00030 /******************************************************************************
00031 * Rendering of source tree tags
00032 ******************************************************************************/
00033 
00034 void
00035 concater_rep::typeset_src_open (tree t, path ip, string extra) {
00036   bool visual_open=
00037     // Visually speaking, the tag is an opening tag
00038     (L(t) == INLINE_TAG) || (L(t) == OPEN_TAG) ||
00039     (env->src_close == CLOSE_REPEAT);
00040   bool visual_close=
00041     // Visually speaking, the tag is a closing tag
00042     (L(t) == INLINE_TAG) || (L(t) == CLOSE_TAG) ||
00043     (env->src_close == CLOSE_REPEAT);
00044 
00045   if (visual_open)
00046     if ((L(t) != INLINE_TAG) && (env->src_close == CLOSE_MINIMAL)) {
00047       typeset_blue (t[0], descend (ip, 0));
00048       if (N(t) > 1) {
00049        penalty_min (0);
00050        print (env->fn->spc);
00051       }
00052       return;
00053     }
00054 
00055   if (visual_open) {
00056     path dip= descend (ip, 0);
00057     path nip= descend (descend (ip, 0), right_index (t[0]));
00058     switch (env->src_style) {
00059     case STYLE_ANGULAR:
00060       ghost ("<", dip);
00061       ghost (extra, dip);
00062       typeset_blue (t[0], descend (ip, 0));
00063       break;
00064     case STYLE_SCHEME:
00065       ghost ("(", dip);
00066       ghost (extra, dip);
00067       typeset_blue (t[0], descend (ip, 0));
00068       break;
00069     case STYLE_LATEX:
00070       //ghost ("\\", dip);
00071       //if (extra == "\\") ghost ("begin", dip);
00072       //else if (extra == "|") ghost ("continue", dip);
00073       //else if (extra == "/") ghost ("end", dip);
00074       //if (extra != "") ghost ("{", dip);
00075       ghost (extra, dip);
00076       typeset_blue (t[0], descend (ip, 0));
00077       //if (extra != "") ghost ("}", nip);
00078       break;
00079     case STYLE_FUNCTIONAL:
00080       ghost (extra, dip);
00081       typeset_blue (t[0], descend (ip, 0));
00082       break;
00083     }
00084   }
00085 
00086   if (visual_close && (N(t) == 1))
00087     // No arguments or block arguments follow
00088     return;
00089 
00090   path dip = descend (descend (ip, 1), 0);
00091   if (N(t) == 1) dip= descend (descend (ip, 0), right_index (t[0]));
00092   if (visual_open) {
00093     if (env->src_style == STYLE_LATEX) ghost ("{", dip);
00094     else if (env->src_style == STYLE_FUNCTIONAL) {
00095       print (env->fn->spc / 2);
00096       ghost ("(", dip);
00097     }
00098     else typeset_src_middle (t, ip, 1);
00099   }
00100   else typeset_src_middle (t, ip, 1);
00101 }
00102 
00103 void
00104 concater_rep::typeset_src_middle (tree t, path ip, int i) {
00105   path pip= descend (descend (ip, i-1), right_index (t[i-1]));
00106   path dip= descend (descend (ip, i), 0);
00107   if (i == N(t)) dip= pip;
00108   switch (env->src_style) {
00109   case STYLE_ANGULAR:
00110     print (space (0, 0, env->fn->spc->max));
00111     ghost ("|", dip);
00112     penalty_min (0);
00113     print (space (0, 0, env->fn->spc->max));
00114     break;
00115   case STYLE_SCHEME:
00116     penalty_min (0);
00117     print (env->fn->spc);
00118     break;
00119   case STYLE_LATEX:
00120     if ((L(t) != INLINE_TAG) && (env->src_close == CLOSE_MINIMAL)) {
00121       ghost (",", dip);
00122       penalty_min (0);
00123       print (env->fn->spc / 2);
00124     }
00125     else {
00126       ghost ("}", pip);
00127       penalty_min (0);
00128       ghost ("{", dip);
00129     }
00130     break;
00131   case STYLE_FUNCTIONAL:
00132     ghost (",", dip);
00133     penalty_min (0);
00134     print (env->fn->spc / 2);
00135     break;
00136   }
00137 }
00138 
00139 void
00140 concater_rep::typeset_src_close (tree t, path ip) {
00141   path dip= descend (descend (ip, N(t)-1), right_index (t[N(t)-1]));
00142   switch (env->src_style) {
00143   case STYLE_ANGULAR:
00144     ghost (">", dip);
00145     break;
00146   case STYLE_SCHEME:
00147     ghost (")", dip);
00148     break;
00149   case STYLE_LATEX:
00150     ghost ("}", dip);
00151     break;
00152   case STYLE_FUNCTIONAL:
00153     ghost (")", dip);
00154     break;
00155   }
00156 }
00157 
00158 void
00159 concater_rep::typeset_src_args (tree t, path ip) {
00160   int i, n= N(t);
00161   for (i=1; i<n; i++) {
00162     if (i>1) typeset_src_middle (t, ip, i);
00163     typeset (t[i], descend (ip, i));
00164   }
00165 }
00166 
00167 void
00168 concater_rep::typeset_src_tag (tree t, path ip) {
00169   if (N(t) == 0) { typeset_error (t, ip); return; }
00170   int n= N(t);
00171   marker (descend (ip, 0));
00172   if ((L(t) == INLINE_TAG) || (env->src_close == CLOSE_REPEAT)) {
00173     string extra;
00174     if (L(t) == OPEN_TAG) extra= "\\";
00175     else if (L(t) == MIDDLE_TAG) extra= "|";
00176     else if (L(t) == CLOSE_TAG) extra= "/";
00177     typeset_src_open (t, ip, extra);
00178     typeset_src_args (t, ip);
00179     if ((n>1) ||
00180        (env->src_style == STYLE_ANGULAR) || (env->src_style == STYLE_SCHEME))
00181       typeset_src_close (t, ip);
00182   }
00183   else {
00184     typeset_src_open (t, ip, "");
00185     typeset_src_args (t, ip);
00186     if ((n>1) || (L(t) == CLOSE_TAG))
00187       if ((L(t) == MIDDLE_TAG) || (env->src_close != CLOSE_MINIMAL)) {
00188        if (L(t) == CLOSE_TAG) typeset_src_close (t, ip);
00189        else typeset_src_middle (t, ip, n);
00190       }
00191   }
00192   marker (descend (ip, 1));
00193 }
00194 
00195 /******************************************************************************
00196 * Inactive and erroneous markup
00197 ******************************************************************************/
00198 
00199 void
00200 concater_rep::typeset_inactive (tree t, path ip) {
00201   tree m (MACRO, "x", tree (REWRITE_INACTIVE, tree (ARG, "x"), "once"));
00202   typeset_auto (t, ip, m);
00203 }
00204 
00205 void
00206 concater_rep::typeset_error (tree t, path ip) {
00207   tree m (MACRO, "x", tree (REWRITE_INACTIVE, tree (ARG, "x"), "error"));
00208   marker (descend (ip, 0));
00209   typeset_auto (attach_right (t, ip), m);
00210   marker (descend (ip, 1));
00211 }