| 57 OpenFile (path); |
57 OpenFile (path); |
| 58 commentmode = 0; |
58 commentmode = 0; |
| 59 } |
59 } |
| 60 |
60 |
| 61 ScriptReader::~ScriptReader () { |
61 ScriptReader::~ScriptReader () { |
| 62 FinalChecks (); |
62 // If comment mode is 2 by the time the file ended, the |
| |
63 // comment was left unterminated. 1 is no problem, since |
| |
64 // it's terminated by newlines anyway. |
| |
65 if (commentmode == 2) |
| |
66 ParserError ("unterminated `/*`-style comment"); |
| 63 |
67 |
| 64 for (unsigned int u = 0; u < MAX_FILESTACK; u++) { |
68 for (unsigned int u = 0; u < MAX_FILESTACK; u++) { |
| 65 if (fp[u]) { |
69 if (fp[u]) { |
| 66 ParserWarning ("file idx %u remained open after parsing", u); |
70 ParserWarning ("file idx %u remained open after parsing", u); |
| 67 CloseFile (u); |
71 CloseFile (u); |
| 360 str num; |
364 str num; |
| 361 if (!fromthis) |
365 if (!fromthis) |
| 362 MustNext (); |
366 MustNext (); |
| 363 num += token; |
367 num += token; |
| 364 |
368 |
| 365 // Cater for a possible minus sign, since it |
369 // The number can possibly start off with a minus sign, which |
| 366 // breaks the token, read a new one with the number. |
370 // also breaks the token. If we encounter it, read another token |
| |
371 // and merge it to this one. |
| 367 if (!token.compare ("-")) { |
372 if (!token.compare ("-")) { |
| 368 MustNext (); |
373 MustNext (); |
| 369 num += token; |
374 num += token; |
| 370 } |
375 } |
| 371 |
376 |
| |
377 // Result must be a number. |
| 372 if (!num.isnumber()) |
378 if (!num.isnumber()) |
| 373 ParserError ("expected a number, got `%s`", num.chars()); |
379 ParserError ("expected a number, got `%s`", num.chars()); |
| 374 |
380 |
| |
381 // Save the number into the token. |
| 375 token = num; |
382 token = num; |
| 376 } |
383 } |
| 377 |
384 |
| 378 void ScriptReader::MustBool () { |
385 void ScriptReader::MustBool () { |
| 379 MustNext(); |
386 MustNext(); |
| 395 case RETURNVAL_INT: MustNumber (); break; |
402 case RETURNVAL_INT: MustNumber (); break; |
| 396 case RETURNVAL_STRING: MustString (); break; |
403 case RETURNVAL_STRING: MustString (); break; |
| 397 case RETURNVAL_BOOLEAN: MustBool (); break; |
404 case RETURNVAL_BOOLEAN: MustBool (); break; |
| 398 } |
405 } |
| 399 } |
406 } |
| 400 |
|
| 401 // Checks to be performed at the end of file |
|
| 402 void ScriptReader::FinalChecks () { |
|
| 403 // If comment mode is 2 by the time the file ended, the |
|
| 404 // comment was left unterminated. 1 is no problem, since |
|
| 405 // it's terminated by newlines anyway. |
|
| 406 if (commentmode == 2) |
|
| 407 ParserError ("unterminated `/*`-style comment"); |
|
| 408 } |
|