ParseText Class Reference

#include <parser.h>

List of all members.

Public Member Functions

 ParseText (QString input)
void parse (QString text)
Valueexpr ()

Private Types

enum  Token {
  text, var, openexpr, closeexpr,
  eof
}

Private Member Functions

Token token ()
Token string_to (unsigned char c)
bool seperator (unsigned char c)
void text_to ()
void initText (QString text)
Valueparse ()
bool getLocation (QString text, int &C, int &R, bool &absolute_column, bool &absolute_row)
ValueproperVarType (QString tokentext)

Private Attributes

char * fulltext
char * currptr
QString tokentext
Valueexpression


Detailed Description

Definition at line 4 of file parser.h.


Member Enumeration Documentation

enum ParseText::Token [private]
 

Enumerator:
text 
var 
openexpr 
closeexpr 
eof 

Definition at line 11 of file parser.h.


Constructor & Destructor Documentation

ParseText::ParseText QString  input  ) 
 

Definition at line 9 of file parser.cpp.

References currptr, expression, fulltext, and parse().

00010 {
00011   fulltext=NULL;
00012   currptr = NULL;
00013   expression = NULL;
00014   parse(text);
00015 };


Member Function Documentation

Value* ParseText::expr  )  [inline]
 

Definition at line 23 of file parser.h.

References expression.

Referenced by IisCell::entered_changed().

00023 {return expression;};

bool ParseText::getLocation QString  text,
int &  C,
int &  R,
bool &  absolute_column,
bool &  absolute_row
[private]
 

Definition at line 46 of file parser.cpp.

Referenced by properVarType().

00047 {
00048   const char * t = text;
00049   const char * c = t;
00050   int column;
00051   int row;
00052   // column
00053   if (absolute_column=(*c=='$')) c++;
00054   column = 0;
00055   while(*c && !isdigit(*c) && *c!='$') 
00056     {
00057       column=column*26+toupper(*c)-'A';
00058       c++;
00059     }
00060   // row
00061   if (absolute_row=(*c=='$')) c++;
00062   row = 0;
00063   while(*c && isdigit(*c) && *c!='$') 
00064     {
00065       row=row*10+toupper(*c)-'0';
00066       c++;
00067     }
00068   // put out result
00069   C=column;
00070   R=row;
00071   return true;
00072 }

void ParseText::initText QString  text  )  [private]
 

Definition at line 100 of file parser.cpp.

References currptr, expression, and fulltext.

Referenced by parse().

00101 {
00102   if (fulltext) free(fulltext);
00103   fulltext=strdup(text);
00104   currptr = fulltext;
00105   printf("To parse: %s\n",fulltext);
00106   expression = NULL;
00107 }

void ParseText::parse QString  text  ) 
 

Definition at line 17 of file parser.cpp.

References expression, initText(), and parse().

00018 {
00019   initText(text);
00020   expression = parse();
00021 }

Value * ParseText::parse  )  [private]
 

Definition at line 74 of file parser.cpp.

References Expression::add(), closeexpr, eof, openexpr, properVarType(), text, token(), tokentext, and var.

Referenced by parse(), and ParseText().

00075 {
00076   Token t = token();
00077   printf("%d\n",t);
00078   switch (t)
00079     {
00080     case text: return new TextValue(tokentext);
00081     case var: return properVarType(tokentext);
00082     case openexpr: 
00083       {
00084         t = token();
00085         if (t!=var)
00086           throw new ParseError("Operand is no operator");
00087         Expression * result = new Expression(tokentext);
00088         Value * arg=NULL;
00089         while((arg=parse()))
00090           result->add(arg);
00091         return result;
00092       }
00093     case closeexpr: return NULL;
00094     case eof: throw new ParseError("Unexpected end of line");
00095     };
00096   throw new ParseError("Unexpected token");
00097   return NULL;
00098 }

Value * ParseText::properVarType QString  tokentext  )  [private]
 

Definition at line 23 of file parser.cpp.

References getLocation().

Referenced by parse().

00024 {
00025   // can we parse a location from it ?
00026   int c,r;
00027   bool ac,ar;
00028   int i;
00029   if ((i=tokentext.find(':'))>=0)
00030     {
00031       printf("%s\n",(const char*)tokentext.left(i));
00032       printf("%s\n",(const char*)tokentext.mid(i+1));
00033       bool res = getLocation(tokentext.left(i),c,r,ac,ar);
00034       assert(res);
00035       Reference * a= new Reference(c,r,ac,ar);
00036       res = getLocation(tokentext.mid(i+1),c,r,ac,ar);
00037       assert(res);
00038       Reference * b= new Reference(c,r,ac,ar);
00039       return new Range(a,b);
00040     }
00041   if (getLocation(tokentext,c,r,ac,ar))
00042     return new Reference(c,r,ac,ar);
00043   return new Variable(tokentext);
00044 }

bool ParseText::seperator unsigned char  c  )  [private]
 

Definition at line 129 of file parser.cpp.

Referenced by text_to().

00130 {
00131   return c==0 || c==' ' || c=='(' || c=='\'' || c=='"' || c==')';
00132 }

ParseText::Token ParseText::string_to unsigned char  c  )  [private]
 

Definition at line 134 of file parser.cpp.

References currptr, text, and tokentext.

Referenced by token().

00135 {
00136   char result[500];
00137   int i = 0;
00138   while(*currptr && *currptr!=c)
00139     result[i++]=*(currptr++);
00140   if(*currptr==c) currptr++;
00141   result[i]=0;
00142   tokentext=result;
00143   return text;
00144 }

void ParseText::text_to  )  [private]
 

Definition at line 146 of file parser.cpp.

References currptr, seperator(), and tokentext.

Referenced by token().

00147 {
00148   char result[500];
00149   int i = 0;
00150   while(!seperator(*currptr))
00151     result[i++]=*(currptr++);
00152   result[i]=0;
00153   tokentext=result;
00154 }

ParseText::Token ParseText::token  )  [private]
 

Definition at line 109 of file parser.cpp.

References closeexpr, currptr, eof, openexpr, string_to(), text, text_to(), and var.

Referenced by parse().

00110 {
00111   if (!currptr) return eof;
00112   // remove whitespace)
00113   while(*currptr && isspace(*currptr)) currptr++;
00114   if (!*currptr) return eof;
00115   // check for the kind of token
00116   switch(*currptr)
00117     {
00118     case '(': currptr++; return openexpr;
00119     case ')': currptr++; return closeexpr;
00120     case '"': currptr++; return string_to('"');
00121     case '\'': currptr++; return string_to('\'');
00122     }
00123   bool d = isdigit(*currptr);
00124   text_to();
00125   if (d) return text;
00126   return var;
00127 }


Member Data Documentation

char* ParseText::currptr [private]
 

Definition at line 8 of file parser.h.

Referenced by initText(), ParseText(), string_to(), text_to(), and token().

Value* ParseText::expression [private]
 

Definition at line 10 of file parser.h.

Referenced by expr(), initText(), parse(), and ParseText().

char* ParseText::fulltext [private]
 

Definition at line 7 of file parser.h.

Referenced by initText(), and ParseText().

QString ParseText::tokentext [private]
 

Definition at line 9 of file parser.h.

Referenced by parse(), string_to(), and text_to().


The documentation for this class was generated from the following files:
Generated on Mon Jun 5 22:08:43 2006 for iis by  doxygen 1.4.6