1 #ifndef GENESIS_UTILS_IO_SCANNER_H_ 2 #define GENESIS_UTILS_IO_SCANNER_H_ 99 using T = std::underlying_type< SkipWhitespace >::type;
100 return static_cast< T
>( lhs ) & static_cast< T >( rhs );
117 template<
typename InputStream >
121 while( source && *source !=
'\n' ) {
133 template<
typename InputStream >
138 while( source && *source !=
'\n' ) {
152 template<
typename InputStream >
157 while( source && *source == criterion ) {
166 template<
typename InputStream >
169 std::function<
bool (
char)> criterion
171 while( source && criterion( *source )) {
183 template<
typename InputStream >
188 while( source && *source != criterion ) {
197 template<
typename InputStream >
200 std::function<
bool (
char)> criterion
202 while( source && ! criterion( *source )) {
215 template<
typename InputStream >
221 while( source && *source == criterion ) {
232 template<
typename InputStream >
235 std::function<
bool (
char)> criterion
238 while( source && criterion( *source )) {
253 template<
typename InputStream >
259 while( source && *source != criterion ) {
270 template<
typename InputStream >
273 std::function<
bool (
char)> criterion
276 while( source && ! criterion( *source )) {
298 template<
typename InputStream >
310 if( !source || *source != criterion ) {
311 throw std::runtime_error(
313 "Expecting " +
char_to_hex( criterion ) +
" at " + source.
at() +
", " +
314 "but received " +
char_to_hex( *source ) +
" instead." 317 assert( source && *source == criterion );
339 template<
typename InputStream >
342 std::function<
bool (
char)> criterion,
351 if( !source || ! criterion( *source )) {
352 throw std::runtime_error(
354 "Unexpected char " +
char_to_hex( *source ) +
" at " + source.
at() +
"." 384 template<
typename InputStream >
396 if( !source || *source != criterion ) {
397 throw std::runtime_error(
399 "Expecting " +
char_to_hex( criterion ) +
" at " + source.
at() +
", " +
400 "but received " +
char_to_hex( *source ) +
" instead." 421 template<
typename InputStream >
424 std::function<
bool (
char)> criterion,
433 if( !source || ! criterion( *source )) {
434 throw std::runtime_error(
436 "Unexpected char " +
char_to_hex( *source ) +
" at " + source.
at() +
"." 449 #endif // include guard Skip no whitespace. Thus, immediately treat the current input char.
void skip_while(InputStream &source, char criterion)
Lexing function that advances the stream while its current char equals the provided one...
Skip all whitespace in the input stream, then treat the next non-white char.
std::string read_to_end_of_line(InputStream &source)
Lexing function that reads until the end of the line (i.e., to the new line char), and returns the read chars (excluding the new line char).
std::string char_to_hex(char c, bool full)
Return the name and hex representation of a char.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
SkipWhitespace
Option to determine how to treat surrounding whitespace when scanning an input stream.
void skip_to_end_of_line(InputStream &source)
Lexing function that advances the stream to the end of the line, i.e., to the new line char...
std::string read_while(InputStream &source, char criterion)
Lexing function that reads from the stream while its current char equals the provided one...
Treat the current char in the input stream, then skip the following whitespace.
Skip whitespace, treat the first non-white char, then skip all following whitespace.
void affirm_char_or_throw(InputStream &source, char criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
Lexing function that checks whether the current char from the stream equals the provided one...
char read_char_or_throw(InputStream &source, char criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
Lexing function that reads a single char from the stream and checks whether it equals the provided on...
std::string read_until(InputStream &source, char criterion)
Lexing function that reads from the stream until its current char equals the provided one...
void skip_until(InputStream &source, char criterion)
Lexing function that advances the stream until its current char equals the provided one...
constexpr bool operator&(SkipWhitespace lhs, SkipWhitespace rhs) noexcept
And-operator to check whether a SkipWhitespace is set.