src/lexerScanner.cpp

changeset 138
a426c1039655
parent 136
1c40bb4f8221
equal deleted inserted replaced
137:73d057b030d0 138:a426c1039655
112 }; 112 };
113 113
114 static_assert (countof (gTokenStrings) == (int) LastNamedToken + 1, 114 static_assert (countof (gTokenStrings) == (int) LastNamedToken + 1,
115 "Count of gTokenStrings is not the same as the amount of named token identifiers."); 115 "Count of gTokenStrings is not the same as the amount of named token identifiers.");
116 116
117 // ============================================================================= 117 // _________________________________________________________________________________________________
118 // 118 //
119 LexerScanner::LexerScanner (FILE* fp) : 119 LexerScanner::LexerScanner (FILE* fp) :
120 m_line (1) 120 m_line (1)
121 { 121 {
122 long fsize, bytes; 122 long fsize, bytes;
128 m_position = m_lineBreakPosition = &m_data[0]; 128 m_position = m_lineBreakPosition = &m_data[0];
129 bytes = fread (m_data, 1, fsize, fp); 129 bytes = fread (m_data, 1, fsize, fp);
130 ASSERT_GT_EQ (bytes, fsize) 130 ASSERT_GT_EQ (bytes, fsize)
131 } 131 }
132 132
133 // ============================================================================= 133 // _________________________________________________________________________________________________
134 // 134 //
135 LexerScanner::~LexerScanner() 135 LexerScanner::~LexerScanner()
136 { 136 {
137 delete m_data; 137 delete m_data;
138 } 138 }
139 139
140 // ============================================================================= 140 // _________________________________________________________________________________________________
141 // 141 //
142 bool LexerScanner::checkString (const char* c, int flags) 142 bool LexerScanner::checkString (const char* c, int flags)
143 { 143 {
144 bool r = strncmp (m_position, c, strlen (c)) == 0; 144 bool r = strncmp (m_position, c, strlen (c)) == 0;
145 145
152 m_position += strlen (c); 152 m_position += strlen (c);
153 153
154 return r; 154 return r;
155 } 155 }
156 156
157 // ============================================================================= 157 // _________________________________________________________________________________________________
158 // 158 //
159 bool LexerScanner::getNextToken() 159 bool LexerScanner::getNextToken()
160 { 160 {
161 m_tokenText = ""; 161 m_tokenText = "";
162 162
263 263
264 error ("unknown character \"%1\"", *m_position); 264 error ("unknown character \"%1\"", *m_position);
265 return false; 265 return false;
266 } 266 }
267 267
268 // ============================================================================= 268 // _________________________________________________________________________________________________
269 // 269 //
270 void LexerScanner::skip() 270 void LexerScanner::skip()
271 { 271 {
272 if (*m_position == '\n') 272 if (*m_position == '\n')
273 { 273 {
276 } 276 }
277 277
278 m_position++; 278 m_position++;
279 } 279 }
280 280
281 // ============================================================================= 281 // _________________________________________________________________________________________________
282 // 282 //
283 void LexerScanner::skip (int chars) 283 void LexerScanner::skip (int chars)
284 { 284 {
285 for (int i = 0; i < chars; ++i) 285 for (int i = 0; i < chars; ++i)
286 skip(); 286 skip();
287 } 287 }
288 288
289 // ============================================================================= 289 // _________________________________________________________________________________________________
290 // 290 //
291 String LexerScanner::GetTokenString (Token a) 291 String LexerScanner::GetTokenString (Token a)
292 { 292 {
293 ASSERT_LT_EQ (a, LastNamedToken); 293 ASSERT_LT_EQ (a, LastNamedToken);
294 return gTokenStrings[int (a)]; 294 return gTokenStrings[int (a)];
295 } 295 }
296 296
297 // ============================================================================= 297 // _________________________________________________________________________________________________
298 // 298 //
299 String LexerScanner::readLine() 299 String LexerScanner::readLine()
300 { 300 {
301 String line; 301 String line;
302 302

mercurial