5#include <unordered_map>
54 std::vector<Token> tokens;
60 if (std::isdigit(c)) {
62 }
else if (c ==
'\\' || std::isalpha(c)) {
65 std::string s(1,
get());
95 while (!
eof() && std::isspace(
peek()))
101 bool has_dot =
false;
103 while (!
eof() && (std::isdigit(
peek()) ||
peek() ==
'.')) {
104 if (
peek() ==
'.') has_dot =
true;
116 if (
peek() ==
'\\') s +=
get();
118 while (!
eof() && (std::isalpha(
peek()) ||
peek() ==
'_')) {
131 return Token(tok->second, s);
138 inline static const std::unordered_map<std::string, TokenType>
SyntaxTable = {
139 {
"+",
TokenType::plus}, {
"-",
TokenType::minus}, {
"*",
TokenType::mult}, {
"/",
TokenType::div}, {
"^",
TokenType::pow},
146 inline static const std::unordered_map<std::string, GreekSymbolminus>
GreekMapLower = {
161 inline static const std::unordered_map<std::string, GreekSymbolplus>
GreekMapUpper = {
TokenType
Definition Latex.hpp:8
GreekSymbolminus
Definition Latex.hpp:18
GreekSymbolplus
Definition Latex.hpp:26
size_t pos
Definition Latex.hpp:80
char peek() const
Definition Latex.hpp:82
static const std::unordered_map< std::string, GreekSymbolplus > GreekMapUpper
Definition Latex.hpp:161
std::string input
Definition Latex.hpp:79
char get()
Definition Latex.hpp:86
void skipWhitespace()
Definition Latex.hpp:94
static const std::unordered_map< std::string, TokenType > SyntaxTable
Definition Latex.hpp:138
static const std::unordered_map< std::string, GreekSymbolminus > GreekMapLower
Definition Latex.hpp:146
Token parseNumber()
Definition Latex.hpp:99
bool eof() const
Definition Latex.hpp:90
Token parseCommandOrSymbol()
Definition Latex.hpp:114
Lexer(const std::string &input)
Definition Latex.hpp:51
std::vector< Token > tokenize()
Definition Latex.hpp:53
std::string value
Definition Latex.hpp:39
TokenType type
Definition Latex.hpp:36
Token(TokenType t, const std::string &val)
Definition Latex.hpp:41
GreekSymbolplus greek_plus
Definition Latex.hpp:38
Token(TokenType t, GreekSymbolminus g, GreekSymbolplus G, const std::string &val)
Definition Latex.hpp:44
GreekSymbolminus greek_minus
Definition Latex.hpp:37