69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
#include "ast_basic.h"
|
|
|
|
using namespace ast_basic;
|
|
using namespace lib_token;
|
|
using namespace lib_syntax;
|
|
|
|
TokenNodeImpl::TokenNodeImpl(std::shared_ptr<const Token> word) : word_store(word) {}
|
|
|
|
QString TokenNodeImpl::filePath() const
|
|
{
|
|
return word_store->file();
|
|
}
|
|
|
|
bool TokenNodeImpl::isLeaf() const { return true; }
|
|
|
|
QList<std::shared_ptr<const Token>> TokenNodeImpl::tokens() const { return QList<std::shared_ptr<const lib_token::Token>>() << word_store; }
|
|
|
|
std::shared_ptr<const TokenNode> TokenNodeImpl::filledWith(const QList<std::shared_ptr<const TokenNode>>& tokens) const {
|
|
Q_UNUSED(tokens);
|
|
throw new lib_syntax::SyntaxException(u8"InternalError[0x0001]不能对TokenNode调用filledWith");
|
|
}
|
|
|
|
ExprNodeImpl::ExprNodeImpl(std::shared_ptr<const lib_syntax::ExprRule> bind) : _expr_rule(bind) {}
|
|
|
|
QString ExprNodeImpl::filePath() const
|
|
{
|
|
auto toks = tokens();
|
|
if (toks.size())
|
|
return toks.first()->file();
|
|
auto exprs = exprNodes();
|
|
if (exprs.size())
|
|
return exprs.first()->filePath();
|
|
|
|
throw new SyntaxException(u8"InternalError[0x0002]一个空的非法无效节点");
|
|
}
|
|
|
|
bool ExprNodeImpl::isLeaf() const { return false; }
|
|
|
|
std::shared_ptr<const ExprRule> ExprNodeImpl::defined() const { return this->_expr_rule; }
|
|
|
|
QList<std::shared_ptr<const ExprNode>> ExprNodeImpl::exprNodes() const {
|
|
QList<std::shared_ptr<const ExprNode>> listret;
|
|
for (auto& it : children_store)
|
|
if (!it->isLeaf())
|
|
listret.append(std::dynamic_pointer_cast<const ExprNode>(it));
|
|
return listret;
|
|
}
|
|
|
|
QList<std::shared_ptr<const TokenNode> > ExprNodeImpl::childTokensMid(int index, int length) const
|
|
{
|
|
if (index >= 0 && length > 0 && index + length <= children_store.size())
|
|
return children_store.mid(index, length);
|
|
|
|
return QList<std::shared_ptr<const TokenNode>>();
|
|
}
|
|
|
|
QList<std::shared_ptr<const Token>> ExprNodeImpl::tokens() const {
|
|
QList<std::shared_ptr<const lib_token::Token>> retlist;
|
|
for (auto& it : children_store)
|
|
retlist.append(it->tokens());
|
|
return retlist;
|
|
}
|
|
|
|
std::shared_ptr<const TokenNode> ExprNodeImpl::filledWith(const QList<std::shared_ptr<const TokenNode>>& child_nodes) const {
|
|
auto vinst = std::make_shared<ExprNodeImpl>(this->_expr_rule);
|
|
vinst->children_store.append(child_nodes);
|
|
return vinst;
|
|
}
|