17 #ifndef NURIA_TOKENIZER_HPP
18 #define NURIA_TOKENIZER_HPP
20 #include "essentials.hpp"
21 #include <QSharedData>
29 class TokenizerRulesPrivate;
30 class TokenizerPrivate;
47 struct NURIA_CORE_EXPORT
Token {
48 Token (
int tokenId = -1,
int row = 0,
int column = 0,
49 const QVariant &value = QVariant ())
50 : row (row), column (column), tokenId (tokenId), value (value)
66 bool operator< (
const Token &right)
const;
102 AutoHandleWhitespace = 0,
105 ManualWhitespaceHandling
127 void addStringToken (
int tokenId,
const QByteArray &terminal);
136 void addRegexToken (
int tokenId,
const QByteArray ®ularExpression);
141 void addRegexToken (
int tokenId,
const std::regex ®ularExpression);
161 void setTokenAction (
int tokenId, TokenAction action);
171 QSharedDataPointer< TokenizerRulesPrivate > d;
248 void addTokenizerRules (
const QString &name,
const TokenizerRules &ruleSet);
259 void removeTokenizerRules (
const QString &name);
265 void setCurrentTokenizerRules (
const QString &name);
274 void tokenize (
const QByteArray &data);
279 QByteArray tokenizeData ()
const;
303 bool hasError ()
const;
306 int errorColumn ()
const;
309 int errorRow ()
const;
312 int errorPosition ()
const;
315 int currentColumn ()
const;
318 int currentRow ()
const;
321 int currentPosition ()
const;
328 void setPosition (
int position,
int column,
int row);
332 void advanceLocation (
char c);
333 void skipWhitespace ();
335 bool readAndHandleTokens ();
336 bool checkStringToken ();
337 bool checkStringToken (
const QByteArray &token,
int tok);
338 bool checkRegexToken ();
339 bool checkRegexToken (
const std::regex ®ex,
int tok);
341 TokenizerPrivate *d_ptr;
347 NURIA_CORE_EXPORT QDebug operator<< (QDebug debug,
const Nuria::Token &token);
349 #endif // NURIA_TOKENIZER_HPP
std::function< bool(Token &, Tokenizer *) > TokenAction
Definition: tokenizer.hpp:110
int column
Definition: tokenizer.hpp:60
int tokenId
Definition: tokenizer.hpp:54
WhitespaceMode
Definition: tokenizer.hpp:99
QVariant value
Definition: tokenizer.hpp:63
Definition: abstractsessionmanager.hpp:24
Storage of rules used by Nuria::Tokenizer.
Definition: tokenizer.hpp:95
int row
Definition: tokenizer.hpp:57
Token as returned by Nuria::Tokenizer.
Definition: tokenizer.hpp:47
General-purpose run-time tokenizer.
Definition: tokenizer.hpp:231