Back to index

texmacs  1.0.7.15
Functions | Variables
cpp_language.cpp File Reference
#include "analyze.hpp"
#include "impl_language.hpp"
#include "scheme.hpp"

Go to the source code of this file.

Functions

static int line_number (tree t)
static int number_of_line (tree t)
static tree line_inc (tree t, int i)
static void parse_number (string s, int &pos)
static void parse_string (string s, int &pos)
static void parse_alpha (string s, int &pos)
static void cpp_color_setup_constants (hashmap< string, string > &t)
static void cpp_color_setup_keywords (hashmap< string, string > &t)
static void cpp_color_setup_otherlexeme (hashmap< string, string > &t)
static bool belongs_to_identifier (char c)
static bool is_number (char c)
static void parse_identifier (hashmap< string, string > &t, string s, int &pos)
static void parse_blanks (string s, int &pos)
static void parse_keyword (hashmap< string, string > &t, string s, int &pos)
static void parse_constant (hashmap< string, string > &t, string s, int &pos)
static void parse_other_lexeme (hashmap< string, string > &t, string s, int &pos)
static void parse_comment_multi_lines (string s, int &pos)
static void parse_comment_single_line (string s, int &pos)
static void parse_end_comment (string s, int &pos)
static void parse_diese (string s, int &pos)
static void parse_preprocessing (string s, int &pos)
static bool begin_comment (string s, int i)
static bool end_comment (string s, int i)
static bool after_begin_comment (string s, int i, tree t)
static bool before_end_comment (string s, int i, tree t)
static bool in_comment (string s, int pos, tree t)
static bool end_preprocessing (string s)
static bool begin_preprocessing (string s)
static bool in_preprocessing (string s, tree t)

Variables

tree the_et

Function Documentation

static bool after_begin_comment ( string  s,
int  i,
tree  t 
) [static]

