Back to index

texmacs  1.0.7.15
Functions
packrat.hpp File Reference
#include "tree.hpp"
#include "scheme.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void packrat_define (string lan, string s, tree t)
void packrat_property (string lan, string s, string var, string val)
void packrat_inherit (string lan, string from)
int packrat_abbreviation (string lan, string s)
path packrat_parse (string lan, string s, tree in)
bool packrat_correct (string lan, string s, tree in)
bool packrat_available_path (string lan, tree in, path in_p)
object packrat_context (string lan, string s, tree in, path in_pos)
bool packrat_select (string lan, string s, tree in, path in_pos, path &p1, path &p2, int mode)
int encode_color (string s)
string decode_color (int c)
void packrat_highlight (string lan, string s, tree t)

Function Documentation

string decode_color ( int  c)

Definition at line 155 of file packrat_grammar.cpp.

                     {
  if (N(color_decoding) == 0) initialize_color_decodings ();
  if (color_decoding->contains (c)) return color_decoding[c];
  else return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

int encode_color ( string  s)

Definition at line 148 of file packrat_grammar.cpp.

                        {
  if (N(color_encoding) == 0) initialize_color_encodings ();
  if (color_encoding->contains (s)) return color_encoding[s];
  else return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int packrat_abbreviation ( string  lan,
string  s 
)

Definition at line 486 of file packrat_grammar.cpp.

                                            {
  static int nr= 1;
  static hashmap<string,int> abbrs (-1);
  string key= lan * ":" * s;
  int r= abbrs[key];
  if (r >= 0) return r;
  packrat_grammar gr= find_packrat_grammar (lan);
  C sym= encode_symbol (compound ("symbol", s));
  if (gr->grammar->contains (sym)) r= nr++;
  else r= 0;
  abbrs (key)= r;
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool packrat_available_path ( string  lan,
tree  in,
path  in_p 
)

Definition at line 739 of file packrat_parser.cpp.

                                                        {
  packrat_parser par= make_packrat_parser (lan, in);
  return par->current_start->contains (in_p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

object packrat_context ( string  lan,
string  s,
tree  in,
path  in_pos 
)

Definition at line 745 of file packrat_parser.cpp.

                                                             {
  //cout << "Context " << in << " at " << in_pos
  //     << " (" << lan << ", " << s << ")" << LF;
  packrat_parser par= make_packrat_parser (lan, in);
  C sym= encode_symbol (compound ("symbol", s));
  if (par->parse (sym, 0) != N(par->current_input))
    par= make_packrat_parser (lan, in, in_pos);
  C pos= par->encode_tree_position (in_pos);
  if (pos == PACKRAT_FAILED) return object (false);
  array<C> kind, begin, end;
  par->context (sym, 0, pos-1, pos+1, 0, kind, begin, end);
  par->compress (kind, begin, end);
  object ret= null_object ();
  for (int i=0; i<N(kind); i++) {
    object x1 (symbol_object (packrat_decode[kind[i]][0]->label));
    object x2 (par->decode_tree_position (begin[i]));
    object x3 (par->decode_tree_position (end[i]));
    ret= cons (list_object (x1, x2, x3), ret);
  }
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool packrat_correct ( string  lan,
string  s,
tree  in 
)

Definition at line 732 of file packrat_parser.cpp.

                                                  {
  packrat_parser par= make_packrat_parser (lan, in);
  C pos= par->parse (encode_symbol (compound ("symbol", sym)), 0);
  return pos == N(par->current_input);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void packrat_define ( string  lan,
string  s,
tree  t 
)

Definition at line 454 of file packrat_grammar.cpp.

                                              {
  packrat_grammar gr= find_packrat_grammar (lan);
  gr->define (s, t);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void packrat_highlight ( string  lan,
string  s,
tree  t 
)

Definition at line 824 of file packrat_parser.cpp.

                                                  {
  int hl_lan= packrat_abbreviation (lan, s);
  if (hl_lan == 0) return;
  //cout << "Highlight " << in << "\n";
  if (is_func (in, DOCUMENT)) {
    int i, begin, end;
    for (begin=0; begin<N(in); begin++)
      if (!has_highlight (in[begin], hl_lan))
       break;
    for (end=N(in)-1; end>begin; end--)
      if (!has_highlight (in[end-1], hl_lan))
       break;
    consistent_enlargement (in, begin, end);    
    for (i=begin; i<end; i++)
      detach_highlight (in[i], hl_lan);
    attach_highlight (in, hl_lan);
    packrat_highlight_subtree (lan, s, in (begin, end));
  }
  else {
    if (is_compound (in))
      for (int i=0; i<N(in); i++)
       detach_highlight (in[i], hl_lan);
    attach_highlight (in, hl_lan);
    packrat_highlight_subtree (lan, s, in);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void packrat_inherit ( string  lan,
string  from 
)

Definition at line 466 of file packrat_grammar.cpp.

                                          {
  packrat_grammar gr = find_packrat_grammar (lan);
  packrat_grammar inh= find_packrat_grammar (from);
  iterator<C>     it = iterate (inh->grammar);
  while (it->busy ()) {
    C sym= it->next ();
    //cout << "Inherit " << sym << " -> " << inh->grammar (sym) << LF;
    gr->grammar (sym)= inh->grammar (sym);
    gr->productions (sym)= inh->productions (sym);
  }

  iterator<D> it2 = iterate (inh->properties);
  while (it2->busy ()) {
    D p= it2->next ();
    //cout << "Inherit " << p << " -> " << inh->properties (p) << LF;
    gr->properties (p)= inh->properties (p);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

path packrat_parse ( string  lan,
string  s,
tree  in 
)

Definition at line 725 of file packrat_parser.cpp.

                                                {
  packrat_parser par= make_packrat_parser (lan, in);
  C pos= par->parse (encode_symbol (compound ("symbol", sym)), 0);
  return par->decode_tree_position (pos);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void packrat_property ( string  lan,
string  s,
string  var,
string  val 
)

Definition at line 460 of file packrat_grammar.cpp.

                                                                {
  packrat_grammar gr= find_packrat_grammar (lan);
  gr->set_property (s, var, val);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool packrat_select ( string  lan,
string  s,
tree  in,
path  in_pos,
path p1,
path p2,
int  mode 
)

Definition at line 768 of file packrat_parser.cpp.

{
  // mode= 0: genuine semantic selection
  // mode= 1: strictly larger selection for select_enlarge
  // mode= 2: determine environment rectangles
  if (path_less (p2, p1))
    return packrat_select (lan, s, in, in_pos, p2, p1, mode);
  //cout << "Enlarge " << p1 << " -- " << p2 << " in " << in
  //<< " (" << lan << ", " << s << ")" << LF;
  packrat_parser par= make_packrat_parser (lan, in);
  C sym = encode_symbol (compound ("symbol", s));
  if (par->parse (sym, 0) != N(par->current_input))
    par= make_packrat_parser (lan, in, in_pos);
  C pos1= par->encode_tree_position (p1);
  C pos2= par->encode_tree_position (p2);
  //cout << "Encoded " << pos1 << " -- " << pos2
  //     << " in " << par->current_string << LF;
  if (par->parse (sym, 0) != N(par->current_input)) return false;
  if (pos1 == PACKRAT_FAILED || pos2 == PACKRAT_FAILED) return false;
  array<C> kind, begin, end;
  C pos0= pos1;
  if ((mode == 1 && pos1 == pos2) || mode == 2) pos0= max (pos1 - 1, 0);
  par->context (sym, 0, pos0, pos2, mode, kind, begin, end);
  //for (int i=0; i<N(kind); i++)
  //  cout << i << ":\t"
  //       << par->decode_tree_position (begin[i]) << "\t"
  //       << par->decode_tree_position (end[i]) << "\t"
  //       << packrat_decode[kind[i]] << LF;
  par->compress (kind, begin, end);
  int n= N(kind);
  if (n == 0) return false;
  if (mode == 1) {
    if (pos1 == begin[n-1] && pos2 == end[n-1]) n--;
    if (n == 0) return false;
  }
  p1= par->decode_tree_position (begin[n-1]);
  p2= par->decode_tree_position (end[n-1]);
  //cout << "Selected " << packrat_decode[kind[n-1]] << LF;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function: