This class offers an input interface which is more convenient and for some purposes more efficient than dealing with a FILE* directly.
More...
|
| | Scanner (const string &formatName, FILE *in) |
| | Construct a Scanner object.
|
| | ~Scanner () |
| const string & | getFormat () const |
| void | setFormat (const string &format) |
| unique_ptr< IOHandler > | createIOHandler () const |
| bool | match (char c) |
| | Return true if the next character is c, and in that case skip past it.
|
| bool | matchEOF () |
| | Return true if no more input.
|
| void | expect (char expected) |
| | Require the next character to be equal to expected.
|
| void | expect (char a, char b) |
| | Require the next character to be equal to a or b.
|
| void | expect (const char *str) |
| | Require the following characters to be equal to str.
|
| void | expect (const string &str) |
| | Require the following characters to be equal to str.
|
| void | expectEOF () |
| | Require that there is no more input.
|
| void | expectIntegerNoSign () |
| | Read an arbitrary-precision integer.
|
| void | readInteger (mpz_class &integer) |
| | Read an arbitrary-precision integer.
|
| void | readIntegerNoSign (string &str) |
| | Read an arbitrary-precision integer.
|
| void | readIntegerNoSign (mpz_class &str) |
| | Read an arbitrary-precision integer.
|
| void | readIntegerAndNegativeAsZero (mpz_class &integer) |
| | Read an integer and set it to zero if it is negative.
|
| void | readIntegerAndNegativeAsZero (std::string &integer) |
| | Read an integer and set it to zero if it is negative.
|
| void | readSizeT (size_t &size) |
| | Reads a size_t, where the representable range of that type determines when the number is too big.
|
| const char * | readIdentifier () |
| | The returned string is only valid until the next method on this object gets called.
|
| void | readIdentifier (string &str) |
| | Reads an identifier into str.
|
| size_t | readVariable (const VarNames &names) |
| | Reads an identifier and returns the index of that identifier as the index of a variable in names.
|
| bool | peekIdentifier () |
| | Skips whitespace and returns true if the next token is an identifier.
|
| bool | peekWhite () |
| | Returns true if the next character is whitespace.
|
| bool | peek (char character) |
| | Skips whitespace and returns true if the next character is equal to the parameter(s).
|
| unsigned int | getLineNumber () const |
| | Returns the number of newlines seen.
|
| int | peek () |
| | Returns the next character or EOF.
|
| void | eatWhite () |
| | Reads past any whitespace, where whitespace is defined by the standard function isspace().
|
This class offers an input interface which is more convenient and for some purposes more efficient than dealing with a FILE* directly.
It keeps track of the current line number to report better error messages. Only one Scanner should be reading from a given FILE*, since otherwise the line numbers will be inaccurate.
All input methods whose documentation does not specifically say otherwise skip whitespace as defined by the standard isspace() method.
There are four concepts for consuming input through a Scanner:
Read X: Require an X to be in the input, and return what is read.
Expect X: Require the exact value X to be in the input and skip past it.
Match X: Return true if the exact value X is in the input, and in that case skip past it. Otherwise return false and do nothing else.
Peek X: Return true if X is the next thing int he input. Do not skip past anything. May or may not skip whitespace depending on what X is.
If a requirement is not met, Scanner reports a syntax error using the functions in the error.h header.
Definition at line 50 of file Scanner.h.