Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Parser Class Reference

Collaboration diagram for Parser:

Collaboration graph
[legend]
List of all members.

Public Methods

 Parser (Awk* awk, const cmt_string pattern, const cmt_regexp* expression)
Awk::condition parse (const cmt_string& text)
Awk::condition parse_line (const cmt_string& line)

Private Attributes

cmt_string m_accumulator
cmt_string m_pattern
const cmt_regexpm_expression
Awkm_awk

Constructor & Destructor Documentation

Parser::Parser ( Awk * awk,
const cmt_string pattern,
const cmt_regexp * expression ) [inline]
 

Definition at line 14 of file cmt_awk.cxx.

00014                                                                             :
00015           m_pattern (pattern), m_expression (expression), m_awk(awk)
00016       {
00017       }


Member Function Documentation

Awk::condition Parser::parse ( const cmt_string & text ) [inline]
 

Definition at line 19 of file cmt_awk.cxx.

Referenced by Awk::run().

00020       {
00021         Awk::condition result = Awk::ok;
00022 
00023         cmt_string line;
00024         int pos;
00025         int max_pos;
00026 
00027         pos = 0;
00028         max_pos = text.size ();
00029 
00030         m_accumulator.erase (0);
00031 
00032         for (pos = 0; pos < max_pos;)
00033           {
00034             int cr = text.find (pos, "\r\n");
00035             int nl = text.find (pos, '\n');
00036             int first = nl;
00037             int length = 1;
00038             
00039             if (cr != cmt_string::npos)
00040               {
00041                 if (nl == cmt_string::npos)
00042                   {
00043                     first = cr;
00044                     length = 2;
00045                   }
00046                 else
00047                   {
00048                     first = (nl < cr) ? nl : cr;
00049                     length = (nl < cr) ? 1 : 2;
00050                   }
00051               }
00052             
00053             if (first == cmt_string::npos)
00054               {
00055                 text.substr (pos, line);
00056                 pos = max_pos;
00057               }
00058             else if (first > pos)
00059               {
00060                 text.substr (pos, first - pos, line);
00061                 pos = first + length;
00062               }
00063             else
00064               {
00065                 line.erase (0);
00066                 pos += length;
00067               }
00068 
00069               //cout << "parse> line=[" << line << "]" << endl;
00070 
00071             result = parse_line (line);
00072             if (result != Awk::ok) break;
00073           }
00074 
00075         return (result);
00076       }

Awk::condition Parser::parse_line ( const cmt_string & line ) [inline]
 

Definition at line 78 of file cmt_awk.cxx.

Referenced by parse().

00079       {
00080         Awk::condition result = Awk::ok;
00081         int length;
00082         int nl;
00083         int back_slash;
00084         cmt_string temp_line = line;
00085 
00086         if (temp_line.size () == 0) return (result);
00087 
00088         nl = temp_line.find_last_of ('\n');
00089         if (nl != cmt_string::npos) temp_line.erase (nl);
00090         
00091         length = temp_line.size ();
00092         if (length == 0) return (result);
00093         
00094           //
00095           // We scan the line for handling backslashes.
00096           //
00097           // o Really terminating backslashes (ie those only followed by spaces/tabs
00098           // mean continued line
00099           //
00100           //
00101 
00102         bool finished = true;
00103 
00104         length = temp_line.size ();
00105 
00106         back_slash = temp_line.find_last_of ('\\');
00107         
00108         if (back_slash != cmt_string::npos)
00109           {
00110               //
00111               // This is the last backslash
00112               // check if there are only space chars after it
00113               //
00114             
00115             bool at_end = true;
00116             
00117             for (int i = (back_slash + 1); i < length; i++)
00118               {
00119                 char c = temp_line[i];
00120                 if ((c != ' ') && (c != '\t'))
00121                   {
00122                     at_end = false;
00123                     break;
00124                   }
00125               }
00126             
00127             if (at_end)
00128               {
00129                 temp_line.erase (back_slash);
00130                 finished = false;
00131               }
00132             else
00133               {
00134                   // This was not a trailing backslash.
00135                 finished = true;
00136               }
00137           }
00138         
00139         m_accumulator += temp_line;
00140         
00141           //cout << "parse_line1> accumulator=[" << m_accumulator << "]" << endl;
00142           //cout << "parse_line1> finished=[" << finished << "]" << endl;
00143 
00144         if (!finished)
00145           {
00146               // We still need to accumulate forthcoming lines
00147               // before parsing the resulting text.
00148             return (result);
00149           }
00150 
00151           // now filter the accumulated line
00152 
00153         if (m_accumulator != "")
00154           {
00155             bool ok = false;
00156             
00157             if (m_expression != 0)
00158               {
00159                 if (m_expression->match (m_accumulator))
00160                   {
00161                     ok = true;
00162                   }
00163               }
00164             else
00165               {
00166                 if ((m_pattern == "") ||
00167                     (m_accumulator.find (m_pattern) != cmt_string::npos))
00168                   {
00169                     ok = true;
00170                   }
00171               }
00172             
00173             if (ok && (m_awk != 0))
00174               {
00175                   //cout << "parse_line> accumulator=[" << m_accumulator << "]" << endl;
00176 
00177                 m_awk->filter (m_accumulator);
00178                 result = m_awk->get_last_condition ();
00179               }
00180           }
00181         
00182         m_accumulator.erase (0);
00183 
00184         return (result);
00185       }


Member Data Documentation

cmt_string Parser::m_accumulator [private]
 

Definition at line 189 of file cmt_awk.cxx.

Awk * Parser::m_awk [private]
 

Definition at line 192 of file cmt_awk.cxx.

const cmt_regexp * Parser::m_expression [private]
 

Definition at line 191 of file cmt_awk.cxx.

cmt_string Parser::m_pattern [private]
 

Definition at line 190 of file cmt_awk.cxx.


The documentation for this class was generated from the following file:
Generated at Thu May 16 16:27:56 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000