QtNovelUI/libParse/LexFoundation.h

77 lines
1.4 KiB
C
Raw Normal View History

2022-11-17 08:26:05 +00:00
#pragma once
#include <QString>
#include <QList>
namespace Lex {
class LexFoundation;
/**
* .
*/
struct LexDef
{
QString TokenType; // Token字符
QString RegExpression; // 词法解析表达式
};
/**
* .
*/
struct LexResult
{
QString Token; // Token字符
QString Text; // 内容
int StartRow, StartCol, EndRow, EndCol; // 波及范围
friend class LexFoundation;
private:
int index_at_segment;
};
/**
* .
*/
class XChar
{
public:
explicit XChar(QChar c, int row, int col);
QChar value() const;
int row() const;
int col() const;
private:
QChar value_store;
int row_index, col_index;
};
/**
* .
*/
class LexFoundation
{
public:
explicit LexFoundation(QList<LexDef> seqence, const QString UnknownToken);
virtual ~LexFoundation() = default;
/**
* .
*
* \param row
* \param col
* \param w
* \return
*/
QList<LexResult> push(int row, int col, const QChar w);
private:
QString unknown_token;
QList<QChar> empty_seq;
QList<XChar> code_acc;
QList<LexDef> lexical_seq;
QList<LexResult> lexical_parse(const QString &segment);
};
}