改进接口
This commit is contained in:
parent
19985a4bb7
commit
740e7b0bef
|
@ -18,10 +18,6 @@ QString ExpressionElement::filePath() const {
|
||||||
return tokens_bind.first()->file();
|
return tokens_bind.first()->file();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionElement::tokensReset(const QList<std::shared_ptr<const IToken>>& list) {
|
|
||||||
this->tokens_bind = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExpressionElement::addToken(std::shared_ptr<const IToken> token_inst) {
|
void ExpressionElement::addToken(std::shared_ptr<const IToken> token_inst) {
|
||||||
this->tokens_bind.append(token_inst);
|
this->tokens_bind.append(token_inst);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +83,7 @@ void ExpressionContext::appendParseErrors(const QString& file_path, int start, c
|
||||||
QStringList ExpressionContext::errors() const {
|
QStringList ExpressionContext::errors() const {
|
||||||
QStringList values;
|
QStringList values;
|
||||||
for (auto& tp : this->errors_storage)
|
for (auto& tp : this->errors_storage)
|
||||||
values.append(QString(u8"%2\n\t文件(%1)").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
|
values.append(QString(u8"文件:%1\n\t%2").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,6 @@ namespace ast_basic {
|
||||||
* \return token序列
|
* \return token序列
|
||||||
*/
|
*/
|
||||||
virtual QList<std::shared_ptr<const lib_token::IToken>> tokens() const = 0;
|
virtual QList<std::shared_ptr<const lib_token::IToken>> tokens() const = 0;
|
||||||
/**
|
|
||||||
* 重置语法Token集.
|
|
||||||
*
|
|
||||||
* \param list
|
|
||||||
*/
|
|
||||||
virtual void tokensReset(const QList<std::shared_ptr<const lib_token::IToken>> &list) = 0;
|
|
||||||
/**
|
/**
|
||||||
* 解析过程中,向表达式内部添加token实例.
|
* 解析过程中,向表达式内部添加token实例.
|
||||||
*
|
*
|
||||||
|
@ -77,7 +71,6 @@ namespace ast_basic {
|
||||||
QString filePath() const override;
|
QString filePath() const override;
|
||||||
|
|
||||||
QList<std::shared_ptr<const lib_token::IToken>> tokens() const override;
|
QList<std::shared_ptr<const lib_token::IToken>> tokens() const override;
|
||||||
void tokensReset(const QList<std::shared_ptr<const lib_token::IToken>>& list) override;
|
|
||||||
void addToken(std::shared_ptr<const lib_token::IToken> token_inst) override;
|
void addToken(std::shared_ptr<const lib_token::IToken> token_inst) override;
|
||||||
|
|
||||||
QList<std::shared_ptr<const IExprInst>> children() const override;
|
QList<std::shared_ptr<const IExprInst>> children() const override;
|
||||||
|
|
|
@ -23,8 +23,8 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> TokenMatch
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rt_inst->appendParseErrors(rt_inst->currentFile(), head->position(),
|
rt_inst->appendParseErrors(rt_inst->currentFile(), head->position(),
|
||||||
QString(u8"Syntax[0x00001]语法匹配错误,不能识别token:%1<%2,%3>(%4)")
|
QString(u8"Syntax[0x00001]语法匹配错误,不能识别token\"%1\"<row:%2,col:%3>(应该为:%4)")
|
||||||
.arg(head->content()).arg(head->row()).arg(head->column()).arg(head->file()));
|
.arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords()));
|
||||||
return std::make_tuple(IBasicRule::MatchResult::Part, head);
|
return std::make_tuple(IBasicRule::MatchResult::Part, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> TokenMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TokenMatch::token_present() const {
|
QString TokenMatch::token_present() const {
|
||||||
return QString(u8"<%1>").arg(this->define_peer->typeName());
|
return QString(u8"<%1>").arg(this->define_peer->reviseWords());
|
||||||
}
|
}
|
||||||
|
|
||||||
Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {}
|
Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {}
|
||||||
|
|
|
@ -13,12 +13,12 @@ auto rightb = std::make_shared<RightBracket>(); // }
|
||||||
auto refers = std::make_shared<ReferMark>(); // @
|
auto refers = std::make_shared<ReferMark>(); // @
|
||||||
auto declare = std::make_shared<DeclareSymbo>(); // #
|
auto declare = std::make_shared<DeclareSymbo>(); // #
|
||||||
|
|
||||||
auto rank_key = std::make_shared<Keywords>(u8"排序", u8"rank-symbol", 0xAEu); // 排序
|
auto rank_key = std::make_shared<Keywords>(u8"排序", 0xAEu); // 排序
|
||||||
auto story_key = std::make_shared<Keywords>(u8"故事", u8"story-mark", 0xAAu); // 故事
|
auto story_key = std::make_shared<Keywords>(u8"故事", 0xAAu); // 故事
|
||||||
auto numbers = std::make_shared<Numbers>(); // [0-9]+
|
auto numbers = std::make_shared<Numbers>(); // [0-9]+
|
||||||
auto frag_key = std::make_shared<Keywords>(u8"情节", u8"fragment-mark", 0xABu); // 情节
|
auto frag_key = std::make_shared<Keywords>(u8"情节", 0xABu); // 情节
|
||||||
auto volume_key = std::make_shared<Keywords>(u8"分卷", u8"volume-mark", 0xACu); // 分卷
|
auto volume_key = std::make_shared<Keywords>(u8"分卷", 0xACu); // 分卷
|
||||||
auto article_key = std::make_shared<Keywords>(u8"章节", u8"article-mark", 0xADu); // 章节
|
auto article_key = std::make_shared<Keywords>(u8"章节", 0xADu); // 章节
|
||||||
auto split_mark = std::make_shared<Split>(); // &
|
auto split_mark = std::make_shared<Split>(); // &
|
||||||
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}\\n@&]+)
|
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}\\n@&]+)
|
||||||
auto name_text = std::make_shared<NameSection>(); // ^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)
|
auto name_text = std::make_shared<NameSection>(); // ^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace lib_token {
|
||||||
* @brief 解析机制名称
|
* @brief 解析机制名称
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual QString typeName() const = 0;
|
virtual QString reviseWords() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief 整数类型标识.
|
* @brief 整数类型标识.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,7 +26,7 @@ std::shared_ptr<const IWordBase> lib_token::TokenContent::nextWord() const
|
||||||
|
|
||||||
std::shared_ptr<const ITokenDefine> TokenContent::define() const { return this->type_def; }
|
std::shared_ptr<const ITokenDefine> TokenContent::define() const { return this->type_def; }
|
||||||
|
|
||||||
QString LeftBracket::typeName() const { return u8"left-bracket"; }
|
QString LeftBracket::reviseWords() const { return u8"{"; }
|
||||||
|
|
||||||
int LeftBracket::typeMark() const
|
int LeftBracket::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ LeftBracket::analysis(std::shared_ptr<const IWordBase> content) const {
|
||||||
return std::make_tuple(token_inst, nullptr);
|
return std::make_tuple(token_inst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RightBracket::typeName() const { return u8"right-bracket"; }
|
QString RightBracket::reviseWords() const { return u8"}"; }
|
||||||
|
|
||||||
int RightBracket::typeMark() const
|
int RightBracket::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ int RightBracket::typeMark() const
|
||||||
|
|
||||||
QString RightBracket::regex() const { return u8"}"; }
|
QString RightBracket::regex() const { return u8"}"; }
|
||||||
|
|
||||||
QString ReferMark::typeName() const { return u8"refer-mark"; }
|
QString ReferMark::reviseWords() const { return u8"@"; }
|
||||||
|
|
||||||
int ReferMark::typeMark() const
|
int ReferMark::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -71,9 +71,9 @@ int ReferMark::typeMark() const
|
||||||
|
|
||||||
QString ReferMark::regex() const { return u8"@"; }
|
QString ReferMark::regex() const { return u8"@"; }
|
||||||
|
|
||||||
Keywords::Keywords(const QString& val, const QString& nm, uint type_code) : means_store(val), name_store(nm), type_code(type_code) {}
|
Keywords::Keywords(const QString& val, uint type_code) : means_store(val), type_code(type_code) {}
|
||||||
|
|
||||||
QString Keywords::typeName() const { return name_store; }
|
QString Keywords::reviseWords() const { return means_store; }
|
||||||
|
|
||||||
int Keywords::typeMark() const
|
int Keywords::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ Keywords::analysis(std::shared_ptr<const IWordBase> content) const {
|
||||||
return std::make_tuple(token_inst, nullptr);
|
return std::make_tuple(token_inst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Numbers::typeName() const { return u8"numbers"; }
|
QString Numbers::reviseWords() const { return u8"ÕýÕûÊý"; }
|
||||||
|
|
||||||
int Numbers::typeMark() const
|
int Numbers::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -114,7 +114,7 @@ Numbers::analysis(std::shared_ptr<const IWordBase> content) const {
|
||||||
return std::make_tuple(tinst, nullptr);
|
return std::make_tuple(tinst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VTextSection::typeName() const { return u8"text-section"; }
|
QString VTextSection::reviseWords() const { return u8"Îı¾"; }
|
||||||
|
|
||||||
int VTextSection::typeMark() const
|
int VTextSection::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ VTextSection::analysis(std::shared_ptr<const IWordBase> content) const {
|
||||||
return std::make_tuple(tinst, nullptr);
|
return std::make_tuple(tinst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Split::typeName() const { return u8"split-mark"; }
|
QString Split::reviseWords() const { return u8"&"; }
|
||||||
|
|
||||||
int Split::typeMark() const
|
int Split::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -153,7 +153,7 @@ int Split::typeMark() const
|
||||||
|
|
||||||
QString Split::regex() const { return u8"&"; }
|
QString Split::regex() const { return u8"&"; }
|
||||||
|
|
||||||
QString NameSection::typeName() const { return u8"name-section"; }
|
QString NameSection::reviseWords() const { return u8"Ãû³Æ"; }
|
||||||
|
|
||||||
int NameSection::typeMark() const
|
int NameSection::typeMark() const
|
||||||
{
|
{
|
||||||
|
@ -183,8 +183,7 @@ std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IWordBase> > Nam
|
||||||
return std::make_tuple(tinst, nullptr);
|
return std::make_tuple(tinst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeclareSymbo::typeName() const
|
QString DeclareSymbo::reviseWords() const {
|
||||||
{
|
|
||||||
return u8"ÉùÃ÷·û";
|
return u8"ÉùÃ÷·û";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace example_novel {
|
||||||
class LIBTOKEN_EXPORT LeftBracket : public lib_token::ITokenDefine, public std::enable_shared_from_this<LeftBracket> {
|
class LIBTOKEN_EXPORT LeftBracket : public lib_token::ITokenDefine, public std::enable_shared_from_this<LeftBracket> {
|
||||||
// TokenDefine interface
|
// TokenDefine interface
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
@ -48,36 +48,36 @@ namespace example_novel {
|
||||||
|
|
||||||
class LIBTOKEN_EXPORT RightBracket : public LeftBracket {
|
class LIBTOKEN_EXPORT RightBracket : public LeftBracket {
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBTOKEN_EXPORT ReferMark : public LeftBracket {
|
class LIBTOKEN_EXPORT ReferMark : public LeftBracket {
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBTOKEN_EXPORT Split : public LeftBracket {
|
class LIBTOKEN_EXPORT Split : public LeftBracket {
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBTOKEN_EXPORT Keywords : public lib_token::ITokenDefine, public std::enable_shared_from_this<Keywords> {
|
class LIBTOKEN_EXPORT Keywords : public lib_token::ITokenDefine, public std::enable_shared_from_this<Keywords> {
|
||||||
private:
|
private:
|
||||||
QString means_store, name_store;
|
QString means_store;
|
||||||
int type_code;
|
int type_code;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Keywords(const QString& val, const QString& nm, uint type_code);
|
Keywords(const QString& val, uint type_code);
|
||||||
|
|
||||||
// TokenDefine interface
|
// TokenDefine interface
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
@ -87,7 +87,7 @@ namespace example_novel {
|
||||||
class LIBTOKEN_EXPORT Numbers : public lib_token::ITokenDefine, public std::enable_shared_from_this<Numbers> {
|
class LIBTOKEN_EXPORT Numbers : public lib_token::ITokenDefine, public std::enable_shared_from_this<Numbers> {
|
||||||
// TokenDefine interface
|
// TokenDefine interface
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
@ -98,7 +98,7 @@ namespace example_novel {
|
||||||
class LIBTOKEN_EXPORT NameSection : public lib_token::ITokenDefine, public std::enable_shared_from_this<NameSection> {
|
class LIBTOKEN_EXPORT NameSection : public lib_token::ITokenDefine, public std::enable_shared_from_this<NameSection> {
|
||||||
// TokenDefine interface
|
// TokenDefine interface
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
@ -108,7 +108,7 @@ namespace example_novel {
|
||||||
class LIBTOKEN_EXPORT VTextSection : public lib_token::ITokenDefine, public std::enable_shared_from_this<VTextSection> {
|
class LIBTOKEN_EXPORT VTextSection : public lib_token::ITokenDefine, public std::enable_shared_from_this<VTextSection> {
|
||||||
// TokenDefine interface
|
// TokenDefine interface
|
||||||
public:
|
public:
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
@ -118,7 +118,7 @@ namespace example_novel {
|
||||||
class LIBTOKEN_EXPORT DeclareSymbo : public lib_token::ITokenDefine, public std::enable_shared_from_this<DeclareSymbo> {
|
class LIBTOKEN_EXPORT DeclareSymbo : public lib_token::ITokenDefine, public std::enable_shared_from_this<DeclareSymbo> {
|
||||||
public:
|
public:
|
||||||
// ͨ¹ý TokenDefine ¼Ì³Ð
|
// ͨ¹ý TokenDefine ¼Ì³Ð
|
||||||
virtual QString typeName() const override;
|
virtual QString reviseWords() const override;
|
||||||
virtual int typeMark() const override;
|
virtual int typeMark() const override;
|
||||||
virtual QString regex() const override;
|
virtual QString regex() const override;
|
||||||
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
virtual std::tuple<std::shared_ptr<const lib_token::IToken>, std::shared_ptr<const lib_token::IWordBase>>
|
||||||
|
|
Loading…
Reference in New Issue