110 lines
2.9 KiB
C++
110 lines
2.9 KiB
C++
#include "ast_basic.h"
|
|
#include <QDebug>
|
|
|
|
using namespace ast_basic;
|
|
using namespace lib_token;
|
|
using namespace lib_syntax;
|
|
|
|
ExprElement::ExprElement(std::shared_ptr<const ExprRule> bind) : _expr_rule(bind) {}
|
|
|
|
std::shared_ptr<const ExprRule> ExprElement::definedRule() const {
|
|
return _expr_rule;
|
|
}
|
|
|
|
QString ExprElement::filePath() const {
|
|
if (!tokens_bind.size())
|
|
throw new SyntaxException(u8"InternalError[0x0002]Ò»¸ö¿ÕµÄ·Ç·¨ÎÞЧ½Úµã");
|
|
|
|
return tokens_bind.first()->file();
|
|
}
|
|
|
|
void ExprElement::addToken(std::shared_ptr<const IToken> token_inst) {
|
|
this->tokens_bind.append(token_inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<const IExprInst>> ExprElement::children() const {
|
|
return this->children_store;
|
|
}
|
|
|
|
void ExprElement::addChild(std::shared_ptr<const IExprInst> inst) {
|
|
this->children_store.append(inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<const IToken>> ExprElement::tokens() const {
|
|
return this->tokens_bind;
|
|
}
|
|
|
|
ExprsContext::ExprsContext() {}
|
|
|
|
void ExprsContext::setCurrentFile(const QString& path) { this->current_file_path = path; }
|
|
|
|
QString ExprsContext::currentFile() const { return this->current_file_path; }
|
|
|
|
std::shared_ptr<IExprInst> ExprsContext::currentExprInst() const
|
|
{
|
|
if (expression_stack.size())
|
|
return expression_stack.last();
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void ExprsContext::pushExprInst(std::shared_ptr<IExprInst> current_inst)
|
|
{
|
|
if (!expression_stack.size() || expression_stack.last() != current_inst)
|
|
expression_stack.append(current_inst);
|
|
}
|
|
|
|
std::shared_ptr<IExprInst> ExprsContext::popExprInst()
|
|
{
|
|
auto lastx = expression_stack.takeLast();
|
|
return lastx;
|
|
}
|
|
|
|
std::shared_ptr<const IBasicRule> ExprsContext::currentExprRule() const {
|
|
if (rule_stack.size())
|
|
return rule_stack.last();
|
|
return nullptr;
|
|
}
|
|
|
|
void ExprsContext::pushExprRule(std::shared_ptr<const IBasicRule> inst) {
|
|
if (!rule_stack.size() || rule_stack.last() != inst)
|
|
rule_stack.append(inst);
|
|
}
|
|
|
|
std::shared_ptr<const IBasicRule> ExprsContext::popExprRule()
|
|
{
|
|
return rule_stack.takeLast();
|
|
}
|
|
|
|
void ExprsContext::appendParseErrors(const QString& file_path, int start, const QString& e) {
|
|
this->errors_storage.append(std::make_tuple(file_path, start, e));
|
|
}
|
|
|
|
QStringList ExprsContext::errors() const {
|
|
QStringList values;
|
|
for (auto& tp : this->errors_storage)
|
|
values.append(QString(u8"Îļþ£º%1\n\t%2").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
|
|
|
|
return values;
|
|
}
|
|
|
|
void ExprsContext::clearErrors(const QString &file_path, int start) {
|
|
for (int idx = 0; idx < this->errors_storage.size(); ++idx) {
|
|
auto &tp = errors_storage[idx];
|
|
if(std::get<0>(tp) == file_path && std::get<1>(tp) >= start)
|
|
errors_storage.removeAt(idx--);
|
|
}
|
|
}
|
|
|
|
QList<std::shared_ptr<const IBasicRule>> ExprsContext::currentExprRuleStack() const {
|
|
return rule_stack;
|
|
}
|
|
|
|
|
|
void ExprsContext::appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) {
|
|
this->document_store.append(inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<const ast_basic::IExprInst>> ExprsContext::getDocInsts() const {
|
|
return this->document_store;
|
|
} |