相对路径改造
This commit is contained in:
parent
bd9ef1f715
commit
3547a2c84a
|
@ -711,11 +711,10 @@ void printer::AstGenerate::append_tokens(QDomElement _elm, std::shared_ptr<const
|
|||
}
|
||||
}
|
||||
|
||||
printer::AstGenerate::AstGenerate()
|
||||
{
|
||||
printer::AstGenerate::AstGenerate(const QDir &src_rt)
|
||||
: src_root(src_rt) {
|
||||
auto procs = doc.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
|
||||
doc.appendChild(procs);
|
||||
|
||||
}
|
||||
|
||||
QString printer::AstGenerate::content() const
|
||||
|
@ -734,6 +733,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
auto body = doc.createElement(u8"ast");
|
||||
doc.appendChild(body);
|
||||
body.setAttribute(u8"time", QDateTime::currentDateTime().toString(u8"yyyyMMdd_hhmmss"));
|
||||
body.setAttribute(u8"dir_src", src_root.absolutePath());
|
||||
element_stack.append(body);
|
||||
}break;
|
||||
case NovelNode::Document: break;
|
||||
|
@ -750,7 +750,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
|
||||
dom_story.setAttribute(u8"name", story_node->name());
|
||||
dom_story.setAttribute(u8"address", (qulonglong)story_node.get());
|
||||
dom_story.setAttribute(u8"file-path", story_node->filePath());
|
||||
dom_story.setAttribute(u8"file-path", src_root.relativeFilePath(story_node->filePath()));
|
||||
dom_story.setAttribute(u8"sort", story_node->sort());
|
||||
|
||||
append_tokens(dom_story, story_node);
|
||||
|
@ -768,7 +768,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
|
||||
dom_fragment.setAttribute(u8"name", fragment_node->name());
|
||||
dom_fragment.setAttribute(u8"address", (qulonglong)fragment_node.get());
|
||||
dom_fragment.setAttribute(u8"file-path", fragment_node->filePath());
|
||||
dom_fragment.setAttribute(u8"file-path", src_root.relativeFilePath(fragment_node->filePath()));
|
||||
|
||||
append_tokens(dom_fragment, fragment_node);
|
||||
}break;
|
||||
|
@ -779,7 +779,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
current_text.appendChild(dom_text);
|
||||
|
||||
dom_text.setAttribute(u8"text", text_node->content());
|
||||
dom_text.setAttribute(u8"file-path", text_node->filePath());
|
||||
dom_text.setAttribute(u8"file-path", src_root.relativeFilePath(text_node->filePath()));
|
||||
|
||||
append_tokens(dom_text, text_node);
|
||||
}break;
|
||||
|
@ -796,7 +796,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
|
||||
dom_refer.setAttribute(u8"story", refer_node->storyRefer());
|
||||
dom_refer.setAttribute(u8"fragment", refer_node->fragmentRefer());
|
||||
dom_refer.setAttribute(u8"file-path", refer_node->filePath());
|
||||
dom_refer.setAttribute(u8"file-path", src_root.relativeFilePath(refer_node->filePath()));
|
||||
|
||||
append_tokens(dom_refer, refer_node);
|
||||
}break;
|
||||
|
@ -813,7 +813,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
|
||||
dom_volume.setAttribute(u8"name", volume_node->name());
|
||||
dom_volume.setAttribute(u8"address", (qulonglong)volume_node.get());
|
||||
dom_volume.setAttribute(u8"file-path", volume_node->filePath());
|
||||
dom_volume.setAttribute(u8"file-path", src_root.relativeFilePath(volume_node->filePath()));
|
||||
|
||||
append_tokens(dom_volume, volume_node);
|
||||
}break;
|
||||
|
@ -830,7 +830,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
|
||||
dom_article.setAttribute(u8"name", article_node->name());
|
||||
dom_article.setAttribute(u8"address", (qulonglong)article_node.get());
|
||||
dom_article.setAttribute(u8"file-path", article_node->filePath());
|
||||
dom_article.setAttribute(u8"file-path", src_root.relativeFilePath(article_node->filePath()));
|
||||
|
||||
append_tokens(dom_article, article_node);
|
||||
}break;
|
||||
|
@ -841,7 +841,7 @@ bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> s
|
|||
ast_element.appendChild(dom_rank);
|
||||
|
||||
dom_rank.setAttribute(u8"rank", rank_node->rankNumber());
|
||||
dom_rank.setAttribute(u8"doc-path", rank_node->filePath());
|
||||
dom_rank.setAttribute(u8"doc-path", src_root.relativeFilePath(rank_node->filePath()));
|
||||
|
||||
append_tokens(dom_rank, rank_node);
|
||||
}break;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <QList>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDomDocument>
|
||||
|
||||
#include <ast_gen.h>
|
||||
|
@ -162,13 +163,14 @@ namespace printer {
|
|||
|
||||
class AstGenerate : public lib_parse::TreeVisitor {
|
||||
private:
|
||||
QDir src_root;
|
||||
QDomDocument doc;
|
||||
QList<QDomElement> element_stack;
|
||||
|
||||
void append_tokens(QDomElement _elm, std::shared_ptr<const ast_gen::SyntaxElement> inst);
|
||||
|
||||
public:
|
||||
AstGenerate();
|
||||
AstGenerate(const QDir &src_root);
|
||||
|
||||
QString content() const;
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ int main(int argc, char* argv[]) {
|
|||
else if (access_ptr) {
|
||||
QTime time_stamp = QTime::currentTime();
|
||||
lib_parse::VisitorControl control;
|
||||
auto visitor = std::make_shared<printer::AstGenerate>();
|
||||
auto visitor = std::make_shared<printer::AstGenerate>(source_dir);
|
||||
control.visitWith(access_ptr, visitor);;
|
||||
auto dom_result = visitor->content();
|
||||
QFile file(destination_dir.absoluteFilePath(u8"storyline.xast"));
|
||||
|
|
Loading…
Reference in New Issue