QtNovelUI/DesParser/LexFoundation.h

77 lines
1.4 KiB
C
Raw Normal View History

2022-11-06 00:37:50 +00:00
#pragma once
#include <QString>
#include <QList>
namespace Lex {
2022-11-06 11:40:11 +00:00
class LexFoundation;
2022-11-06 00:37:50 +00:00
/**
* .
*/
2022-11-06 11:40:11 +00:00
struct LexDef
2022-11-06 00:37:50 +00:00
{
QString TokenType; // Token字符
QString RegExpression; // 词法解析表达式
};
/**
* .
*/
struct LexResult
{
QString Token; // Token字符
QString Text; // 内容
int StartRow, StartCol, EndRow, EndCol; // 波及范围
2022-11-06 11:40:11 +00:00
friend class LexFoundation;
2022-11-06 00:37:50 +00:00
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;
};
/**
* .
*/
2022-11-06 11:40:11 +00:00
class LexFoundation
2022-11-06 00:37:50 +00:00
{
public:
2022-11-06 11:40:11 +00:00
explicit LexFoundation(QList<LexDef> seqence, const QString UnknownToken);
virtual ~LexFoundation() = default;
2022-11-06 00:37:50 +00:00
/**
* .
*
* \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;
2022-11-06 11:40:11 +00:00
QList<LexDef> lexical_seq;
2022-11-06 00:37:50 +00:00
QList<LexResult> lexical_parse(const QString &segment);
};
2022-11-06 11:40:11 +00:00
}