You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
648 B
44 lines
648 B
2 years ago
|
/*
|
||
|
* Copyright (C) 2022 Riyyi
|
||
|
*
|
||
|
* SPDX-License-Identifier: MIT
|
||
|
*/
|
||
|
|
||
|
#ifndef UTIL_GENERIC_LEXER_H
|
||
|
#define UTIL_GENERIC_LEXER_H
|
||
|
|
||
|
#include <cassert> // assert
|
||
|
#include <cstddef> // size_t
|
||
|
#include <string_view>
|
||
|
|
||
|
namespace Util {
|
||
|
|
||
|
class GenericLexer {
|
||
|
public:
|
||
|
GenericLexer(std::string_view input);
|
||
|
virtual ~GenericLexer();
|
||
|
|
||
|
// Position
|
||
|
|
||
|
size_t tell() const;
|
||
|
bool isEOF() const;
|
||
|
|
||
|
// Access
|
||
|
|
||
|
char peek(size_t offset = 0) const;
|
||
|
|
||
|
// Modifiers
|
||
|
|
||
|
void ignore(size_t count = 1);
|
||
|
void retreat(size_t count = 1);
|
||
|
char consume();
|
||
|
|
||
|
protected:
|
||
|
size_t m_index { 0 };
|
||
|
std::string_view m_input;
|
||
|
};
|
||
|
|
||
|
} // namespace Util
|
||
|
|
||
|
#endif // UTIL_GENERIC_LEXER_H
|