55 lines
901 B
C++
55 lines
901 B
C++
#ifndef LEXER_H
|
|
#define LEXER_H
|
|
|
|
#include <string>
|
|
#include <stdexcept>
|
|
#include <cstddef>
|
|
|
|
class SyntaxError : public std::runtime_error {
|
|
public:
|
|
int row;
|
|
int col;
|
|
|
|
SyntaxError(const std::string& msg, int row_, int col_)
|
|
: std::runtime_error(msg), row(row_), col(col_) {}
|
|
};
|
|
|
|
|
|
class Lexer {
|
|
public:
|
|
int row;
|
|
int col;
|
|
|
|
explicit Lexer(std::string input);
|
|
|
|
Lexer& mark();
|
|
|
|
std::string extract(int ofs);
|
|
std::string extract();
|
|
|
|
char peek(int ahead) const;
|
|
char peek() const;
|
|
|
|
char advance();
|
|
|
|
bool advanceIf(char ch);
|
|
void advance(char ch);
|
|
|
|
|
|
bool skipWhitespace();
|
|
|
|
std::string readTo(char delimiter);
|
|
|
|
std::string readAlphanumeric();
|
|
|
|
std::string readDigits(int radix);
|
|
|
|
private:
|
|
std::string input_;
|
|
std::size_t pos_;
|
|
std::size_t start_;
|
|
|
|
static int digitValue(char c, int radix);
|
|
};
|
|
|
|
#endif // LEXER_H
|