Back to index

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

List of all members.

Public Member Functions

 math_language_rep (string name)
void set_type (string cl, string s)
void set_left_penalty (string cl, string s)
void set_right_penalty (string cl, string s)
void set_left_spacing (string cl, string s)
void set_right_spacing (string cl, string s)
void set_limits (string cl, string s)
void skip_spaces (string s, int &pos, space fn_spc, space &spc)
string next_word (string s, int &pos)
text_property advance (tree t, int &pos)
array< int > get_hyphens (string s)
void hyphenate (string s, int after, string &left, string &right)
string get_group (string s)
array< stringget_members (string s)
virtual void highlight (tree t)
virtual string get_color (tree t, int start, int end)

Public Attributes

hashmap< string, stringgroup
hashmap< string,
text_property_rep
tpr_class
hashmap< string,
text_property_rep
tpr_member
string lan_name
int hl_lan
string res_name

Detailed Description

Definition at line 23 of file math_language.cpp.


Constructor & Destructor Documentation

Definition at line 127 of file math_language.cpp.

                                                :
  language_rep (name),
  group ("symbol"),
  tpr_class (text_property_rep ()),
  tpr_member (text_property_rep ())
{
  language::instances (name)= (pointer) this;
  tpr_class("symbol").op_type = OP_SYMBOL;

  packrat_grammar gr= find_packrat_grammar (name);
  hashmap<D,string> props= gr->properties;
  hashmap<string,bool> cls (false);
  iterator<D> it= iterate (props);
  while (it->busy ()) {
    D key = it->next ();
    C prop= ((C) (key >> 32));
    C sym = ((C) (key & 0xffffffff)) ^ prop;
    ASSERT (is_compound (packrat_decode[sym], "symbol", 1) &&
           is_compound (packrat_decode[prop], "property", 1),
           "invalid symbol or property");
    string cl = packrat_decode[sym ][0]->label;
    string var= packrat_decode[prop][0]->label;
    string val= props[key];
    //cout << cl << ", " << var << " -> " << val << "\n";
    if (var == "type") { set_type (cl, val); cls (cl)= true; }
    else if (var == "left-penalty") set_left_penalty (cl, val);
    else if (var == "right-penalty") set_right_penalty (cl, val);
    else if (var == "left-spacing") set_left_spacing (cl, val);
    else if (var == "right-spacing") set_right_spacing (cl, val);
    else if (var == "limits") set_limits (cl, val);
  }

  iterator<string> it2= iterate (cls);
  while (it2->busy ()) {
    string cl= it2->next ();
    array<string> a= gr->members (cl);
    for (int i=0; i<N(a); i++) {
      group (a[i])= cl;
      tpr_member (a[i])= tpr_class [cl];
    }
  }
}

Here is the call graph for this function:


Member Function Documentation

text_property math_language_rep::advance ( tree  t,
int &  pos 
) [virtual]

Implements language_rep.

Definition at line 202 of file math_language.cpp.

                                            {
  string s= t->label;
  bool op_flag1=
    (pos==0) ||
    ((pos>=2) && is_alpha (s[pos-2]) && is_alpha (s[pos-1]));
  string r= next_word (s, pos);
  if (r == " ") {
    bool op_flag2=
      (pos==N(s)) ||
      (((pos+2)<N(s)) && is_alpha (s[pos]) && is_alpha (s[pos+1]));
    if (op_flag1 || op_flag2) return &tp_operator_rep;
    else return &tp_shortop_rep;
  }
  return &tpr_member(r);

  /****************************** variant *******************************
  string r= next_word (s, pos);
  if (r == " ") return &tp_operator_rep;
  else return &tpr_member(r);
  **********************************************************************/
}

Here is the call graph for this function:

string language_rep::get_color ( tree  t,
int  start,
int  end 
) [virtual, inherited]

Reimplemented in cpp_language_rep, mathemagix_language_rep, scheme_language_rep, and verb_language_rep.

Definition at line 168 of file language.cpp.

                                                   {
  (void) t; (void) start; (void) end;
  return "";
}

Reimplemented from language_rep.

Definition at line 253 of file math_language.cpp.

                                      {
  return group[s];
}
array< int > math_language_rep::get_hyphens ( string  s) [virtual]

Implements language_rep.

Definition at line 229 of file math_language.cpp.

                                        {
  ASSERT (N(s) != 0, "hyphenation of empty string");
  int i, n= N(s)-1;
  bool flag= is_numeric (s);
  array<int> penalty (n);
  for (i=0; i<n; i++) penalty[i]= (flag? HYPH_PANIC: HYPH_INVALID);
  if (n>0) penalty[0]= penalty[n-1]= HYPH_INVALID;
  if (n>2) penalty[1]= penalty[n-2]= HYPH_INVALID;
  if (n>4) penalty[2]= penalty[n-3]= HYPH_INVALID;
  return penalty;
}

Here is the call graph for this function:

Reimplemented from language_rep.

Definition at line 258 of file math_language.cpp.

                                        {
  array<string> r;
  iterator<string> it= iterate (group);
  while (it->busy ()) {
    string s= it->next ();
    if (group[s] == g) r << s;
  }
  return r;
}

Here is the call graph for this function:

void language_rep::highlight ( tree  t) [virtual, inherited]

