From e8ea5e907ca1fb359d5dd342e505a78bab42d879 Mon Sep 17 00:00:00 2001 From: Joel Grunbaum <joelgrun@gmail.com> Date: Thu, 12 Aug 2021 10:14:58 +0000 Subject: [PATCH] Renamed tester to fit with parser naming --- ast.h | 306 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 183 insertions(+), 123 deletions(-) diff --git a/ast.h b/ast.h index ccc5e74..91b93f7 100644 --- a/ast.h +++ b/ast.h @@ -1,11 +1,11 @@ #ifndef AST_H #define AST_H -#include <vector> #include <string> +#include <vector> -//class ast_node; +// class ast_node; class ast_visitor; -//class Document; +// class Document; // class Block; // class Block_Table; // class Block_Code; @@ -24,173 +24,233 @@ // class Format_Verbatim; // class Text; -class ast_node { -public: - virtual ~ast_node()=default; - virtual void* visit(ast_visitor *v)=0; +class ast_node +{ + public: + virtual ~ast_node() = default; + virtual void *visit(ast_visitor *v) = 0; }; -class Word: public ast_node {}; - -class MathInline: public Word { - std::string *expr; -public: - MathInline(std::string *e); - ~MathInline(); - std::string* get_expr(); - void* visit(ast_visitor *v); +class Word : public ast_node +{ }; -class Link: public Word { - std::string *link, *text; -public: - Link(std::string *l, std::string *t); - ~Link(); - std::string* get_link(); - std::string* get_text(); - void* visit(ast_visitor *v); +class MathInline : public Word +{ + std::string expr; + + public: + MathInline(std::string e); + std::string get_expr(); + void *visit(ast_visitor *v); }; -class Format: public Word {}; +class Link : public Word +{ + std::string link, text; -class Text: public Format { + public: + Link(std::string l, std::string t); + std::string get_link(); + std::string get_text(); + void *visit(ast_visitor *v); +}; + +class Format : public Word +{ +}; + +class Text : public Format +{ std::string t; -public: + + public: Text(std::string tt); - std::string* get_text(); - void* visit(ast_visitor *v); + std::string get_text(); + void *visit(ast_visitor *v); }; -class Format_Bold: public Format { +class Format_Bold : public Format +{ Format *f; -public: - Format_Bold(Format* ff); + + public: + Format_Bold(Format *ff); ~Format_Bold(); - Format* get_f(); - void* visit(ast_visitor *v); + Format *get_f(); + void *visit(ast_visitor *v); }; -class Format_Italic: public Format { +class Format_Italic : public Format +{ Format *f; -public: - Format_Italic(Format* ff); + + public: + Format_Italic(Format *ff); ~Format_Italic(); - Format* get_f(); - void* visit(ast_visitor *v); + Format *get_f(); + void *visit(ast_visitor *v); }; -class Format_Verbatim: public Format { +class Format_Verbatim : public Format +{ Format *f; -public: - Format_Verbatim(Format* ff); - ~Format_Verbatim(); - Format* get_f(); - void* visit(ast_visitor *v); -}; -class Line: public ast_node {}; -class Heading: public Line { + public: + Format_Verbatim(Format *ff); + ~Format_Verbatim(); + Format *get_f(); + void *visit(ast_visitor *v); +}; + +class Format_Underline : public Format +{ + Format *f; + + public: + Format_Underline(Format *ff); + ~Format_Underline(); + Format *get_f(); + void *visit(ast_visitor *v); +}; + +class Format_Strikethrough : public Format +{ + Format *f; + + public: + Format_Strikethrough(Format *ff); + ~Format_Strikethrough(); + Format *get_f(); + void *visit(ast_visitor *v); +}; + +// class Line : public ast_node {}; + +class Line_Word : public Word +{ + std::vector<Word *> words; + + public: + ~Line_Word(); + int add_word(Word *w); + std::vector<Word *> *get_words(); + void *visit(ast_visitor *v); +}; + +class Heading : public Word +{ int level; - std::vector<Word*> words; -public: - Heading(int l, std::vector<Word*> w); + Line_Word *words; + + public: + Heading(int l, Line_Word *w); ~Heading(); int get_level(); - std::vector<Word*>* get_words(); - void* visit(ast_visitor *v); + Line_Word *get_words(); + void *visit(ast_visitor *v); }; -class List: public Line { +class List : public Word +{ int level, number; - std::vector<Word*> words; -public: - List(int l, int n, std::vector<Word*> w); + Line_Word *words; + + public: + List(int l, int n, Line_Word *w); ~List(); int get_level(); int get_number(); - std::vector<Word*>* get_words(); - void* visit(ast_visitor *v); + Line_Word *get_words(); + void *visit(ast_visitor *v); }; -class MathDisp: public Line { - std::string *expr; -public: - MathDisp(std::string *e); - ~MathDisp(); - std::string* get_expr(); - void* visit(ast_visitor *v); +class MathDisp : public Word +{ + std::string expr; + + public: + MathDisp(std::string e); + std::string get_expr(); + void *visit(ast_visitor *v); }; -class Line_Word: public Line { - std::vector<Word*> words; -public: - ~Line_Word(); - int add_word(Word *w); - std::vector<Word*>* get_words(); - void* visit(ast_visitor *v); +class Block : public ast_node +{ }; -class Block: public ast_node {}; +class Block_Table : public Block +{ + std::vector<std::vector<Line_Word *> *> table; -class Block_Table: public Block { - std::vector<std::vector<Line_Word*>> table; -public: + public: ~Block_Table(); - std::vector<std::vector<Line_Word*>> get_table(); - int add_row(std::vector<Line_Word*> row); - void* visit(ast_visitor *v); + std::vector<std::vector<Line_Word *> *> *get_table(); + int add_row(std::vector<Line_Word *> *row); + std::vector<Line_Word *> * + get_row(std::vector<Line_Word *>::size_type i); + void *visit(ast_visitor *v); }; -class Block_Code: public Block { - std::string *c; - std::string *lang; -public: - Block_Code(std::string *l); - ~Block_Code(); - int add_line(std::string *add); - std::string* get_lang(); - std::string* get_code(); - void* visit(ast_visitor *v); +class Block_Code : public Block +{ + std::string c; + std::string lang; + + public: + Block_Code(std::string l); + int add_line(std::string add); + std::string get_lang(); + std::string get_code(); + void *visit(ast_visitor *v); }; -class Block_Line: public Block { - std::vector<Line*> lines; -public: - ~Block_Line(); - std::vector<Line*>* get_lines(); - int add_line(Line* l); - void* visit(ast_visitor *v); +class Block_Word : public Block +{ + Line_Word *words; + + public: + Block_Word(Line_Word *lw); + ~Block_Word(); + int add_word(Word *w); + Line_Word *get_words(); + void *visit(ast_visitor *v); }; -class Document: public ast_node { - std::string *title, *author, *date; - std::vector<Block*> blocks; -public: - Document(std::string *t, std::string *a, std::string *d); +class Document : public ast_node +{ + std::string title, author, date; + std::vector<Block *> blocks; + + public: + Document(std::string t, std::string a, std::string d); ~Document(); - std::string* get_title(); - std::string* get_author(); - std::string* get_date(); - std::vector<Block*>* get_blocks(); + std::string get_title(); + std::string get_author(); + std::string get_date(); + std::vector<Block *> *get_blocks(); int add_block(Block *b); - void* visit(ast_visitor *v); + void *visit(ast_visitor *v); }; -class ast_visitor { -public: - virtual void* visit_Document(Document *d)=0; - virtual void* visit_Block_Table(Block_Table *bt)=0; - virtual void* visit_Block_Code(Block_Code *bc)=0; - virtual void* visit_Block_Line(Block_Line *bl)=0; - virtual void* visit_Heading(Heading *h)=0; - virtual void* visit_List(List *l)=0; - virtual void* visit_MathDisp(MathDisp *md)=0; - virtual void* visit_Line_Word(Line_Word *lw)=0; - virtual void* visit_Link(Link *l)=0; - virtual void* visit_MathInline(MathInline *mi)=0; - virtual void* visit_Format_Bold(Format_Bold *fb)=0; - virtual void* visit_Format_Italic(Format_Italic *fi)=0; - virtual void* visit_Format_Verbatim(Format_Verbatim *fv)=0; - virtual void* visit_Text(Text *t)=0; +class ast_visitor +{ + public: + virtual void *visit_Document(Document *d) = 0; + virtual void *visit_Block_Table(Block_Table *bt) = 0; + virtual void *visit_Block_Code(Block_Code *bc) = 0; + virtual void *visit_Block_Word(Block_Word *bw) = 0; + virtual void *visit_Heading(Heading *h) = 0; + virtual void *visit_List(List *l) = 0; + virtual void *visit_MathDisp(MathDisp *md) = 0; + virtual void *visit_Line_Word(Line_Word *lw) = 0; + virtual void *visit_Link(Link *l) = 0; + virtual void *visit_MathInline(MathInline *mi) = 0; + virtual void *visit_Format_Bold(Format_Bold *fb) = 0; + virtual void *visit_Format_Italic(Format_Italic *fi) = 0; + virtual void *visit_Format_Verbatim(Format_Verbatim *fv) = 0; + virtual void *visit_Format_Underline(Format_Underline *fu) = 0; + virtual void *visit_Format_Strikethrough(Format_Strikethrough *fs) = 0; + virtual void *visit_Text(Text *t) = 0; }; #endif -- Gitblit v1.10.0