33 _tmpStringCapacity(16),
34 _formatName(formatName),
36 _bufferPos(_buffer.end()) {
54 if (*it == character) {
62 if (character == EOF && it == str)
63 got <<
"no more input";
65 got <<
'\"' << string(str, it);
66 if (isalnum(character))
67 got << static_cast<char>(character);
68 while (isalnum(
peek()))
69 got << static_cast<char>(
getChar());
88 ASSERT(a != got && b != got);
90 err << a <<
" or " << b;
97 expectedStr += expected;
113 while (isdigit(
peek())) {
136 while (isdigit(
peek())) {
159 for (
size_t i = 1; i < size; ++i)
175 if (!isdigit(
peek())) {
192 if (!isdigit(
peek())) {
209 if (
sizeof(
size_t) ==
sizeof(
unsigned int)) {
212 errorMsg <<
"expected non-negative integer of size at most "
213 << numeric_limits<unsigned int>::max()
217 size = (
unsigned int)
_integer.get_ui();
218 }
else if (
sizeof(
size_t) ==
sizeof(
unsigned long)) {
221 errorMsg <<
"expected non-negative integer of size at most "
222 << numeric_limits<unsigned long>::max()
230 "Frobby does not work on this machine due to an "
231 "unexpected technical issue.\n"
232 "Please contact the developers of Frobby about this.\n"
234 "Details that will be useful to the developers:\n"
235 " error location: Scanner::readSizeT\n"
236 " sizeof(size_t) = " <<
sizeof(size_t) <<
"\n"
237 " sizeof(unsigned int) = " <<
sizeof(
unsigned int) <<
"\n"
238 " sizeof(unsigned long) = " <<
sizeof(
unsigned long) <<
"\n";
246 char* str =
new char[newCapacity];
257 if (!isalpha(
peek()))
263 while (isalnum(
peek()) ||
peek() ==
'_') {
280 errorMsg <<
"Unknown variable \"" << name <<
"\". Maybe you forgot a *.";
285(
const string& expected,
int got) {
288 gotDescription <<
"no more input";
290 gotDescription <<
'\"' <<
static_cast<char>(got)<<
'\"';
295(
const string& expected,
const string& got) {
297 errorMsg <<
"Expected " << expected;
299 errorMsg <<
", but got " << got;
auto_ptr< IOHandler > createIOHandler(const string &prefix)
Returns an IOHandler for the format whose name has the given prefix.
string getFormatNameIndicatingToGuessTheInputFormat()
Using the returned string in place of an (input) format name indicates to guess the format based on w...
string autoDetectFormat(Scanner &in)
Return the format of what in is reading based on the first non-whitespace character.
static const size_t BufferSize
A replacement for stringstream.
auto_ptr< IOHandler > createIOHandler() const
int peek()
Returns the next character or EOF.
size_t readIntegerString()
Returns the size of the string.
size_t _tmpStringCapacity
void parseInteger(mpz_class &integer, size_t size)
Scanner(const string &formatName, FILE *in)
Construct a Scanner object.
void reportErrorUnexpectedToken(const string &expected, int got)
void eatWhite()
Reads past any whitespace, where whitespace is defined by the standard function isspace().
vector< char >::iterator _bufferPos
void errorReadIdentifier()
void expectEOF()
Require that there is no more input.
void readIntegerAndNegativeAsZero(mpz_class &integer)
Read an integer and set it to zero if it is negative.
void expect(char expected)
Require the next character to be equal to expected.
const char * readIdentifier()
The returned string is only valid until the next method on this object gets called.
void errorExpectTwo(char a, char b, int got)
void readSizeT(size_t &size)
Reads a size_t, where the representable range of that type determines when the number is too big.
const string & getFormat() const
void readInteger(mpz_class &integer)
Read an arbitrary-precision integer.
void errorExpectOne(char expected, int got)
void setFormat(const string &format)
void errorReadVariable(const char *name)
size_t readIntegerStringNoSign()
Returns the size of the string.
void reportInternalError(const string &errorMsg)
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)