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

Parser Class Reference

Collaboration diagram for Parser:

[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)
? this first level parsing function extracts individual lines from the text, taking care of both Unix and Windows EOL styles.

Awk::condition? parse_line (const cmt_string &line)
? This second level parsing function accumulates individual lines with real trailing back slashes.


Private Attributes

cmt_string? m_accumulator
cmt_string? m_pattern
const cmt_regexp *? m_expression
Awk *? m_awk

Constructor & Destructor Documentation

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

Definition at line 19 of file cmt_awk.cxx.

References m_awk, m_expression, and m_pattern.

00019                                                                             :
00020           m_pattern (pattern), m_expression (expression), m_awk(awk)
00021       {
00022       }


Member Function Documentation

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

this first level parsing function extracts individual lines from the text, taking care of both Unix and Windows EOL styles.

Then the second level parsing function parse_line is called.

Definition at line 30 of file cmt_awk.cxx.

References Awk::condition, cmt_string::erase(), cmt_string::find(), Awk::inc_line_number(), m_accumulator, m_awk, cmt_string::npos, Awk::ok, parse_line(), cmt_string::size(), and cmt_string::substr().

Referenced by Awk::run().

00031       {
00032         Awk::condition result = Awk::ok;
00033 
00034         cmt_string line;
00035         int pos;
00036         int max_pos;
00037 
00038         pos = 0;
00039         max_pos = text.size ();
00040 
00041         m_accumulator.erase (0);
00042 
00043         for (pos = 0; pos < max_pos;)
00044           {
00045             int eol = text.find (pos, '\n');
00046             
00047             if (eol == cmt_string::npos)
00048               {
00049                   // Last line, since there is no eol at all
00050                 text.substr (pos, line);
00051                 pos = max_pos;
00052               }
00053             else
00054               {
00055                 int length = 1;
00056 
00057                 int cr = text.find (pos, "\r\n");
00058 
00059                 if (cr == (eol-1))
00060                   {
00061                     eol = cr;
00062                     length = 2;
00063                   }
00064 
00065                 if (eol == pos)
00066                   {
00067                       // this is an empty line
00068                     line = "";
00069                     pos += length;
00070                   }
00071                 else
00072                   {
00073                       // The eol was found beyond the current position
00074                       // (ie. this is a non empty line)
00075                     text.substr (pos, eol - pos, line);
00076                     pos = eol + length;
00077                   }
00078               }
00079 
00080             if (m_awk != 0) m_awk->inc_line_number ();
00081 
00082               //cout << "parse> line=[" << line << "]" << endl;
00083 
00084             result = parse_line (line);
00085             if (result != Awk::ok) break;
00086           }
00087 
00088         return (result);
00089       }

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

This second level parsing function accumulates individual lines with real trailing back slashes.

Eventually the possible text pattern or regular expression is checked and the Awk::filter function is called in case of succesful match onto the accumulated line.

Definition at line 98 of file cmt_awk.cxx.

References Awk::condition, cmt_string::erase(), Awk::filter(), cmt_string::find(), cmt_string::find_last_of(), Awk::get_last_condition(), m_accumulator, m_awk, m_expression, m_pattern, cmt_regexp::match(), cmt_string::npos, Awk::ok, and cmt_string::size().

Referenced by parse().

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

Member Data Documentation

cmt_string Parser::m_accumulator [private]
?

Definition at line 207 of file cmt_awk.cxx.

Referenced by parse(), and parse_line().

Awk* Parser::m_awk [private]
?

Definition at line 210 of file cmt_awk.cxx.

Referenced by parse(), parse_line(), and Parser().

const cmt_regexp* Parser::m_expression [private]
?

Definition at line 209 of file cmt_awk.cxx.

Referenced by parse_line(), and Parser().

cmt_string Parser::m_pattern [private]
?

Definition at line 208 of file cmt_awk.cxx.

Referenced by parse_line(), and Parser().


The documentation for this class was generated from the following file:
Generated on Wed Sep 1 11:00:47 2004 for CMT by 1.2.18