#include "ast_basic.h" using namespace ast_basic; using namespace lib_token; using namespace lib_syntax; TokenNodeImpl::TokenNodeImpl(std::shared_ptr word) : word_store(word) {} QString TokenNodeImpl::filePath() const { return word_store->file(); } bool TokenNodeImpl::isLeaf() const { return true; } QList> TokenNodeImpl::tokens() const { return QList>() << word_store; } std::shared_ptr TokenNodeImpl::filledWith(const QList>& tokens) const { Q_UNUSED(tokens); throw new lib_syntax::SyntaxException(u8"InternalError[0x0001]不能对TokenNode调用filledWith"); } ExprNodeImpl::ExprNodeImpl(std::shared_ptr 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 ExprNodeImpl::defined() const { return this->_expr_rule; } QList> ExprNodeImpl::exprNodes() const { QList> listret; for (auto& it : children_store) if (!it->isLeaf()) listret.append(std::dynamic_pointer_cast(it)); return listret; } QList > 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>(); } QList> ExprNodeImpl::tokens() const { QList> retlist; for (auto& it : children_store) retlist.append(it->tokens()); return retlist; } std::shared_ptr ExprNodeImpl::filledWith(const QList>& child_nodes) const { auto vinst = std::make_shared(this->_expr_rule); vinst->children_store.append(child_nodes); return vinst; }