/* * doc.h --- Seq documentation generator. * * (c) Seq project. All rights reserved. * This file is subject to the terms and conditions defined in * file 'LICENSE', which is part of this source code package. */ #pragma once #include #include #include #include #include #include #include "parser/ast.h" #include "parser/common.h" #include "parser/ctx.h" #include "parser/visitors/visitor.h" namespace seq { namespace ast { struct json { // values={str -> null} -> string value // values={i -> json} -> list (if list=true) // values={...} -> dictionary unordered_map> values; bool list; json(); json(const string &s); json(const string &s, const string &v); json(const vector> &vs); json(const vector &vs); json(const unordered_map &vs); string toString(); shared_ptr get(const string &s); shared_ptr set(const string &s, const string &value); shared_ptr set(const string &s, const shared_ptr &value); }; struct DocContext; struct DocShared { int itemID; shared_ptr j; unordered_map> modules; string argv0; shared_ptr cache; unordered_map> generics; DocShared() : itemID(1) {} }; struct DocContext : public Context { shared_ptr shared; explicit DocContext(shared_ptr shared) : Context(""), shared(move(shared)) { stack.push_front(vector()); } shared_ptr find(const string &s) const override; }; struct DocVisitor : public CallbackASTVisitor, string> { shared_ptr ctx; shared_ptr resultExpr; string resultStmt; public: explicit DocVisitor(shared_ptr ctx) : ctx(move(ctx)) {} static shared_ptr apply(const string &argv0, const vector &files); shared_ptr transform(const ExprPtr &e) override; string transform(const StmtPtr &e) override; void transformModule(StmtPtr stmt); shared_ptr jsonify(const seq::SrcInfo &s); vector flatten(StmtPtr stmt, string *docstr = nullptr, bool deep = true); public: void visit(IntExpr *) override; void visit(IdExpr *) override; void visit(IndexExpr *) override; void visit(FunctionStmt *) override; void visit(ClassStmt *) override; void visit(AssignStmt *) override; void visit(ImportStmt *) override; }; } // namespace ast } // namespace seq