A template class that parses text and throws meaningful error messages.
More...
#include <jade.scanner.hpp>
|
| basic_scanner (istream_type &in) |
| Initializes a new instance of the class to scan the specified stream. More...
|
|
| basic_scanner (const string_type &in) |
| Initializes a new instance of the class to scan the specified string. More...
|
|
void | expect (const char_type ch) |
| Skips whitespace and validates the next symbol in the stream matches the specified character. If the validation fails, this method throws an exception with a meaningful error message. More...
|
|
bool | is_end_of_data () const |
|
void | read_digits (ostream_type &out) |
| Reads a series of digits from the stream and copies them to the specified output stream. This method does not skip whitespace before or after reading the digits. More...
|
|
double | read_double () |
| Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message. More...
|
|
float | read_float () |
| Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message. More...
|
|
template<typename TValue > |
TValue | read_real () |
| Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message. More...
|
|
string_type | read_token (char_type const *const delimeters=nullptr) |
| Reads and returns a series of characters terminated by the end of the input stream or a specified delimeter. If no delimeters are unspecified, then the method uses whitespace as the delimeters. More...
|
|
void | skip_whitespace () |
| Skips whitespace from the input stream. If the input stream indicates the end of the stream, the method returns without an error. More...
|
|
bool | try_char (const char_type ch) |
| Skips whitespace and then checks if the next character from the stream matches the specified character. If it does, the method advances the stream past the character and returns true; otherwise, the method returns false. More...
|
|
template<typename TChar>
class jade::basic_scanner< TChar >
A template class that parses text and throws meaningful error messages.
Definition at line 18 of file jade.scanner.hpp.
◆ char_traits_type
template<typename TChar >
◆ char_type
template<typename TChar >
◆ istream_type
template<typename TChar >
◆ istringstream_type
template<typename TChar >
◆ ostream_type
template<typename TChar >
◆ ostringstream_type
template<typename TChar >
◆ string_type
template<typename TChar >
◆ basic_scanner() [1/2]
template<typename TChar >
Initializes a new instance of the class to scan the specified stream.
- Parameters
-
Definition at line 46 of file jade.scanner.hpp.
◆ basic_scanner() [2/2]
template<typename TChar >
Initializes a new instance of the class to scan the specified string.
- Parameters
-
Definition at line 57 of file jade.scanner.hpp.
◆ expect()
template<typename TChar >
Skips whitespace and validates the next symbol in the stream matches the specified character. If the validation fails, this method throws an exception with a meaningful error message.
- Exceptions
-
jade::error | Thrown if the stream provides an unexpected symbol. |
- Parameters
-
ch | The expected character. |
Definition at line 72 of file jade.scanner.hpp.
83 const auto actual = _in.peek();
86 <<
"expected symbol '" <<
char_type(ch) <<
"' "
87 <<
"but encountered end of stream";
100 <<
"expected symbol '" <<
char_type(ch) <<
"' "
101 <<
"but encountered symbol '"
105 <<
"expected symbol '" <<
char_type(ch) <<
"' "
106 <<
"but encountered ASCII code " << actual;
◆ is_end_of_data()
template<typename TChar >
- Returns
- True if all data has been read from the scanner.
Definition at line 112 of file jade.scanner.hpp.
114 return _in.peek() < 0;
◆ read_digits()
template<typename TChar >
Reads a series of digits from the stream and copies them to the specified output stream. This method does not skip whitespace before or after reading the digits.
- Parameters
-
Definition at line 122 of file jade.scanner.hpp.
125 while (::isdigit(_in.peek()))
◆ read_double()
template<typename TChar >
Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message.
- Returns
- A floating-point value.
- Exceptions
-
jade::error | Thrown if there is an error parsing the length. |
Definition at line 139 of file jade.scanner.hpp.
141 return read_real<double>();
◆ read_float()
template<typename TChar >
Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message.
- Returns
- A floating-point value.
- Exceptions
-
jade::error | Thrown if there is an error parsing the length. |
Definition at line 154 of file jade.scanner.hpp.
156 return read_real<float>();
◆ read_real()
template<typename TChar >
template<typename TValue >
Skips whitespace and then parses and returns a floating-point value from the specified stream. If there is an error parsing the value, the method throws an exception with a meaningful error message.
- Returns
- A floating-point value.
- Exceptions
-
jade::error | Thrown if there is an error parsing the length. |
Definition at line 170 of file jade.scanner.hpp.
172 static const auto hyphen =
char_type(
'-');
173 static const auto period =
char_type(
'.');
205 const auto length_str = out.str();
206 if (length_str.empty())
208 "expected a floating-point value but "
209 "did not encounter any digits");
217 if (length_in >> length)
220 <<
"expected a length but encountered '"
221 << length_str <<
"'";
◆ read_token()
template<typename TChar >
Reads and returns a series of characters terminated by the end of the input stream or a specified delimeter. If no delimeters are unspecified, then the method uses whitespace as the delimeters.
- Parameters
-
delimeters | The delimeters, or nullptr. |
- Returns
- The token.
Definition at line 232 of file jade.scanner.hpp.
245 const auto delims = delimeters ==
nullptr ? fallback : delimeters;
246 const auto length = char_traits_type::length(delims);
252 auto ch = _in.peek();
254 if (ch < 0 ||
nullptr != char_traits_type::find(
◆ skip_whitespace()
template<typename TChar >
Skips whitespace from the input stream. If the input stream indicates the end of the stream, the method returns without an error.
Definition at line 267 of file jade.scanner.hpp.
269 while (::isspace(_in.peek()))
◆ try_char()
template<typename TChar >
Skips whitespace and then checks if the next character from the stream matches the specified character. If it does, the method advances the stream past the character and returns true; otherwise, the method returns false.
- Returns
- True if encountering the character; otherwise, false.
- Parameters
-
Definition at line 281 of file jade.scanner.hpp.
293 if (ch != _in.peek())
The documentation for this class was generated from the following file: