This commit is contained in:
IlushaShurupov 2023-07-16 18:28:24 +03:00
parent fabceb52d3
commit bc892da992
24 changed files with 116 additions and 110 deletions

View file

@ -16,36 +16,53 @@ namespace tp::RegEx {
REPEAT,
VAL,
} mType = NONE;
AstNode() = default;
virtual ~AstNode() = default;
};
template <typename tAlphabetType>
struct AstVal : public AstNode {
explicit AstVal(tAlphabetType val) : mVal(val) { mType = VAL; }
~AstVal() override = default;
tAlphabetType mVal;
};
struct AstCompound : public AstNode {
AstCompound() { mType = COMPOUND; }
~AstCompound() override {
for (auto iter : mChilds) {
delete iter.data();
}
mChilds.removeAll();
}
List<AstNode*> mChilds;
};
struct AstAlternation : public AstNode {
AstAlternation() { mType = OR; }
~AstAlternation() override {
delete mFirst;
delete mSecond;
}
AstNode* mFirst = nullptr;
AstNode* mSecond = nullptr;
};
struct AstIf : public AstNode {
AstIf() { mType = IF; }
~AstIf() override { delete mNode; }
AstNode* mNode = nullptr;
};
struct AstAny : public AstNode {
AstAny() { mType = ANY; }
~AstAny() override = default;
};
struct AstRepetition : public AstNode {
AstRepetition() { mType = REPEAT; }
~AstRepetition() override { delete mNode; }
AstNode* mNode = nullptr;
bool mPlus = false;
};
@ -53,8 +70,9 @@ namespace tp::RegEx {
template <typename tAlphabetType>
struct AstClass : public AstNode {
AstClass() { mType = CLASS; }
~AstClass() override { mRanges.removeAll(); }
List<Range<tAlphabetType>> mRanges;
bool mExclude{};
bool mExclude = false;
};
struct ParseError {

View file

@ -1,10 +1,9 @@
#include "Testing.hpp"
#include "Tokenizer.hpp"
#include <cstdio>
#include <iostream>
#define LOG(val) std::cout << #val << " "
#define LOG(val) // std::cout << #val << " "
using namespace tp;
@ -126,7 +125,7 @@ TEST_DEF_STATIC(Simple) {
});
if (!lexer.isBuild()) {
std::cout << lexer.getBuildError().description;
printf("Error : %s", lexer.getBuildError().description);
return;
}
@ -141,7 +140,7 @@ TEST_DEF_STATIC(Simple) {
outputHash += ualni(tok);
switch (tok) {
case TokType::SPACE: { std::cout << " "; } break;
case TokType::SPACE: { printf(" "); } break;
case TokType::VAR: { LOG(VAR); } break;
case TokType::CLASS_DEF: { LOG(CLASS_DEF); } break;
case TokType::SELF: { LOG(SELF); } break;
@ -188,7 +187,7 @@ TEST_DEF_STATIC(Simple) {
} while (tok != TokType::TOK_SOURCE_END && tok != TokType::FAILED);
std::cout << "\n\nOutputHash : " << outputHash;
printf("\n\nOutputHash : %llu", outputHash);
TEST(outputHash == outputHashPassed);
}