Definition at line 400 of file cpp_language.cpp.

                                                          {
  if (begin_comment(s, i)) return true;
  tree t2= t;
  string s2= s;
  if (N(s2)==0) return false;
  int pos=0;
  parse_blanks(s2,pos);
  if (s2[pos]!='*') return false;
  while (line_number(t2) > 0) {
    t2= line_inc(t2,-1);
    // line_inc return tree(ERROR) upon error
    if (!is_atomic(t2)) return false;
    s2= t2->label;
    if (N(s2)>0 && begin_comment (s2, N(s2)-1)) return true;
    if (N(s2)==0) return false;
    int pos=0;
    parse_blanks(s2,pos);
    if (s2[pos]!='*') return false;
    } 
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool before_end_comment ( string  s,
int  i,
tree  t 
) [static]

Definition at line 422 of file cpp_language.cpp.

                                                         {
  int number= number_of_line(t);
  tree t2= t;
  string s2=s;
  if (N(s2)==0) return false;
  int pos=0;
  if (!begin_comment(s,i)) {
    parse_blanks(s2,pos);
    if (s2[pos]!='*') return false;
  }
  if (end_comment(s, i)) return true;
  while (line_number(t2) < number-1) {
    t2= line_inc(t2,1);
    // line_inc return tree(ERROR) upon error
    if (!is_atomic(t2)) return false;
    s2= t2->label;
    if (N(s2)==0) return false;
    pos=0;
    parse_blanks(s2, pos);
    if (s2[pos]!='*') return false;
    if (N(s2)>0 && end_comment (s2, 0)) return true;
  } 
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool begin_comment ( string  s,
int  i 
) [static]

Definition at line 361 of file cpp_language.cpp.

                                            {
  bool comment;
  int pos= 0;
  int opos; 
  do {
    do {
    opos= pos;
    comment= false;
    parse_string (s, pos);
    if (opos < pos) break;
    parse_comment_multi_lines (s, pos);
    if (opos < pos) {comment= true; break;}
    pos++;
    }
  while (false);
  }
  while (pos<=i);
  return comment;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool begin_preprocessing ( string  s) [static]

Definition at line 460 of file cpp_language.cpp.

                                           { 
  if (N(s)>0 && s[0]=='#') return true;
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 210 of file cpp_language.cpp.

                               {
  return ((c<='9' && c>='0') ||
         (c<='Z' && c>='A') ||
        (c<='z' && c>='a') ||
          c=='_');
}

Here is the caller graph for this function:

static void cpp_color_setup_constants ( hashmap< string, string > &  t) [static]

Definition at line 111 of file cpp_language.cpp.

                                                        {
  string c= "#2060c0";
  t ("true")= c;
  t ("false")= c;
  t ("cout")= c;
  t ("cin")= c;
  t ("cerr")= c;
}

Here is the caller graph for this function:

static void cpp_color_setup_keywords ( hashmap< string, string > &  t) [static]

Definition at line 121 of file cpp_language.cpp.

                                                        {
  string c= "#8020c0"; 
  t ("asm")= c;
  t ("auto")= c;
  t ("break")= c;
  t ("case")= c;
  t ("catch")= c;
  t ("class")= c;
  t ("concrete")= c;
  t ("constant")= c;
  t ("continue")= c;
  t ("default")= c;
  t ("delete")= c;
  t ("do")= c;
  t ("else")= c;
  t ("enum")= c;
  t ("extern")= c;
  t ("explicit")= c;
  t ("for")= c;
  t ("friend")= c;
  t ("goto")= c;
  t ("if")= c;
  t ("inline")= c;
  t ("mutable")= c;
  t ("new")= c;
  t ("operator")= c;
  t ("private")= c;
  t ("protected")= c;
  t ("public")= c;
  t ("register")= c;
  t ("return")= c ;
  t ("sizeof")= c;
  t ("static")= c;
  t ("struct")= c;
  t ("switch")= c;
  t ("template")= c;
  t ("this")= c;
  t ("throw")= c;
  t ("to")= c;
  t ("try")= c;
  t ("typedef")= c;
  t ("union")= c;
  t ("virtual")= c;
  t ("volatile")= c;
  t ("while")= c;
  t ("malloc")= c;
  t ("realloc")= c;
  t ("calloc")= c;
  t ("free")= c;
}

Here is the caller graph for this function:

static void cpp_color_setup_otherlexeme ( hashmap< string, string > &  t) [static]

Definition at line 173 of file cpp_language.cpp.

                                                         {
  string c= "black";
  t ("+")= c;
  t ("-")= c;
  t ("/")= c;
  t ("=")= c;
  t (".")= c;
  t ("<less>")= c;
  t ("gtr")= c;
  t ("|")= c;
  t ("!")= c;
  t ("...")= c;
  t (",")= c;
  t ("+=")= c;
  t ("-=")= c; 
  t ("*=")= c;
  t ("/=")= c;
  t (",")= c;
  t (";")= c;
  t ("(")= c;
  t (")")= c;
  t ("[")= c;
  t ("]")= c;
  t ("{")= c;
  t ("}")= c;
  t ("<less><less>")= c;
  t ("<gtr><gtr>")= c;
  t ("<less>=")= c;
  t ("==")= c;
  t ("<gtr>=")= c;
  t ("&&")= c;
  t ("||")= c;
  t ("!=")= c;
  
}

Here is the caller graph for this function:

static bool end_comment ( string  s,
int  i 
) [static]

Definition at line 381 of file cpp_language.cpp.

                                          {
  bool comment;
  int pos= 0; int opos;
  do {
    do {
    opos= pos;
    comment= false;
    parse_string (s, pos);
       if (opos < pos) break;
    parse_end_comment (s, pos);
    if (opos < pos && pos>i) return true;
    pos ++;
    }
  while (false);
  }
  while (pos<N(s));
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool end_preprocessing ( string  s) [static]

Definition at line 452 of file cpp_language.cpp.

                                         {
  int pos=N(s)-1;
  if (N(s)==0) return false;
  while (s[pos]==' ' && pos>0) {pos--;}
  if (s[pos]=='/') return true;
  return false;
}  

Here is the call graph for this function:

Here is the caller graph for this function:

static bool in_comment ( string  s,
int  pos,
tree  t 
) [static]

Definition at line 447 of file cpp_language.cpp.

                                                  {
  if (after_begin_comment(s, pos, t) && before_end_comment(s, pos, t)) return true;
  return false;
}  

Here is the call graph for this function:

Here is the caller graph for this function:

static bool in_preprocessing ( string  s,
tree  t 
) [static]

Definition at line 465 of file cpp_language.cpp.

                                                {
  if (begin_preprocessing(s)) return true;
  tree t2= t;
  string s2= s;
  while (line_number(t2) > 0) {
    t2= line_inc(t2,-1);
    // line_inc return tree(ERROR) upon error
    if (!is_atomic(t2)) return false;
    s2= t2->label;
    if (!end_preprocessing(s2)) return false;
    if (begin_preprocessing(s2)) return true;
  } 
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 218 of file cpp_language.cpp.

                   {
  return (c>='0' && c<='9');
}
static tree line_inc ( tree  t,
int  i 
) [static]

Definition at line 49 of file cpp_language.cpp.

                         {
  path p= obtain_ip (t);
  if (is_nil (p) || last_item (p) < 0) return tree (ERROR);
  tree pt= subtree (the_et, reverse (p->next));
  if (!is_func (pt, DOCUMENT)) return tree (ERROR);
  if ((p->item + i < 0) || (p->item + i >= N(pt))) return tree (ERROR);
  return pt[p->item + i];
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int line_number ( tree  t) [static]

Definition at line 31 of file cpp_language.cpp.

                     {
  path p= obtain_ip (t);
  if (is_nil (p) || last_item (p) < 0) return -1;
  tree pt= subtree (the_et, reverse (p->next));
  if (!is_func (pt, DOCUMENT)) return -1;
  return p->item;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int number_of_line ( tree  t) [static]

Definition at line 40 of file cpp_language.cpp.

                        {
  path p= obtain_ip (t);
  if (is_nil (p) || last_item (p) < 0) return -1;
  tree pt= subtree (the_et, reverse (p->next));
  if (!is_func (pt, DOCUMENT)) return -1;
  return N(pt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_alpha ( string  s,
int &  pos 
) [static]

Definition at line 232 of file cpp_language.cpp.

                                 {
  static hashmap<string,string> empty;
  parse_identifier (empty, s, pos);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_blanks ( string  s,
int &  pos 
) [static]

Definition at line 238 of file cpp_language.cpp.

                                  {
  while (pos<N(s) && (s[pos]==' ' || s[pos]=='\t')) pos++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_comment_multi_lines ( string  s,
int &  pos 
) [static]

Definition at line 314 of file cpp_language.cpp.

                                               {
  if (pos>=N(s)) return;
  if (s[pos]!='/') return;
  if (pos+1<N(s) && s[pos+1]=='*') {
    pos= pos+2;
    while ((pos<N(s) && s[pos]!='*') || (pos+1<N(s) && s[pos+1]!='/')) pos++;
    pos= min(pos+2,N(s));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_comment_single_line ( string  s,
int &  pos 
) [static]

Definition at line 325 of file cpp_language.cpp.

                                               {
  if (pos>=N(s)) return;
  if (s[pos]!='/') return;
  if (pos+1<N(s) && s[pos+1]=='/') {pos=N(s);return;}
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_constant ( hashmap< string, string > &  t,
string  s,
int &  pos 
) [static]

Definition at line 275 of file cpp_language.cpp.

                                                               {
  int i=pos;
  if (pos>=N(s)) return;
  if (is_number (s[i])) return;
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
  string r= s (pos, i);
  if (t->contains (r) && t(r)=="#2060c0") { pos=i; return; }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_diese ( string  s,
int &  pos 
) [static]

Definition at line 336 of file cpp_language.cpp.

                                             {
  if (s[pos] == '#') pos++;
  }

Here is the caller graph for this function:

static void parse_end_comment ( string  s,
int &  pos 
) [static]

Definition at line 332 of file cpp_language.cpp.

                                       {
  if (pos+1<N(s) && s[pos]=='*' && s[pos+1]=='/') pos=pos+2; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_identifier ( hashmap< string, string > &  t,
string  s,
int &  pos 
) [static]

Definition at line 223 of file cpp_language.cpp.

                                                                  {
  int i=pos;
  if (pos >= N(s)) return;
  if (is_number (s[i])) return;
  while (i<N(s) && belongs_to_identifier (s[i])) i++;
  if (!(t->contains (s (pos, i)))) pos= i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_keyword ( hashmap< string, string > &  t,
string  s,
int &  pos 
) [static]

Definition at line 265 of file cpp_language.cpp.

                                                              {
  int i= pos;
  if (pos>=N(s)) return;
  if (is_number (s[i])) return;
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
  string r= s (pos, i);
  if (t->contains (r) && t(r)=="#8020c0") { pos=i; return; }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_number ( string  s,
int &  pos 
) [static]

Definition at line 295 of file cpp_language.cpp.

                                  {
  int i= pos;
  if (pos>=N(s)) return;
  if (s[i] == '.') return;
  while (i<N(s) && 
        (is_number (s[i]) ||
         (s[i] == '.' && (i+1<N(s)) &&
          (is_number (s[i+1]) ||
           s[i+1] == 'e' || s[i+1] == 'E')))) i++;
  if (i == pos) return;
  if (i<N(s) && (s[i] == 'e' || s[i] == 'E')) {
    i++;
    if (i<N(s) && s[i] == '-') i++;
    while (i<N(s) && (is_number (s[i]))) i++;
  }
  pos= i;
}

Here is the call graph for this function:

static void parse_other_lexeme ( hashmap< string, string > &  t,
string  s,
int &  pos 
) [static]

Definition at line 285 of file cpp_language.cpp.

                                                                   {
  int i;
  for (i=12; i>=1; i--) {
    string r=s(pos,pos+i);
    if (t->contains(r) && t(r)=="black") {
      pos=pos+i; return; }
  }
}

Here is the caller graph for this function:

static void parse_preprocessing ( string  s,
int &  pos 
) [static]

Definition at line 340 of file cpp_language.cpp.

                                                      {
  int i= pos;
  if (pos>=N(s)) return;
  if (is_number (s[i])) return;
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
  string r= s (pos, i);
  if (r == "include" ||
       r == "if" ||
       r == "ifdef" ||
       r == "ifndef" ||
       r == "else" ||
       r == "elif" ||
       r == "endif" ||
       r == "define" ||
       r == "undef" ||
       r == "pragma" ||
       r == "error") { pos=i; return; }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_string ( string  s,
int &  pos 
) [static]

Definition at line 243 of file cpp_language.cpp.

                                  {
  if (pos>=N(s)) return;
  switch (s[pos])  {
  case '\042':
    do pos++;
    while((pos<N(s)) &&
         ((s[pos-1]=='\\' && s[pos]=='\042') || s[pos]!='\042'));
    if (s[pos]=='\042') pos++;
    return;
  case '/':
    if (pos+1<N(s) && s[pos+1]=='\042') {
      pos=pos+2;
      do {
       if (pos+1<N(s) && s[pos]=='\042' && s[pos+1]=='/') {
         pos=pos+2; return; }
       pos++;
      } while (pos<N(s));
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 18 of file new_document.cpp.