Back to index

texmacs  1.0.7.15
Functions | Variables
lazy_typeset.cpp File Reference
#include "Line/lazy_typeset.hpp"
#include "Line/lazy_vstream.hpp"
#include "Format/format.hpp"
#include "Stack/stacker.hpp"
#include "Boxes/construct.hpp"
#include "analyze.hpp"
#include "packrat.hpp"

Go to the source code of this file.

Functions

array< line_itemtypeset_marker (edit_env env, path ip)
array< line_itemtypeset_concat (edit_env, tree t, path ip)
array< line_itemjoin (array< line_item > a, array< line_item > b)
lazy make_lazy_paragraph (edit_env env, tree t, path ip)
lazy make_lazy_table (edit_env env, tree t, path ip)
lazy make_lazy_canvas (edit_env env, tree t, path ip)
lazy make_lazy_ornament (edit_env env, tree t, path ip)
lazy make_lazy_hidden (edit_env env, tree t, path ip)
lazy make_lazy_formatting (edit_env env, tree t, path ip, string v)
lazy make_lazy_with (edit_env env, tree t, path ip)
lazy make_lazy_compound (edit_env env, tree t, path ip)
lazy make_lazy_rewrite (edit_env env, tree t, path ip)
lazy make_lazy_eval (edit_env env, tree t, path ip)
lazy make_lazy_auto (edit_env env, tree t, path ip, tree f)
lazy make_lazy_argument (edit_env env, tree t, path ip)
lazy make_lazy_mark (edit_env env, tree t, path ip)
lazy make_lazy_expand_as (edit_env env, tree t, path ip)
lazy make_lazy_locus (edit_env env, tree t, path ip)
lazy make_lazy (edit_env env, tree t, path ip)

Variables

static tree inactive_m (MACRO,"x", tree(REWRITE_INACTIVE, tree(ARG,"x","0"),"once*"))
static tree var_inactive_m (MACRO,"x", tree(REWRITE_INACTIVE, tree(ARG,"x","0"),"recurse*"))

Function Documentation

Definition at line 525 of file lazy_paragraph.cpp.

                                              {
  int i, m= N(a), n= N(b);
  array<line_item> c (m+n);
  for (i=0; i<m; i++) c[i  ]= a[i];
  for (i=0; i<n; i++) c[i+m]= b[i];
  return c;
}

Here is the call graph for this function:

