Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
tm_reader Struct Reference
Collaboration diagram for tm_reader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tm_reader (string buf2)
 tm_reader (string buf2, string version2)
int skip_blank ()
string decode (string s)
string read_char ()
string read_next ()
string read_function_name ()
tree read_apply (string s, bool skip_flag)
tree read (bool skip_flag)

Public Attributes

string version
hashmap< string, int > codes
tree_label EXPAND_APPLY
bool backslash_ok
bool with_extensions
string buf
int pos
string last

Detailed Description

Definition at line 22 of file fromtm.cpp.


Constructor & Destructor Documentation

tm_reader::tm_reader ( string  buf2) [inline]

Definition at line 32 of file fromtm.cpp.

                         :
    version (TEXMACS_VERSION),
    codes (STD_CODE),
    EXPAND_APPLY (EXPAND),
    backslash_ok (true),
    with_extensions (true),
    buf (buf2), pos (0), last ("") {}
tm_reader::tm_reader ( string  buf2,
string  version2 
) [inline]

Definition at line 39 of file fromtm.cpp.

                                          :
    version (version2),
    codes (get_codes (version)),
    EXPAND_APPLY (version_inf (version, "0.3.3.22")? APPLY: EXPAND),
    backslash_ok (version_inf (version, "1.0.1.23")? false: true),
    with_extensions (version_inf (version, "1.0.2.4")? false: true),
    buf (buf2), pos (0), last ("") {}

Member Function Documentation

