yacreader/YACReaderLibrary/db/query_lexer.h
Luis Ángel San Martín f09c5955d8 Remove space and atWord tokens
`atWord` wasn't used at all and spaces should be eaten by the lexer

And added `unspecified` token
2021-01-14 08:39:16 +01:00

58 lines
798 B
C++

#ifndef QUERY_LEXER_H
#define QUERY_LEXER_H
#include <string>
class Token
{
public:
enum class Type {
eof,
opcode,
word,
quotedWord,
undefined
};
Token(Type type, std::string lexeme = "")
: _type(type), _lexeme(std::move(lexeme))
{
}
Type type() const
{
return _type;
}
std::string lexeme() const
{
return _lexeme;
}
private:
Type _type {};
std::string _lexeme {};
};
class QueryLexer
{
public:
QueryLexer(const std::string &input);
Token next();
private:
std::string input;
int index = 0;
char peek();
char get();
Token single(Token::Type type);
Token word();
Token quotedWord();
bool isSpace(char c);
};
#endif // QUERY_LEXER_H