lazy make_lazy ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 478 of file lazy_typeset.cpp.

                                          {
  /*
  if (is_accessible (ip)) {
    if (obtain_ip (t) != ip)
      cout << "TeXmacs] Wrong ip: " << t << "\n";
  }
  */

  if (!is_accessible (ip)) {
    path ip2= obtain_ip (t);
    if (ip2 != path (DETACHED))
      ip= ip2;
  }

  if (env->hl_lan != 0)
    env->lan->highlight (t);

  switch (L(t)) {
  case DOCUMENT:
    return lazy_document (env, t, ip);
  case SURROUND:
    return lazy_surround (env, t, ip);
    //case HIDDEN:
    //return make_lazy_hidden (env, t, ip);
  case DATOMS:
    return make_lazy_formatting (env, t, ip, ATOM_DECORATIONS);
  case DLINES:
    return make_lazy_formatting (env, t, ip, LINE_DECORATIONS);
  case DPAGES:
    return make_lazy_formatting (env, t, ip, PAGE_DECORATIONS);
  case TFORMAT:
    return make_lazy_formatting (env, t, ip, CELL_FORMAT);
  case TABLE:
    return make_lazy_table (env, t, ip);
  case WITH:
    return make_lazy_with (env, t, ip);
  case ARG:
    return make_lazy_argument (env, t, ip);
  case MARK:
    return make_lazy_mark (env, t, ip);
  case EXPAND_AS:
    return make_lazy_expand_as (env, t, ip);
  case EVAL:
  case QUASI:
    return make_lazy_eval (env, t, ip);
  case COMPOUND:
    return make_lazy_compound (env, t, ip);
  case EXTERN:
    return make_lazy_rewrite (env, t, ip);
  case INCLUDE:
    return make_lazy_rewrite (env, t, ip);
  case STYLE_ONLY:
  case VAR_STYLE_ONLY:
  case ACTIVE:
  case VAR_ACTIVE:
    return make_lazy_compound (env, t, ip);
  case INACTIVE:
    return make_lazy_auto (env, t, ip, inactive_m);
  case VAR_INACTIVE:
    return make_lazy_auto (env, t, ip, var_inactive_m);
  case REWRITE_INACTIVE:
    return make_lazy_rewrite (env, t, ip);
  case LOCUS:
    return make_lazy_locus (env, t, ip);
  case HLINK:
  case ACTION:
    return make_lazy_compound (env, t, ip);
  case CANVAS:
    return make_lazy_canvas (env, t, ip);
  case ORNAMENT:
    return make_lazy_ornament (env, t, ip);
  default:
    if (L(t) < START_EXTENSIONS) return make_lazy_paragraph (env, t, ip);
    else return make_lazy_compound (env, t, ip);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_argument ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 341 of file lazy_typeset.cpp.

                                                   {
  string name;
  tree   value;
  path   valip= decorate_right (ip);

  tree r= t[0];
  if (is_compound (r)) value= tree (ERROR, "bad arg");
  else {
    name = r->label;
    if ((!is_nil (env->macro_arg)) && env->macro_arg->item->contains (r->label)) {
      value= env->macro_arg->item [name];
      if (!is_func (value, BACKUP)) {
       path new_valip= env->macro_src->item [name];
       if (is_accessible (new_valip)) valip= new_valip;
      }
    }
    else value= tree (ERROR, "arg " * name);
  }

  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  list<hashmap<string,tree> > old_var= env->macro_arg;
  list<hashmap<string,path> > old_src= env->macro_src;
  if (!is_nil (env->macro_arg)) env->macro_arg= env->macro_arg->next;
  if (!is_nil (env->macro_src)) env->macro_src= env->macro_src->next;

  if (N(t) > 1) {
    int i, n= N(t);
    for (i=1; i<n; i++) {
      tree r= env->exec (t[i]);
      if (!is_int (r)) {
        value= tree (ERROR, "arg " * name);
        valip= decorate_right (ip);
        break;
      }
      int nr= as_int (r);
      if ((!is_compound (value)) || (nr<0) || (nr>=N(value))) {
        value= tree (ERROR, "arg " * name);
        valip= decorate_right (ip);
        break;
      }
      value= value[nr];
      valip= descend (valip, nr);
    }
  }
  lazy par= make_lazy (env, attach_here (value, valip));

  env->macro_arg= old_var;
  env->macro_src= old_src;
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_auto ( edit_env  env,
tree  t,
path  ip,
tree  f 
)

Definition at line 312 of file lazy_typeset.cpp.

                                                       {
  array<line_item> a;
  array<line_item> b;
  if (!is_decoration (ip)) {
    a= typeset_marker (env, descend (ip, 0));
    b= typeset_marker (env, descend (ip, 1));
  }

  lazy par;
  env->macro_arg= list<hashmap<string,tree> > (
    hashmap<string,tree> (UNINIT), env->macro_arg);
  env->macro_src= list<hashmap<string,path> > (
    hashmap<string,path> (path (DECORATION)), env->macro_src);
  string var= f[0]->label;
  env->macro_arg->item (var)= t;
  env->macro_src->item (var)= ip;
  if (is_decoration (ip)) par= make_lazy (env, attach_here (f[1], ip));
  else par= make_lazy (env, attach_right (f[1], ip));
  env->macro_arg= env->macro_arg->next;
  env->macro_src= env->macro_src->next;

  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_canvas ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 134 of file lazy_gui.cpp.

                                                 {
  canvas_properties props= get_canvas_properties (env, t);
  lazy par= make_lazy (env, t[6], descend (ip, 6));
  return lazy_canvas (props, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_compound ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 222 of file lazy_typeset.cpp.

                                                   {
  int d; tree f;
  if (L(t) == COMPOUND) {
    d= 1;
    f= t[0];
    if (is_compound (f)) f= env->exec (f);
    if (is_atomic (f)) {
      string var= f->label;
      if (env->provides (var)) f= env->read (var);
      else f= tree (ERROR, "compound " * var);
    }
  }
  else {
    string var= as_string (L(t));
    if (env->provides (var)) f= env->read (var);
    else f= tree (ERROR, "compound " * var);
    d= 0;
  }

  array<line_item> a;
  array<line_item> b;
  if (/*NON_CHILD_ENFORCING(t)&&*/ (!is_decoration (ip))) {
    a= typeset_marker (env, descend (ip, 0));
    b= typeset_marker (env, descend (ip, 1));
  }
  lazy par;

  if (is_applicable (f)) {
    int i, n=N(f)-1, m=N(t)-d;
    env->macro_arg= list<hashmap<string,tree> > (
      hashmap<string,tree> (UNINIT), env->macro_arg);
    env->macro_src= list<hashmap<string,path> > (
      hashmap<string,path> (path (DECORATION)), env->macro_src);
    if (L(f) == XMACRO) {
      if (is_atomic (f[0])) {
       string var= f[0]->label;
       env->macro_arg->item (var)= t;
       env->macro_src->item (var)= ip;
      }
    }
    else for (i=0; i<n; i++)
      if (is_atomic (f[i])) {
       string var= f[i]->label;
       env->macro_arg->item (var)=
         i<m? t[i+d]: attach_dip (tree (UNINIT), decorate_right(ip));
       env->macro_src->item (var)= i<m? descend (ip,i+d): decorate_right(ip);
      }
    if (is_decoration (ip)) par= make_lazy (env, attach_here (f[n], ip));
    else par= make_lazy (env, attach_right (f[n], ip));
    env->macro_arg= env->macro_arg->next;
    env->macro_src= env->macro_src->next;
  }
  else {
    if (is_decoration (ip)) par= make_lazy (env, attach_here (f, ip));
    else par= make_lazy (env, attach_right (f, ip));
  }
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_eval ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 299 of file lazy_typeset.cpp.

                                               {
  tree r= env->exec (is_func (t, EVAL, 1)? t[0]: tree (QUASIQUOTE, t[0]));
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  lazy par= make_lazy (env, attach_right (r, ip));
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_expand_as ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 438 of file lazy_typeset.cpp.

                                                    {
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  lazy par= make_lazy (env, t[1], descend (ip, 1));
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_formatting ( edit_env  env,
tree  t,
path  ip,
string  v 
)

Definition at line 159 of file lazy_typeset.cpp.

                                                               {
  int last= N(t)-1;
  tree new_format= env->read (v) * t (0, last);
  tree old_format= env->local_begin (v, new_format);
  array<line_item> a;
  array<line_item> b;
  if (v != CELL_FORMAT) {
    a= typeset_marker (env, descend (ip, 0));
    b= typeset_marker (env, descend (ip, 1));
  }
  lazy par= make_lazy (env, t[last], descend (ip, last));
  env->local_end (v, old_format);
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_hidden ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 149 of file lazy_typeset.cpp.

                                                 {
  (void) make_lazy (env, t[0], descend (ip, 0));
  return lazy_document (env, tree (DOCUMENT), ip);
}

Here is the call graph for this function:

lazy make_lazy_locus ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 450 of file lazy_typeset.cpp.

                                                {
  extern bool build_locus (edit_env env, tree t, list<string>& ids, string& c);
  list<string> ids;
  string col;
  if (!build_locus (env, t, ids, col))
    system_warning ("Ignored unaccessible loci");
  int last= N(t)-1;
  tree old_col= env->read (COLOR);
  env->write_update (COLOR, col);
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  lazy par= make_lazy (env, t[last], descend (ip, last));
  env->write_update (COLOR, old_col);
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_mark ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 398 of file lazy_typeset.cpp.

                                               {
  // cout << "Lazy mark: " << t << ", " << ip << "\n";
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));

  if (is_func (t[0], ARG) &&
      is_atomic (t[0][0]) &&
      (!is_nil (env->macro_arg)) &&
      env->macro_arg->item->contains (t[0][0]->label))
    {
      string name = t[0][0]->label;
      tree   value= env->macro_arg->item [name];
      path   valip= decorate_right (ip);
      if (!is_func (value, BACKUP)) {
       path new_valip= env->macro_src->item [name];
       if (is_accessible (new_valip)) valip= new_valip;
      }

      if (N(t[0]) > 1) {
       int i, n= N(t[0]);
       for (i=1; i<n; i++) {
         tree r= env->exec (t[0][i]);
         if (!is_int (r)) break;
         int nr= as_int (r);
         if ((!is_compound (value)) || (nr<0) || (nr>=N(value))) break;
         value= value[nr];
         valip= descend (valip, nr);
       }
      }
      if (is_compound (value)) {
       a= typeset_marker (env, descend (valip, 0));
       b= typeset_marker (env, descend (valip, 1));
      }
    }

  lazy par= make_lazy (env, t[1], descend (ip, 1));
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_ornament ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 210 of file lazy_gui.cpp.

                                                   {
  SI    w     = env->get_length (ORNAMENT_BORDER);
  SI    xpad  = env->get_length (ORNAMENT_HPADDING);
  SI    ypad  = env->get_length (ORNAMENT_VPADDING);
  tree  bg    = env->read       (ORNAMENT_COLOR);
  int   a     = env->alpha;
  color sunny = env->get_color  (ORNAMENT_SUNNY_COLOR);
  color shadow= env->get_color  (ORNAMENT_SHADOW_COLOR);
  lazy  par   = make_lazy (env, t[0], descend (ip, 0));
  return lazy_ornament (env, par, ip, w, xpad, ypad, bg, a, sunny, shadow);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_paragraph ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 511 of file lazy_paragraph.cpp.

                                                    {
  lazy_paragraph par (env, ip);
  par->a= typeset_concat (env, t, ip);
  return par;
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_rewrite ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 286 of file lazy_typeset.cpp.

                                                  {
  tree r= env->rewrite (t);
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  lazy par= make_lazy (env, attach_right (r, ip));
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

lazy make_lazy_table ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 865 of file table.cpp.

                                                {
  table T (env);
  T->typeset (t, ip);
  T->handle_decorations ();
  T->handle_span ();
  T->merge_borders (); // FIXME: introduce merge_border variables
  return lazy_table (T, ip);
}

Here is the caller graph for this function:

lazy make_lazy_with ( edit_env  env,
tree  t,
path  ip 
)

Definition at line 179 of file lazy_typeset.cpp.

                                               {
  int last= N(t)-1;
  int i, k= last>>1; // is k=0 allowed ?
  // if ((last&1) != 0) return;
  
  STACK_NEW_ARRAY(vars,string,k);
  STACK_NEW_ARRAY(oldv,tree,k);
  STACK_NEW_ARRAY(newv,tree,k);
  for (i=0; i<k; i++) {
    tree var_t= env->exec (t[i<<1]);
    if (is_atomic (var_t)) {
      string var= var_t->label;
      vars[i]= var;
      oldv[i]= env->read (var);
      newv[i]= env->exec (t[(i<<1)+1]);
    }
    /*
    else {
      STACK_DELETE_ARRAY(vars);
      STACK_DELETE_ARRAY(oldv);
      STACK_DELETE_ARRAY(newv);
      return;
    }
    */
  }

  // for (i=0; i<k; i++) env->monitored_write_update (vars[i], newv[i]);
  for (i=0; i<k; i++) env->write_update (vars[i], newv[i]);
  array<line_item> a= typeset_marker (env, descend (ip, 0));
  array<line_item> b= typeset_marker (env, descend (ip, 1));
  lazy par= make_lazy (env, t[last], descend (ip, last));
  for (i=k-1; i>=0; i--) env->write_update (vars[i], oldv[i]);
  STACK_DELETE_ARRAY(vars);
  STACK_DELETE_ARRAY(oldv);
  STACK_DELETE_ARRAY(newv);
  return lazy_surround (a, b, par, ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 742 of file concater.cpp.

                                               {
  concater ccc= tm_new<concater_rep> (env);
  ccc->typeset (t, ip);
  ccc->finish ();
  array<line_item> a= ccc->a;
  tm_delete (ccc);
  return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 752 of file concater.cpp.

                                       {
  concater ccc= tm_new<concater_rep> (env);
  ccc->marker (ip);
  array<line_item> a= ccc->a;
  tm_delete (ccc);
  return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tree inactive_m(MACRO,"x", tree(REWRITE_INACTIVE, tree(ARG,"x","0"),"once*")) [static]
tree var_inactive_m(MACRO,"x", tree(REWRITE_INACTIVE, tree(ARG,"x","0"),"recurse*")) [static]