
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. More... | |
| Awk::condition | parse_line (const cmt_string& line) |
| This second level parsing function accumulates individual lines with real trailing back slashes. More... | |
Private Attributes | |
| cmt_string | m_accumulator |
| cmt_string | m_pattern |
| const cmt_regexp* | m_expression |
| Awk* | m_awk |
|
|
Definition at line 14 of file cmt_awk.cxx. 00014 : 00015 m_pattern (pattern), m_expression (expression), m_awk(awk) 00016 { 00017 } |
|
|
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 25 of file cmt_awk.cxx. Referenced by Awk::run(). 00026 {
00027 Awk::condition result = Awk::ok;
00028
00029 cmt_string line;
00030 int pos;
00031 int max_pos;
00032
00033 pos = 0;
00034 max_pos = text.size ();
00035
00036 m_accumulator.erase (0);
00037
00038 for (pos = 0; pos < max_pos;)
00039 {
00040 int eol = text.find (pos, '\n');
00041
00042 if (eol == cmt_string::npos)
00043 {
00044 // Last line, since there is no eol at all
00045 text.substr (pos, line);
00046 pos = max_pos;
00047 }
00048 else
00049 {
00050 int length = 1;
00051
00052 int cr = text.find (pos, "\r\n");
00053
00054 if (cr == (eol-1))
00055 {
00056 eol = cr;
00057 length = 2;
00058 }
00059
00060 if (eol == pos)
00061 {
00062 // this is an empty line
00063 line = "";
00064 pos += length;
00065 }
00066 else
00067 {
00068 // The eol was found beyond the current position
00069 // (ie. this is a non empty line)
00070 text.substr (pos, eol - pos, line);
00071 pos = eol + length;
00072 }
00073 }
00074
00075 if (m_awk != 0) m_awk->inc_line_number ();
00076
00077 //cout << "parse> line=[" << line << "]" << endl;
00078
00079 result = parse_line (line);
00080 if (result != Awk::ok) break;
00081 }
00082
00083 return (result);
00084 }
|
|
|
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 93 of file cmt_awk.cxx. Referenced by parse(). 00094 {
00095 Awk::condition result = Awk::ok;
00096 int length;
00097 cmt_string temp_line = line;
00098
00099 //
00100 // We scan the line for handling backslashes.
00101 //
00102 // Really terminating backslashes (ie those only followed by spaces/tabs
00103 // mean continued line
00104 //
00105 //
00106
00107 bool finished = true;
00108
00109 length = temp_line.size ();
00110
00111 if (length == 0)
00112 {
00113 // An empty line following a backslash terminates the continuation.
00114 finished = true;
00115 }
00116 else
00117 {
00118 int back_slash = temp_line.find_last_of ('\\');
00119
00120 if (back_slash != cmt_string::npos)
00121 {
00122 //
00123 // This is the last backslash
00124 // check if there are only space chars after it
00125 //
00126
00127 bool at_end = true;
00128
00129 for (int i = (back_slash + 1); i < length; i++)
00130 {
00131 char c = temp_line[i];
00132 if ((c != ' ') && (c != '\t'))
00133 {
00134 at_end = false;
00135 break;
00136 }
00137 }
00138
00139 if (at_end)
00140 {
00141 temp_line.erase (back_slash);
00142 finished = false;
00143 }
00144 else
00145 {
00146 // This was not a trailing backslash.
00147 finished = true;
00148 }
00149 }
00150
00151 m_accumulator += temp_line;
00152 }
00153
00154 //cout << "parse_line1> accumulator=[" << m_accumulator << "]" << endl;
00155 //cout << "parse_line1> finished=[" << finished << "]" << endl;
00156
00157 if (!finished)
00158 {
00159 // We still need to accumulate forthcoming lines
00160 // before parsing the resulting text.
00161 return (Awk::ok);
00162 }
00163
00164 // now filter the complete accumulated line (if non empty)
00165
00166 if (m_accumulator != "")
00167 {
00168 bool ok = false;
00169
00170 if (m_expression != 0)
00171 {
00172 if (m_expression->match (m_accumulator))
00173 {
00174 ok = true;
00175 }
00176 }
00177 else
00178 {
00179 if ((m_pattern == "") ||
00180 (m_accumulator.find (m_pattern) != cmt_string::npos))
00181 {
00182 ok = true;
00183 }
00184 }
00185
00186 if (ok && (m_awk != 0))
00187 {
00188 //cout << "parse_line> accumulator=[" << m_accumulator << "]" << endl;
00189
00190 m_awk->filter (m_accumulator);
00191 result = m_awk->get_last_condition ();
00192 }
00193
00194 m_accumulator.erase (0);
00195 }
00196
00197 return (result);
00198 }
|
|
|
Definition at line 202 of file cmt_awk.cxx. |
|
|
Definition at line 205 of file cmt_awk.cxx. |
|
|
Definition at line 204 of file cmt_awk.cxx. |
|
|
Definition at line 203 of file cmt_awk.cxx. |
1.2.3 written by Dimitri van Heesch,
© 1997-2000