使用预定义code取代string比较

This commit is contained in:
codeboss 2024-06-19 12:05:43 +08:00
parent 3c4662415f
commit 60c3f86ff0
9 changed files with 98 additions and 37 deletions

View File

@ -6,12 +6,12 @@
<LocalDebuggerCommandArguments>--path "D:\手作小说\科学+修仙+创造世界"</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.6534384Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:21.9792038Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.7471721Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.1198275Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>

View File

@ -5,12 +5,12 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.9815477Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.1667034Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:04.0440621Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.2604525Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>

View File

@ -5,12 +5,12 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.7784470Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.4167016Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.8565020Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.5104526Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>

View File

@ -12,7 +12,7 @@ QList<std::shared_ptr<const BaseRule>> TokenMatch::children() const { return QLi
std::tuple<BaseRule::MatchResult, uint, std::shared_ptr<const Token>> TokenMatch::match(std::shared_ptr<const Token> remains_head) const {
QString token_seqs = this->token_present();
if (remains_head && remains_head->define()->name() == define_peer->name())
if (remains_head && remains_head->define()->typeMark() == define_peer->typeMark())
return std::make_tuple(MatchResult::Success, 1, remains_head->nextToken());
return std::make_tuple(MatchResult::Fail, 0, nullptr);
@ -24,7 +24,7 @@ std::tuple<std::shared_ptr<const Expression>, std::shared_ptr<const Token>> Toke
if (!head)
throw std::make_shared<InputTerminal>();
if (head->define()->name() == define_peer->name()) {
if (head->define()->typeMark() == define_peer->typeMark()) {
rt_inst->currentInst()->addToken(head);
return std::make_tuple(nullptr, head->nextToken());
}
@ -33,7 +33,7 @@ std::tuple<std::shared_ptr<const Expression>, std::shared_ptr<const Token>> Toke
}
QString TokenMatch::token_present() const {
return QString(u8"<%1>").arg(this->define_peer->name());
return QString(u8"<%1>").arg(this->define_peer->typeName());
}
Rept::Rept(std::shared_ptr<const BaseRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {}

View File

@ -12,11 +12,11 @@ auto leftb = std::make_shared<LeftBracket>(); // {
auto rightb = std::make_shared<RightBracket>(); // }
auto refers = std::make_shared<ReferMark>(); // @
auto story_key = std::make_shared<Keywords>(u8"故事", u8"story-mark"); // 故事
auto story_key = std::make_shared<Keywords>(u8"故事", u8"story-mark", 0xAAu); // 故事
auto numbers = std::make_shared<Numbers>(); // [0-9]+
auto frag_key = std::make_shared<Keywords>(u8"情节", u8"fragment-mark"); // 情节
auto volume_key = std::make_shared<Keywords>(u8"分卷", u8"volume-mark"); // 分卷
auto article_key = std::make_shared<Keywords>(u8"章节", u8"article-mark"); // 章节
auto frag_key = std::make_shared<Keywords>(u8"情节", u8"fragment-mark", 0xABu); // 情节
auto volume_key = std::make_shared<Keywords>(u8"分卷", u8"volume-mark", 0xACu); // 分卷
auto article_key = std::make_shared<Keywords>(u8"章节", u8"article-mark", 0xADu); // 章节
auto split_mark = std::make_shared<Split>(); // &
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}\\n@&]+)
auto name_text = std::make_shared<NameSection>(); // ^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)
@ -53,7 +53,7 @@ QList<std::shared_ptr<const BaseRule>> LinesMerge(std::shared_ptr<const BaseRule
auto remove_nl = [](const ExpressionRule::TokenSeqs& p)->ExpressionRule::TokenSeqs {
ExpressionRule::TokenSeqs result;
for (auto& n : p) {
if (n->define()->name() == newl->name())
if (n->define()->typeMark() == newl->typeMark())
continue;
result.append(n);
}

View File

@ -2,12 +2,12 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.8877508Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.3229534Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-06-18T15:36:03.9502420Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-06-19T03:41:22.3698305Z</QtLastBackgroundBuild>
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>

View File

@ -68,7 +68,13 @@ namespace lib_token {
* @brief
* @return
*/
virtual QString name() const = 0;
virtual QString typeName() const = 0;
/**
* @brief .
*
* \return
*/
virtual int typeMark() const = 0;
/**
* @brief
* @return

View File

@ -3,7 +3,12 @@
using namespace example_novel;
using namespace lib_token;
QString LeftBracket::name() const { return u8"left-bracket"; }
QString LeftBracket::typeName() const { return u8"left-bracket"; }
int example_novel::LeftBracket::typeMark() const
{
return 0x01000000;
}
QString LeftBracket::regex() const { return u8"{"; }
@ -23,17 +28,32 @@ LeftBracket::analysis(std::shared_ptr<const WordBase> content) const {
return std::make_tuple(token_inst, nullptr);
}
QString RightBracket::name() const { return u8"right-bracket"; }
QString RightBracket::typeName() const { return u8"right-bracket"; }
int example_novel::RightBracket::typeMark() const
{
return 0x02000000;
}
QString RightBracket::regex() const { return u8"}"; }
QString ReferMark::name() const { return u8"refer-mark"; }
QString ReferMark::typeName() const { return u8"refer-mark"; }
int example_novel::ReferMark::typeMark() const
{
return 0x03000000;
}
QString ReferMark::regex() const { return u8"@"; }
Keywords::Keywords(const QString& val, const QString& nm) : value_store(val), name_store(nm) {}
Keywords::Keywords(const QString& val, const QString& nm, uint type_code) : value_store(val), name_store(nm), type_code(type_code) {}
QString Keywords::name() const { return name_store; }
QString Keywords::typeName() const { return name_store; }
int example_novel::Keywords::typeMark() const
{
return 0x06000000 | (0x00ffffff & type_code);
}
QString Keywords::regex() const { return value_store; }
@ -47,11 +67,21 @@ Keywords::analysis(std::shared_ptr<const WordBase> content) const {
return std::make_tuple(token_inst, nullptr);
}
QString NewLine::name() const { return u8"new-line"; }
QString NewLine::typeName() const { return u8"new-line"; }
int example_novel::NewLine::typeMark() const
{
return 0x04000000;
}
QString NewLine::regex() const { return u8"\n"; }
QString Numbers::name() const { return u8"numbers"; }
QString Numbers::typeName() const { return u8"numbers"; }
int example_novel::Numbers::typeMark() const
{
return 0x07000000;
}
QString Numbers::regex() const { return u8"^([0-9]+)$"; }
@ -66,7 +96,12 @@ Numbers::analysis(std::shared_ptr<const WordBase> content) const {
return std::make_tuple(tinst, nullptr);
}
QString VTextSection::name() const { return u8"text-section"; }
QString VTextSection::typeName() const { return u8"text-section"; }
int example_novel::VTextSection::typeMark() const
{
return 0x09000000;
}
QString VTextSection::regex() const { return u8"^([^\\{\\}\\n@&]+)"; }
@ -89,11 +124,21 @@ VTextSection::analysis(std::shared_ptr<const WordBase> content) const {
return std::make_tuple(tinst, nullptr);
}
QString Split::name() const { return u8"split-mark"; }
QString Split::typeName() const { return u8"split-mark"; }
int example_novel::Split::typeMark() const
{
return 0x05000000;
}
QString Split::regex() const { return u8"&"; }
QString NameSection::name() const { return u8"name-section"; }
QString NameSection::typeName() const { return u8"name-section"; }
int example_novel::NameSection::typeMark() const
{
return 0x08000000;
}
QString NameSection::regex() const { return u8"^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)"; }

View File

@ -11,7 +11,8 @@ namespace example_novel {
class LIBTOKEN_EXPORT LeftBracket : public lib_token::TokenDefine, public std::enable_shared_from_this<LeftBracket> {
// TokenDefine interface
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
virtual std::tuple<std::shared_ptr<const lib_token::Token>, std::shared_ptr<const lib_token::WordBase>>
analysis(std::shared_ptr<const lib_token::WordBase> content) const override;
@ -19,38 +20,44 @@ namespace example_novel {
class LIBTOKEN_EXPORT RightBracket : public LeftBracket {
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
};
class LIBTOKEN_EXPORT ReferMark : public LeftBracket {
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
};
class LIBTOKEN_EXPORT NewLine : public LeftBracket {
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
};
class LIBTOKEN_EXPORT Split : public LeftBracket {
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
};
class LIBTOKEN_EXPORT Keywords : public lib_token::TokenDefine, public std::enable_shared_from_this<Keywords> {
private:
QString value_store, name_store;
int type_code;
public:
Keywords(const QString& val, const QString& nm);
Keywords(const QString& val, const QString& nm, uint type_code);
// TokenDefine interface
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
virtual std::tuple<std::shared_ptr<const lib_token::Token>, std::shared_ptr<const lib_token::WordBase>>
analysis(std::shared_ptr<const lib_token::WordBase> content) const override;
@ -59,7 +66,8 @@ namespace example_novel {
class LIBTOKEN_EXPORT Numbers : public lib_token::TokenDefine, public std::enable_shared_from_this<Numbers> {
// TokenDefine interface
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
virtual std::tuple<std::shared_ptr<const lib_token::Token>, std::shared_ptr<const lib_token::WordBase>>
analysis(std::shared_ptr<const lib_token::WordBase> content) const override;
@ -69,7 +77,8 @@ namespace example_novel {
class LIBTOKEN_EXPORT NameSection : public lib_token::TokenDefine, public std::enable_shared_from_this<NameSection> {
// TokenDefine interface
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
virtual std::tuple<std::shared_ptr<const lib_token::Token>, std::shared_ptr<const lib_token::WordBase>>
analysis(std::shared_ptr<const lib_token::WordBase> content) const override;
@ -78,7 +87,8 @@ namespace example_novel {
class LIBTOKEN_EXPORT VTextSection : public lib_token::TokenDefine, public std::enable_shared_from_this<VTextSection> {
// TokenDefine interface
public:
virtual QString name() const override;
virtual QString typeName() const override;
virtual int typeMark() const override;
virtual QString regex() const override;
virtual std::tuple<std::shared_ptr<const lib_token::Token>, std::shared_ptr<const lib_token::WordBase>>
analysis(std::shared_ptr<const lib_token::WordBase> content) const override;