WsParser_VS/libSyntax/ast_basic.cpp

110 lines
2.9 KiB
C++
Raw Normal View History

2024-03-17 07:58:28 +00:00
#include "ast_basic.h"
2024-06-18 17:09:45 +00:00
#include <QDebug>
2024-03-17 07:58:28 +00:00
using namespace ast_basic;
using namespace lib_token;
using namespace lib_syntax;
ExpressionElement::ExpressionElement(std::shared_ptr<const ExprRule> bind) : _expr_rule(bind) {}
2024-03-17 07:58:28 +00:00
std::shared_ptr<const ExprRule> ExpressionElement::definedRule() const {
return _expr_rule;
2024-03-17 07:58:28 +00:00
}
2024-06-20 14:13:06 +00:00
QString ExpressionElement::filePath() const {
if (!tokens_bind.size())
throw new SyntaxException(u8"InternalError[0x0002]һ<><D2BB><EFBFBD>յķǷ<C4B7><C7B7><EFBFBD>Ч<EFBFBD>ڵ<EFBFBD>");
return tokens_bind.first()->file();
}
2024-03-17 07:58:28 +00:00
2024-06-20 14:13:06 +00:00
void ExpressionElement::addToken(std::shared_ptr<const IToken> token_inst) {
this->tokens_bind.append(token_inst);
2024-03-17 07:58:28 +00:00
}
2024-07-12 21:52:32 +00:00
QList<std::shared_ptr<const IExprInst>> ExpressionElement::children() const {
return this->children_store;
}
2024-03-17 07:58:28 +00:00
2024-07-12 21:52:32 +00:00
void ExpressionElement::addChild(std::shared_ptr<const IExprInst> inst) {
this->children_store.append(inst);
}
QList<std::shared_ptr<const IToken>> ExpressionElement::tokens() const {
return this->tokens_bind;
2024-03-17 07:58:28 +00:00
}
2024-07-28 06:39:18 +00:00
ExprsContext::ExprsContext() {}
2024-07-28 06:39:18 +00:00
void ExprsContext::setCurrentFile(const QString& path) { this->current_file_path = path; }
2024-07-28 06:39:18 +00:00
QString ExprsContext::currentFile() const { return this->current_file_path; }
2024-07-28 06:39:18 +00:00
std::shared_ptr<IExprInst> ExprsContext::currentExprInst() const
{
if (expression_stack.size())
return expression_stack.last();
2024-03-17 07:58:28 +00:00
return nullptr;
}
2024-03-17 07:58:28 +00:00
2024-07-28 06:39:18 +00:00
void ExprsContext::pushExprInst(std::shared_ptr<IExprInst> current_inst)
{
if (!expression_stack.size() || expression_stack.last() != current_inst)
expression_stack.append(current_inst);
2024-03-17 07:58:28 +00:00
}
2024-07-28 06:39:18 +00:00
std::shared_ptr<IExprInst> ExprsContext::popExprInst()
2024-03-17 07:58:28 +00:00
{
auto lastx = expression_stack.takeLast();
return lastx;
}
2024-03-17 07:58:28 +00:00
2024-07-28 06:39:18 +00:00
std::shared_ptr<const IBasicRule> ExprsContext::currentExprRule() const {
if (rule_stack.size())
return rule_stack.last();
return nullptr;
2024-03-17 07:58:28 +00:00
}
2024-07-28 06:39:18 +00:00
void ExprsContext::pushExprRule(std::shared_ptr<const IBasicRule> inst) {
if (!rule_stack.size() || rule_stack.last() != inst)
rule_stack.append(inst);
2024-03-17 07:58:28 +00:00
}
2024-07-28 06:39:18 +00:00
std::shared_ptr<const IBasicRule> ExprsContext::popExprRule()
{
return rule_stack.takeLast();
}
2024-07-28 06:39:18 +00:00
void ExprsContext::appendParseErrors(const QString& file_path, int start, const QString& e) {
2024-07-12 09:35:35 +00:00
this->errors_storage.append(std::make_tuple(file_path, start, e));
2024-03-17 07:58:28 +00:00
}
2024-07-28 06:39:18 +00:00
QStringList ExprsContext::errors() const {
QStringList values;
for (auto& tp : this->errors_storage)
2024-07-12 22:16:11 +00:00
values.append(QString(u8"<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>%1\n\t%2").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
return values;
}
2024-07-28 06:39:18 +00:00
void ExprsContext::clearErrors(const QString &file_path, int start) {
for (int idx = 0; idx < this->errors_storage.size(); ++idx) {
auto &tp = errors_storage[idx];
2024-07-12 09:35:35 +00:00
if(std::get<0>(tp) == file_path && std::get<1>(tp) >= start)
errors_storage.removeAt(idx--);
}
}
2024-07-28 06:39:18 +00:00
QList<std::shared_ptr<const IBasicRule>> ExprsContext::currentExprRuleStack() const {
return rule_stack;
}
2024-07-28 06:39:18 +00:00
void ExprsContext::appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) {
this->document_store.append(inst);
}
2024-07-28 06:39:18 +00:00
QList<std::shared_ptr<const ast_basic::IExprInst>> ExprsContext::getDocInsts() const {
return this->document_store;
}