Definition at line 162 of file language.cpp.

                               {
  if (hl_lan != 0 && !has_highlight (t, hl_lan))
    packrat_highlight (res_name, "Main", t);
}

Here is the call graph for this function:

void math_language_rep::hyphenate ( string  s,
int  after,
string left,
string right 
) [virtual]

Implements language_rep.

Definition at line 242 of file math_language.cpp.

{
  left = s (0, after+1) * string ("\\");
  right= s (after+1, N(s));
}

Here is the call graph for this function:

string math_language_rep::next_word ( string  s,
int &  pos 
)

Definition at line 175 of file math_language.cpp.

                                                {
  int start= pos;

  if (pos>=N(s)) return string ("");

  if ((s[pos]>='0') && (s[pos]<='9')) {
    while ((pos<N(s)) && is_numeric (s[pos])) pos++;
    while (s[pos-1]=='.') pos--;
    return s (start, pos);
  }

  if (is_alpha (s[pos])) {
    while ((pos<N(s)) && (is_alpha (s[pos]))) pos++;
    return s (start, pos);
  }

  if (s[pos]=='<') {
    while ((pos<N(s)) && (s[pos]!='>')) pos++;
    if (pos<N(s)) pos++;
    return s (start, pos);
  }

  pos++;
  return s (start, pos);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file math_language.cpp.

                                                        {
  if (is_int (s)) tpr_class(cl).pen_before= as_int (s);
  else if (s == "panic")   tpr_class(cl).pen_before= HYPH_PANIC;
  else if (s == "invalid") tpr_class(cl).pen_before= HYPH_INVALID;
  else {
    cerr << "Attempt to associate left penalty " << s << " to " << cl << "\n";
    FAILED ("invalid penalty");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 92 of file math_language.cpp.

                                                        {
  if      (s == "none")    tpr_class(cl).spc_before= SPC_NONE;
  else if (s == "half")    tpr_class(cl).spc_before= SPC_HALF;
  else if (s == "default") tpr_class(cl).spc_before= SPC_OPERATOR;
  else if (s == "big")     tpr_class(cl).spc_before= SPC_BIGOP;
  else {
    cerr << "Attempt to associate left spacing " << s << " to " << cl << "\n";
    FAILED ("invalid spacing");
  }
}

Here is the caller graph for this function:

Definition at line 116 of file math_language.cpp.

                                                  {
  if      (s == "none")    tpr_class(cl).limits= LIMITS_NONE;
  else if (s == "display") tpr_class(cl).limits= LIMITS_DISPLAY;
  else if (s == "always")  tpr_class(cl).limits= LIMITS_ALWAYS;
  else {
    cerr << "Attempt to associate limits " << s << " to " << cl << "\n";
    FAILED ("invalid limits");
  }
}

Here is the caller graph for this function:

Definition at line 81 of file math_language.cpp.

                                                         {
  if (is_int (s)) tpr_class(cl).pen_after= as_int (s);
  else if (s == "panic")   tpr_class(cl).pen_after= HYPH_PANIC;
  else if (s == "invalid") tpr_class(cl).pen_after= HYPH_INVALID;
  else {
    cerr << "Attempt to associate right penalty " << s << " to " << cl << "\n";
    FAILED ("invalid penalty");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 104 of file math_language.cpp.

                                                         {
  if      (s == "none")    tpr_class(cl).spc_after= SPC_NONE;
  else if (s == "half")    tpr_class(cl).spc_after= SPC_HALF;
  else if (s == "default") tpr_class(cl).spc_after= SPC_OPERATOR;
  else if (s == "big")     tpr_class(cl).spc_after= SPC_BIGOP;
  else {
    cerr << "Attempt to associate right spacing " << s << " to " << cl << "\n";
    FAILED ("invalid spacing");
  }
}

Here is the caller graph for this function:

Definition at line 50 of file math_language.cpp.

                                                {
  int &ot= tpr_class(cl).op_type;
  if (s == "symbol") ot= OP_SYMBOL;
  else if (s == "unary") ot= OP_UNARY;
  else if (s == "binary") ot= OP_BINARY;
  else if (s == "n-ary") ot= OP_N_ARY;
  else if (s == "prefix") ot= OP_PREFIX;
  else if (s == "postfix") ot= OP_POSTFIX;
  else if (s == "infix") ot= OP_INFIX;
  else if (s == "separator") ot= OP_SEPARATOR;
  else if (s == "opening-bracket") ot= OP_OPENING_BRACKET;
  else if (s == "middle-bracket") ot= OP_MIDDLE_BRACKET;
  else if (s == "closing-bracket") ot= OP_CLOSING_BRACKET;
  else {
    cerr << "Attempt to associate type " << s << " to " << cl << "\n";
    FAILED ("invalid type");
  }
}

Here is the caller graph for this function:

void math_language_rep::skip_spaces ( string  s,
int &  pos,
space  fn_spc,
space spc 
)

Member Data Documentation

Definition at line 24 of file math_language.cpp.

int language_rep::hl_lan [inherited]

Definition at line 113 of file language.hpp.

Definition at line 112 of file language.hpp.

string rep< language >::res_name [inherited]

Definition at line 17 of file resource.hpp.

Definition at line 25 of file math_language.cpp.

Definition at line 26 of file math_language.cpp.


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