Definition at line 70 of file fromtm.cpp.

                           {
  int i, n=N(s);
  string r;
  for (i=0; i<n; i++)
    if (((i+1)<n) && (s[i]=='\\')) {
      i++;
      if (s[i] == ';');
      else if (s[i] == '0') r << '\0';
      else if (s[i] == 't') r << '\t';
      else if (s[i] == 'r') r << '\r';
      else if (s[i] == 'n') r << '\n';
      else if (s[i] == '\\') r << '\\';
      else if ((s[i] >= '@') && (s[i] < '`')) r << (s[i] - '@');
      else r << s[i];
    }
    else r << s[i];
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree tm_reader::read ( bool  skip_flag)

Definition at line 239 of file fromtm.cpp.

                               {
  tree   D (DOCUMENT);
  tree   C (CONCAT);
  string S ("");
  bool   spc_flag= false;
  bool   ret_flag= false;

  while (true) {
    last= read_next ();
    // cout << "--> " << last << "\n";
    if (last == "") break;
    if (last == "|") break;
    if (last == ">") break;
    
    if (last[0] == '<') {
      if (last[N(last)-1] == '\\') {
       flush (D, C, S, spc_flag, ret_flag);
       string name= read_function_name ();
       if (last == ">") last= "\\>";
       else last= "\\|";
       C << read_apply (name, true);
      }
      else if (last[N(last)-1] == '|') {
       (void) read_function_name ();
       if (last == ">") last= "|>";
       else last= "||";
       break;
      }
      else if (last[N(last)-1] == '/') {
       (void) read_function_name ();
       if (last == ">") last= "/>";
       else last= "/|";
       break;
      }
      else if (last[N(last)-1] == '#') {
       string r;
       while ((buf[pos] != '>') && (pos+2<N(buf))) {
         r << ((char) from_hexadecimal (buf (pos, pos+2)));
         pos += 2;
       }
       if (buf[pos] == '>') pos++;
       flush (D, C, S, spc_flag, ret_flag);
       C << tree (RAW_DATA, r);
       last= read_next ();
       break;
      }
      else {
       flush (D, C, S, spc_flag, ret_flag);
       string name= decode (read_next ());
       string sep = ">";
       if (name == ">") name= "";
       else sep = read_next ();
       // cout << "==> " << name << "\n";
       // cout << "~~> " << sep << "\n";
       if (sep == '|') {
         last= "|";
         C << read_apply (name, false);
       }
       else {
         tree t (make_tree_label (name));
         if (!with_extensions)
           t= tree (EXPAND_APPLY, name);
         if (codes->contains (name)) {
           // cout << name << " -> " << as_string ((tree_label) codes [name]) << "\n";
           t= tree ((tree_label) codes [name]);
         }
         C << t;
       }
      }
    }
    else if (last == " ") spc_flag= true;
    else if (last == "\n") ret_flag= true;
    else {
      flush (D, C, S, spc_flag, ret_flag);
      // cout << "<<< " << last << "\n";
      // cout << ">>> " << decode (last) << "\n";
      S << decode (last);
      if ((S == "") && (N(C) == 0)) C << "";
    }
  }

  if (skip_flag) spc_flag= ret_flag= false;
  flush (D, C, S, spc_flag, ret_flag);
  if (N(C) == 1) D << C[0];
  else if (N(C)>1) D << C;
  // cout << "*** " << D << "\n";
  if (N(D)==0) return "";
  if (N(D)==1) {
    if (!skip_flag) return D[0];
    if (version_inf_eq (version, "0.3.4.10")) return D[0];
    if (is_func (D[0], COLLECTION)) return D[0];
  }
  return D;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree tm_reader::read_apply ( string  s,
bool  skip_flag 
)

Definition at line 189 of file fromtm.cpp.

                                                  {
  // cout << "Read apply " << name << INDENT << LF;
  tree t (make_tree_label (name));
  if (!with_extensions)
    t= tree (EXPAND_APPLY, name);
  if (codes->contains (name)) {
    // cout << "  " << name << " -> " << as_string ((tree_label) codes [name]) << "\n";
    t= tree ((tree_label) codes [name]);
  }

  bool closed= !skip_flag;
  while (pos < N(buf)) {
    // cout << "last= " << last << LF;
    bool sub_flag= (skip_flag) && ((last == "") || (last[N(last)-1] != '|'));
    if (sub_flag) (void) skip_blank ();
    t << read (sub_flag);
    if ((last == "/>") || (last == "/|")) closed= true;
    if (closed && ((last == ">") || (last == "/>"))) break;
  }
  // cout << "last= " << last << UNINDENT << LF;
  // cout << "Done" << LF;

  if (is_func (t, COLLECTION)) {
    tree u (COLLECTION);
    get_collection (u, t);
    return u;
  }
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 90 of file fromtm.cpp.

                      {
  while (((pos+1) < N(buf)) && (buf[pos] == '\\') && (buf[pos+1] == '\n')) {
    pos += 2;
    skip_spaces (buf, pos);
  }
  if (pos >= N(buf)) return "";
  pos++;
  return buf (pos-1, pos);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 165 of file fromtm.cpp.

                               {
  string name= decode (read_next ());
  // cout << "==> " << name << "\n";
  while (true) {
    last= read_next ();
    // cout << "~~> " << last << "\n";
    if ((last == "") || (last == "|") || (last == ">")) break;
  }
  return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 101 of file fromtm.cpp.

                      {
  int old_pos= pos;
  string c= read_char ();
  if (c == "") return c;
  switch (c[0]) {
  case '\t':
  case '\n':
  case '\r':
  case ' ': 
    pos--;
    if (skip_blank () <= 1) return " ";
    else return "\n";
  case '<':
    {
      old_pos= pos;
      c= read_char ();
      if (c == "") return "";
      if (c == "#") return "<#";
      if ((c == "\\") || (c == "|") || (c == "/")) return "<" * c;
      if (is_iso_alpha (c[0]) || (c == ">")) {
       pos= old_pos;
       return "<";
      }
      pos= old_pos;
      return "<";
      /*
      string d= read_char ();
      if ((d == "\\") || (d == "|") || (d == "/")) return "<" * c * d;
      pos= old_pos;
      return "<" * c;
      */
    }
  case '|':
  case '>':
    return c;
  }

  string r;
  pos= old_pos;
  while (true) {
    old_pos= pos;
    c= read_char ();
    if (c == "") return r;
    else if (c == "\\") {
      if ((pos < N(buf)) && (buf[pos] == '\\') && backslash_ok) {
       r << c << "\\";
       pos++;
      }
      else r << c << read_char ();
    }
    else if (c == "\t") break;
    else if (c == "\r") break;
    else if (c == "\n") break;
    else if (c == " ") break;
    else if (c == "<") break;
    else if (c == "|") break;
    else if (c == ">") break;
    else r << c;
  }
  pos= old_pos;
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 57 of file fromtm.cpp.

                       {
  int n=0;
  for (; pos < N(buf); pos++) {
    if (buf[pos]==' ') continue;
    if (buf[pos]=='\t') continue;
    if (buf[pos]=='\r') continue;
    if (buf[pos]=='\n') { n++; continue; }
    break;
  }
  return n;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 26 of file fromtm.cpp.

Definition at line 28 of file fromtm.cpp.

Definition at line 24 of file fromtm.cpp.

Definition at line 25 of file fromtm.cpp.

Definition at line 30 of file fromtm.cpp.

Definition at line 29 of file fromtm.cpp.

Definition at line 23 of file fromtm.cpp.

Definition at line 27 of file fromtm.cpp.


The documentation for this struct was generated from the following file: