Back to index

texmacs  1.0.7.15
Functions | Variables
tree_traverse.cpp File Reference
#include "tree_traverse.hpp"
#include "drd_std.hpp"
#include "analyze.hpp"
#include "hashset.hpp"
#include "scheme.hpp"

Go to the source code of this file.

Functions

int minimal_arity (tree t)
int maximal_arity (tree t)
bool correct_arity (tree t, int n)
int insert_point (tree t, int i)
bool is_dynamic (tree t)
bool is_accessible_child (tree t, int i)
array< treeaccessible_children (tree t)
bool all_accessible (tree t)
bool none_accessible (tree t)
string get_name (tree t)
string get_long_name (tree t)
string get_child_name (tree t, int i)
string get_child_long_name (tree t, int i)
string get_child_type (tree t, int i)
tree get_env_child (tree t, int i, string var, tree val)
static path move_any (tree t, path p, bool forward)
path next_any (tree t, path p)
path previous_any (tree t, path p)
static path move_valid (tree t, path p, bool forward)
path next_valid (tree t, path p)
path previous_valid (tree t, path p)
static path move_accessible (tree t, path p, bool forward)
path next_accessible (tree t, path p)
path previous_accessible (tree t, path p)
static bool is_iso_alphanum (char c)
static bool at_border (tree t, path p, bool forward)
static bool next_is_word (tree t, path p)
static path move_word (tree t, path p, bool forward)
path next_word (tree t, path p)
path previous_word (tree t, path p)
static path move_node (tree t, path p, bool forward)
path next_node (tree t, path p)
path previous_node (tree t, path p)
static int tag_border (tree t, path p)
static bool distinct_tag_or_argument (tree t, path p, path q, hashset< int > labs)
static bool acceptable_border (tree t, path p, path q, hashset< int > labs)
static int tag_index (tree t, path p, hashset< int > labs)
static path move_tag (tree t, path p, hashset< int > labs, bool forward, bool preserve)
static hashset< int > get_labels (scheme_tree t)
path next_tag (tree t, path p, scheme_tree which)
path previous_tag (tree t, path p, scheme_tree which)
path next_tag_same_argument (tree t, path p, scheme_tree which)
path previous_tag_same_argument (tree t, path p, scheme_tree which)
static path move_argument (tree t, path p, bool forward)
path next_argument (tree t, path p)
path previous_argument (tree t, path p)
static path search_upwards (tree t, path p, tree_label which)
bool inside_same (tree t, path p, path q, tree_label which)
bool more_inside (tree t, path p, path q, tree_label which)
void init_sections ()
path previous_section_impl (tree t, path p)
path previous_section (tree t, path p)
void search_sections (array< tree > &a, tree t)
array< treesearch_sections (tree t)

Variables

hashset< tree_labelsection_traverse_tags
hashset< tree_labelsection_tags

Function Documentation

static bool acceptable_border ( tree  t,
path  p,
path  q,
hashset< int >  labs 
) [static]

Definition at line 322 of file tree_traverse.cpp.

                                                              {
  if (tag_border (t, q) == 0) return true;
  if (!labs->contains ((int) L (subtree (t, path_up (q))))) return true;
  if (tag_border (t, q) < 0) return false;
  return tag_border (t, p) != 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 53 of file tree_traverse.cpp.

                             {
  array<tree> a;
  int i, n= N(t);
  for (i=0; i<n; i++)
    if (the_drd->is_accessible_child (t, i))
      a << t[i];
  return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool all_accessible ( tree  t)

Definition at line 63 of file tree_traverse.cpp.

                        {
  if (is_atomic (t)) return false;
  return the_drd->all_accessible (L(t));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool at_border ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 220 of file tree_traverse.cpp.

                                         {
  tree st= subtree (t, path_up (p));
  int l= last_item (p), n= N(st);
  if (!is_concat (st) && !is_document (st)) return true;
  if ((forward && l!=n-1) || (!forward && l!=0)) return false;
  return at_border (t, path_up (p), forward);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool correct_arity ( tree  t,
int  n 
)

Definition at line 33 of file tree_traverse.cpp.

                              {
  return the_drd->correct_arity (L(t), n);
}

Here is the caller graph for this function:

static bool distinct_tag_or_argument ( tree  t,
path  p,
path  q,
hashset< int >  labs 
) [static]

Definition at line 309 of file tree_traverse.cpp.

                                                                     {
  path c= common (p, q);
  path r= path_up (q);
  if (labs->contains ((int) L (subtree (t, r))) && tag_border (t, q) != 0)
    return true;
  while (!is_nil (r) && (r != c)) {
    r= path_up (r);
    if (labs->contains ((int) L (subtree (t, r)))) return true;
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string get_child_long_name ( tree  t,
int  i 
)

Definition at line 94 of file tree_traverse.cpp.

                                    {
  return the_drd->get_child_long_name (t, i);
}

Here is the caller graph for this function:

string get_child_name ( tree  t,
int  i 
)

Definition at line 89 of file tree_traverse.cpp.

                               {
  return the_drd->get_child_name (t, i);
}

Here is the caller graph for this function:

string get_child_type ( tree  t,
int  i 
)

Definition at line 99 of file tree_traverse.cpp.

                               {
  return drd_decode_type (the_drd->get_type_child (t, i));
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree get_env_child ( tree  t,
int  i,
string  var,
tree  val 
)

Definition at line 104 of file tree_traverse.cpp.

                                                    {
  return the_drd->get_env_child (t, i, var, val);
}

Here is the caller graph for this function:

static hashset<int> get_labels ( scheme_tree  t) [static]

Definition at line 355 of file tree_traverse.cpp.

                           {
  hashset<int> labs;
  if (is_atomic (t))
    labs->insert ((int) as_tree_label (t->label));
  else {
    int i, n= N(t);
    for (i=0; i<n; i++)
      if (is_atomic (t[i]))
       labs->insert ((int) as_tree_label (t[i]->label));
  }
  return labs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 84 of file tree_traverse.cpp.

                       {
  return the_drd->get_long_name (L(t));
}

Here is the caller graph for this function:

Definition at line 79 of file tree_traverse.cpp.

                  {
  return the_drd->get_name (L(t));
}

Here is the caller graph for this function:

void init_sections ( )

Definition at line 438 of file tree_traverse.cpp.

                 {
  if (N(section_traverse_tags) == 0) {
    section_traverse_tags= hashset<tree_label> ();
    section_traverse_tags->insert (DOCUMENT);
    section_traverse_tags->insert (CONCAT);
    section_traverse_tags->insert (as_tree_label ("ignore"));
    section_traverse_tags->insert (as_tree_label ("show-part"));
    section_traverse_tags->insert (as_tree_label ("hide-part"));
  }
  if (N(section_tags) == 0) {
    eval ("(use-modules (text std-text-drd))");
    object l= eval ("(append (section-tag-list) (section*-tag-list))");
    while (!is_null (l)) {
      section_tags->insert (as_tree_label (as_symbol (car (l))));
      l= cdr (l);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int insert_point ( tree  t,
int  i 
)

Definition at line 38 of file tree_traverse.cpp.

                             {
  return the_drd->insert_point (L(t), i, N(t));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool inside_same ( tree  t,
path  p,
path  q,
tree_label  which 
)

Definition at line 417 of file tree_traverse.cpp.

                                                       {
  return
    search_upwards (t, path_up (p), which) ==
    search_upwards (t, path_up (q), which);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_accessible_child ( tree  t,
int  i 
)

Definition at line 48 of file tree_traverse.cpp.

                                    {
  return the_drd->is_accessible_child (t, i);
}

Here is the caller graph for this function:

bool is_dynamic ( tree  t)

Definition at line 43 of file tree_traverse.cpp.

                    {
  return the_drd->is_dynamic (t, false);
}

Here is the caller graph for this function:

static bool is_iso_alphanum ( char  c) [inline, static]

Definition at line 215 of file tree_traverse.cpp.

                         {
  return is_iso_alpha (c) || is_digit (c);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maximal_arity ( tree  t)

Definition at line 28 of file tree_traverse.cpp.

                       {
  return the_drd->get_maximal_arity (L(t));
}

Here is the caller graph for this function:

int minimal_arity ( tree  t)

Definition at line 23 of file tree_traverse.cpp.

                       {
  return the_drd->get_minimal_arity (L(t));
}
bool more_inside ( tree  t,
path  p,
path  q,
tree_label  which 
)

Definition at line 424 of file tree_traverse.cpp.

                                                       {
  return
    search_upwards (t, path_up (q), which) <=
    search_upwards (t, path_up (p), which);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_accessible ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 194 of file tree_traverse.cpp.

                                               {
  ASSERT (is_inside (t, p), "invalid cursor");
  path q= p;
  while (true) {
    path r= move_any (t, q, forward);
    if (r == q) return p;
    if (is_accessible_cursor (t, r)) return r;
    q= r;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_any ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 113 of file tree_traverse.cpp.

                                        {
  path q = path_up (p);
  int  l = last_item (p);
  tree st= subtree (t, q);
  if (is_atomic (st)) {
    string s= st->label;
    ASSERT (l >= 0 && l <= N(s), "out of range");
    if (forward) {
      if (l<N(s)) {
       tm_char_forwards (s, l);
       return q * l;
      }
    }
    else {
      if (l>0) {
       tm_char_backwards (s, l);
       return q * l;
      }
    }
  }
  else if ((forward && l==0) || (!forward && l==1)) {
    int i, n= N(st);
    if (forward) {
      for (i=0; i<n; i++)
       if (the_drd->is_accessible_child (st, i))
         return q * path (i, 0);
    }
    else {
      for (i=n-1; i>=0; i--)
       if (the_drd->is_accessible_child (st, i))
         return q * path (i, right_index (st[i]));
    }
    return q * (1-l);
  }
  else if (is_nil (q)) return p;

  l = last_item (q);
  q = path_up (q);
  st= subtree (t, q);
  int i, n= N(st);
  if (forward) {
    for (i=l+1; i<n; i++)
      if (the_drd->is_accessible_child (st, i))
       return q * path (i, 0);
  }
  else {
    for (i=l-1; i>=0; i--)
      if (the_drd->is_accessible_child (st, i)) {
       return q * path (i, right_index (st[i]));
    }
  }
  return q * (forward? 1: 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_argument ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 383 of file tree_traverse.cpp.

                                             {
  path q = path_up (p);
  int  l = last_item (p);
  tree st= subtree (t, q);
  int i, n= N(st);
  if (forward) {
    for (i=l+1; i<n; i++)
      if (the_drd->is_accessible_child (st, i))
       return start (t, q * i);
  }
  else {
    for (i=l-1; i>=0; i--)
      if (the_drd->is_accessible_child (st, i))
       return end (t, q * i);
  }
  return path ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_node ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 281 of file tree_traverse.cpp.

                                         {
  tree st= subtree (t, path_up (p));
  if (is_atomic (st)) {
    if (forward) p= path_up (p) * N (st->label);
    else p= path_up (p) * 0;
  }
  return move_valid (t, p, forward);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_tag ( tree  t,
path  p,
hashset< int >  labs,
bool  forward,
bool  preserve 
) [static]

Definition at line 341 of file tree_traverse.cpp.

                                                                          {
  path q= p;
  while (true) {
    path r= move_node (t, q, forward);
    if (r == q) return p;
    if (distinct_tag_or_argument (t, p, r, labs) &&
        acceptable_border (t, p, r, labs) &&
       (!preserve || tag_index (t, r, labs) == tag_index (t, p, labs)))
      return r;
    q= r;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_valid ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 177 of file tree_traverse.cpp.

                                          {
  ASSERT (is_inside (t, p), "invalid cursor");
  path q= p;
  while (true) {
    path r= move_any (t, q, forward);
    if (r == q) return p;
    if (valid_cursor (t, r)) return r;
    q= r;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static path move_word ( tree  t,
path  p,
bool  forward 
) [static]

Definition at line 238 of file tree_traverse.cpp.

                                         {
  while (true) {
    path q= move_valid (t, p, forward);
    int l= last_item (q);
    if (q == p) return p;
    tree st= subtree (t, path_up (q));
    if (is_atomic (st)) {
      string s= st->label;
      int n= N(s);
      if (s == "") return q;
      if (forward && l>0 &&
         (is_iso_alphanum (s[l-1]) ||
          (l==n && at_border (t, path_up (q), forward))) &&
         (l==n || !is_iso_alphanum (s[l])))
       return q;
      if (!forward && l<n &&
         (is_iso_alphanum (s[l]) ||
          (l==0 && at_border (t, path_up (q), forward))) &&
         (l==0 || !is_iso_alphanum (s[l-1])))
       return q;
      if (!forward && l==n && next_is_word (t, path_up (q)))
       return q;
    }
    else {
      if (forward && l==1) return q;
      if (!forward && l==0) return q;
      if (!forward && next_is_word (t, path_up (q)))
       return q;
    }
    p= q;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

path next_accessible ( tree  t,
path  p 
)

Definition at line 205 of file tree_traverse.cpp.

                                      {
  return move_accessible (t, p, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

path next_any ( tree  t,
path  p 
)

Definition at line 167 of file tree_traverse.cpp.

                               {
  return move_any (t, p, true); }

Here is the call graph for this function:

path next_argument ( tree  t,
path  p 
)

Definition at line 401 of file tree_traverse.cpp.

                                    {
  return move_argument (t, p, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool next_is_word ( tree  t,
path  p 
) [static]

Definition at line 229 of file tree_traverse.cpp.

                              {
  tree st= subtree (t, path_up (p));
  int l= last_item (p), n= N(st);
  if (!is_concat (st) || l+1 >= n) return false;
  if (is_compound (st[l+1])) return true;
  return st[l+1] != "" && is_iso_alphanum (st[l+1]->label[0]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

path next_node ( tree  t,
path  p 
)

Definition at line 290 of file tree_traverse.cpp.

                                {
  return move_node (t, p, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

path next_tag ( tree  t,
path  p,
scheme_tree  which 
)

Definition at line 368 of file tree_traverse.cpp.

                                                  {
  return move_tag (t, p, get_labels (which), true, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

path next_tag_same_argument ( tree  t,
path  p,
scheme_tree  which 
)

Definition at line 373 of file tree_traverse.cpp.

                                                                {
  return move_tag (t, p, get_labels (which), true, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

path next_valid ( tree  t,
path  p 
)

Definition at line 188 of file tree_traverse.cpp.

                                 {
  return move_valid (t, p, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

path next_word ( tree  t,
path  p 
)

Definition at line 271 of file tree_traverse.cpp.

                                {
  return move_word (t, p, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool none_accessible ( tree  t)

Definition at line 69 of file tree_traverse.cpp.

                         {
  if (is_atomic (t)) return false;
  return the_drd->none_accessible (L(t));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 207 of file tree_traverse.cpp.

                                          {
  return move_accessible (t, p, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_any ( tree  t,
path  p 
)

Definition at line 169 of file tree_traverse.cpp.

                                   {
  return move_any (t, p, false); }

Here is the call graph for this function:

path previous_argument ( tree  t,
path  p 
)

Definition at line 403 of file tree_traverse.cpp.

                                        {
  return move_argument (t, p, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_node ( tree  t,
path  p 
)

Definition at line 292 of file tree_traverse.cpp.

                                    {
  return move_node (t, p, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_section ( tree  t,
path  p 
)

Definition at line 479 of file tree_traverse.cpp.

                                  {
  init_sections ();
  path r= previous_section_impl (t, p);
  if (is_nil (r)) return p;
  return path_up (r);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 458 of file tree_traverse.cpp.

                                       {
  if (is_atomic (t)) return path ();
  else if (N(t) == 1 && section_tags->contains (L(t)))
    return p * 0;
  else if (section_traverse_tags->contains (L(t))) {
    int i= is_nil (p)? N(t)-1: p->item;
    for (; i>=0; i--) {
      if (!is_nil (p) && i == p->item) {
       path r= previous_section_impl (t[i], p->next);
       if (!is_nil (r)) return path (i, r);
      }
      else {
       path r= previous_section_impl (t[i], path ());
       if (!is_nil (r)) return path (i, r);
      }
    }
  }
  return path ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_tag ( tree  t,
path  p,
scheme_tree  which 
)

Definition at line 370 of file tree_traverse.cpp.

                                                      {
  return move_tag (t, p, get_labels (which), false, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 375 of file tree_traverse.cpp.

                                                                    {
  return move_tag (t, p, get_labels (which), false, true); }

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_valid ( tree  t,
path  p 
)

Definition at line 190 of file tree_traverse.cpp.

                                     {
  return move_valid (t, p, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

path previous_word ( tree  t,
path  p 
)

Definition at line 273 of file tree_traverse.cpp.

                                    {
  return move_word (t, p, false); }

Here is the call graph for this function:

Here is the caller graph for this function:

void search_sections ( array< tree > &  a,
tree  t 
)

Definition at line 487 of file tree_traverse.cpp.

                                         {
  if (is_atomic (t)) return;
  else if (N(t) == 1 && section_tags->contains (L(t))) a << t;
  else if (section_traverse_tags->contains (L(t)))
    for (int i=0; i<N(t); i++)
      search_sections (a, t[i]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 496 of file tree_traverse.cpp.

                         {
  init_sections ();
  array<tree> a;
  search_sections (a, t);
  return a;
}

Here is the call graph for this function:

static path search_upwards ( tree  t,
path  p,
tree_label  which 
) [static]

Definition at line 411 of file tree_traverse.cpp.

                                                  {
  if (is_nil (p) || L (subtree (t, p)) == which) return p;
  else return search_upwards (t, path_up (p), which);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int tag_border ( tree  t,
path  p 
) [static]

Definition at line 300 of file tree_traverse.cpp.

                            {
  if (none_accessible (subtree (t, path_up (p)))) {
    if (last_item (p) == 0) return -1;
    if (last_item (p) == 1) return 1;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int tag_index ( tree  t,
path  p,
hashset< int >  labs 
) [static]

Definition at line 330 of file tree_traverse.cpp.

                                              {
  p= path_up (p);
  while (!is_nil (p)) {
    if (labs->contains ((int) L (subtree (t, path_up (p)))))
      return last_item (p);
    else p= path_up (p);
  }
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 435 of file tree_traverse.cpp.

Definition at line 434 of file tree_traverse.cpp.