58 lines
808 B
C++
58 lines
808 B
C++
#pragma once
|
|||
|
|
|
||
|
|
#include "engine/address.hpp"
|
||
|
|
#include "engine/value.hpp"
|
||
|
|
|
||
|
|
#include <cstddef>
|
||
|
|
#include <string>
|
||
|
|
#include <string_view>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
namespace htab {
|
||
|
|
|
||
|
|
enum class TokenKind {
|
||
|
|
Number,
|
||
|
|
String,
|
||
|
|
Bool,
|
||
|
|
Error,
|
||
|
|
CellRef,
|
||
|
|
Ident,
|
||
|
|
Colon,
|
||
|
|
Comma,
|
||
|
|
Plus,
|
||
|
|
Minus,
|
||
|
|
Star,
|
||
|
|
Slash,
|
||
|
|
Caret,
|
||
|
|
Percent,
|
||
|
|
Amp,
|
||
|
|
Eq,
|
||
|
|
Neq,
|
||
|
|
Lt,
|
||
|
|
Gt,
|
||
|
|
Le,
|
||
|
|
Ge,
|
||
|
|
LParen,
|
||
|
|
RParen,
|
||
|
|
Eof,
|
||
|
|
Invalid,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Token {
|
||
|
|
TokenKind kind = TokenKind::Invalid;
|
||
|
|
std::string text;
|
||
|
|
size_t start = 0;
|
||
|
|
size_t end = 0;
|
||
|
|
bool had_space_before = false;
|
||
|
|
double num_val = 0.0;
|
||
|
|
bool bool_val = false;
|
||
|
|
ErrorCode err_val = ErrorCode::Value;
|
||
|
|
CellRef ref_val;
|
||
|
|
};
|
||
|
|
|
||
|
|
class Lexer {
|
||
|
|
public:
|
||
|
|
static std::vector<Token> tokenize(std::string_view input, bool skip_leading_equals = true);
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace htab
|