mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Replace lexertl with a custom lexeter implementation
QueryLexeter does not parse "atWord" because I couldn't find what it is used for.
This commit is contained in:
59
YACReaderLibrary/db/query_lexer.h
Normal file
59
YACReaderLibrary/db/query_lexer.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef QUERY_LEXER_H
|
||||
#define QUERY_LEXER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Token
|
||||
{
|
||||
public:
|
||||
enum class Type {
|
||||
eof,
|
||||
opcode,
|
||||
atWord,
|
||||
word,
|
||||
quotedWord,
|
||||
space
|
||||
};
|
||||
|
||||
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 space();
|
||||
Token word();
|
||||
Token quotedWord();
|
||||
|
||||
bool isSpace(char c);
|
||||
};
|
||||
|
||||
#endif // QUERY_LEXER_H
|
Reference in New Issue
Block a user