Joel Grunbaum
2021-08-12 ca483d438742be9650a5045e846b974f57c67e4f
ast.cpp
@@ -1,177 +1,114 @@
#include <vector>
#include <string>
#include "ast.h"
#include <string>
#include <vector>
MathInline::MathInline(std::string e) {
   expr = e;
}
std::string MathInline::get_expr() {
   return expr;
}
void* MathInline::visit(ast_visitor *v) {
   return v->visit_MathInline(this);
}
MathInline::MathInline(std::string e) { expr = e; }
std::string MathInline::get_expr() { return expr; }
void *MathInline::visit(ast_visitor *v) { return v->visit_MathInline(this); }
Link::Link(std::string l, std::string t) {
Link::Link(std::string l, std::string t)
{
   link = l;
   text = t;
}
std::string Link::get_link() {
   return link;
}
std::string Link::get_link() { return link; }
std::string Link::get_text() { return text; }
void *Link::visit(ast_visitor *v) { return v->visit_Link(this); }
Text::Text(std::string tt) { t = tt; }
std::string Text::get_text() { return t; }
void *Text::visit(ast_visitor *v) { return v->visit_Text(this); }
Format_Bold::Format_Bold(Format *ff) { f = ff; }
Format_Bold::~Format_Bold() { delete f; }
Format *Format_Bold::get_f() { return f; }
void *Format_Bold::visit(ast_visitor *v) { return v->visit_Format_Bold(this); }
Format_Italic::Format_Italic(Format *ff) { f = ff; }
Format_Italic::~Format_Italic() { delete f; }
Format *Format_Italic::get_f() { return f; }
std::string Link::get_text() {
   return text;
}
void* Link::visit(ast_visitor *v) {
   return v->visit_Link(this);
}
Text::Text(std::string tt) {
   t=tt;
}
std::string Text::get_text() {
   return t;
}
void* Text::visit(ast_visitor *v) {
   return v->visit_Text(this);
}
Format_Bold::Format_Bold(Format* ff) {
   f=ff;
}
Format_Bold::~Format_Bold() {
   delete f;
}
Format* Format_Bold::get_f() {
   return f;
}
void* Format_Bold::visit(ast_visitor *v) {
   return v->visit_Format_Bold(this);
}
Format_Italic::Format_Italic(Format* ff) {
   f=ff;
}
Format_Italic::~Format_Italic() {
   delete f;
}
Format* Format_Italic::get_f() {
   return f;
}
void* Format_Italic::visit(ast_visitor *v) {
void *Format_Italic::visit(ast_visitor *v)
{
   return v->visit_Format_Italic(this);
}
Format_Verbatim::Format_Verbatim(Format* ff) {
   f=ff;
}
Format_Verbatim::Format_Verbatim(Format *ff) { f = ff; }
Format_Verbatim::~Format_Verbatim() { delete f; }
Format *Format_Verbatim::get_f() { return f; }
Format_Verbatim::~Format_Verbatim() {
   delete f;
}
Format* Format_Verbatim::get_f() {
   return f;
}
void* Format_Verbatim::visit(ast_visitor *v) {
void *Format_Verbatim::visit(ast_visitor *v)
{
   return v->visit_Format_Verbatim(this);
}
Heading::Heading(int l, Line_Word *w) {
Format_Underline::Format_Underline(Format *ff) { f = ff; }
Format_Underline::~Format_Underline() { delete f; }
Format *Format_Underline::get_f() { return f; }
void *Format_Underline::visit(ast_visitor *v)
{
   return v->visit_Format_Underline(this);
}
Format_Strikethrough::Format_Strikethrough(Format *ff) { f = ff; }
Format_Strikethrough::~Format_Strikethrough() { delete f; }
Format *Format_Strikethrough::get_f() { return f; }
void *Format_Strikethrough::visit(ast_visitor *v)
{
   return v->visit_Format_Strikethrough(this);
}
Heading::Heading(int l, Line_Word *w)
{
   level = l;
   words = w;
}
Heading::~Heading() {
   delete words;
}
Heading::~Heading() { delete words; }
int Heading::get_level() { return level; }
Line_Word *Heading::get_words() { return words; }
void *Heading::visit(ast_visitor *v) { return v->visit_Heading(this); }
int Heading::get_level() {
   return level;
}
Line_Word* Heading::get_words() {
   return words;
}
void* Heading::visit(ast_visitor *v) {
   return v->visit_Heading(this);
}
List::List(int l, int n, Line_Word *w) {
List::List(int l, int n, Line_Word *w)
{
   level = l;
   number = n;
   words = w;
}
List::~List() {
   delete words;
}
List::~List() { delete words; }
int List::get_level() { return level; }
int List::get_number() { return number; }
Line_Word *List::get_words() { return words; }
void *List::visit(ast_visitor *v) { return v->visit_List(this); }
MathDisp::MathDisp(std::string e) { expr = e; }
std::string MathDisp::get_expr() { return expr; }
void *MathDisp::visit(ast_visitor *v) { return v->visit_MathDisp(this); }
int List::get_level() {
   return level;
}
int List::get_number() {
   return number;
}
Line_Word* List::get_words() {
   return words;
}
void* List::visit(ast_visitor *v) {
   return v->visit_List(this);
}
MathDisp::MathDisp(std::string e) {
   expr = e;
}
std::string MathDisp::get_expr() {
   return expr;
}
void* MathDisp::visit(ast_visitor *v) {
   return v->visit_MathDisp(this);
}
Line_Word::~Line_Word() {
   for (std::vector<Word*>::size_type i = 0; i < words.size(); i++) {
Line_Word::~Line_Word()
{
   for (std::vector<Word *>::size_type i = 0; i < words.size(); i++) {
      delete words[i];
   }
   words.clear();
}
int Line_Word::add_word(Word *w) {
int Line_Word::add_word(Word *w)
{
   words.push_back(w);
   return 0;
}
std::vector<Word*>* Line_Word::get_words() {
   return &words;
}
std::vector<Word *> *Line_Word::get_words() { return &words; }
void *Line_Word::visit(ast_visitor *v) { return v->visit_Line_Word(this); }
void* Line_Word::visit(ast_visitor *v) {
   return v->visit_Line_Word(this);
}
Block_Table::~Block_Table() {
   for (std::vector<std::vector<Line_Word*>*>::size_type i = 0; i < table.size(); i++) {
      std::vector<Line_Word*> *t = table[i];
      for (std::vector<Line_Word*>::size_type j = 0; j < t->size(); j++) {
Block_Table::~Block_Table()
{
   for (std::vector<std::vector<Line_Word *> *>::size_type i = 0;
        i < table.size(); i++) {
      std::vector<Line_Word *> *t = table[i];
      for (std::vector<Line_Word *>::size_type j = 0; j < t->size();
           j++) {
         delete (*t)[j];
      }
      t->clear();
@@ -180,16 +117,20 @@
   table.clear();
}
std::vector<std::vector<Line_Word*>*>* Block_Table::get_table() {
std::vector<std::vector<Line_Word *> *> *Block_Table::get_table()
{
   return &table;
}
int Block_Table::add_row(std::vector<Line_Word*>* row) {
int Block_Table::add_row(std::vector<Line_Word *> *row)
{
   table.push_back(row);
   return 0;
}
std::vector<Line_Word*>* Block_Table::get_row(std::vector<Line_Word*>::size_type i) {
std::vector<Line_Word *> *
Block_Table::get_row(std::vector<Line_Word *>::size_type i)
{
   if (i < table.size()) {
      return table[i];
   } else {
@@ -197,86 +138,54 @@
   }
}
void* Block_Table::visit(ast_visitor *v) {
   return v->visit_Block_Table(this);
}
void *Block_Table::visit(ast_visitor *v) { return v->visit_Block_Table(this); }
Block_Code::Block_Code(std::string l) {
Block_Code::Block_Code(std::string l)
{
   lang = l;
   c = "";
}
int Block_Code::add_line(std::string add) {
int Block_Code::add_line(std::string add)
{
   c = c + add + "\n";
   return 0;
}
std::string Block_Code::get_lang() {
   return lang;
}
std::string Block_Code::get_lang() { return lang; }
std::string Block_Code::get_code() { return c; }
void *Block_Code::visit(ast_visitor *v) { return v->visit_Block_Code(this); }
std::string Block_Code::get_code() {
   return c;
}
Block_Word::Block_Word(Line_Word *lw) { words = lw; }
Block_Word::~Block_Word() { delete words; }
int Block_Word::add_word(Word *w) { return words->add_word(w); }
Line_Word *Block_Word::get_words() { return words; }
void *Block_Word::visit(ast_visitor *v) { return v->visit_Block_Word(this); }
void* Block_Code::visit(ast_visitor *v) {
   return v->visit_Block_Code(this);
}
Block_Line::~Block_Line() {
   for (std::vector<Line*>::size_type i = 0; i < lines.size(); i++) {
      delete lines[i];
   }
   lines.clear();
}
std::vector<Line*>* Block_Line::get_lines() {
   return &lines;
}
int Block_Line::add_line(Line* l) {
   lines.push_back(l);
   return 0;
}
void* Block_Line::visit(ast_visitor *v) {
   return v->visit_Block_Line(this);
}
Document::Document(std::string t, std::string a, std::string d) {
Document::Document(std::string t, std::string a, std::string d)
{
   title = t;
   author = a;
   date = d;
}
Document::~Document() {
   for (std::vector<Block*>::size_type i = 0; i < blocks.size(); i++) {
Document::~Document()
{
   for (std::vector<Block *>::size_type i = 0; i < blocks.size(); i++) {
      delete blocks[i];
   }
   blocks.clear();
}
std::string Document::get_title() {
   return title;
}
std::string Document::get_title() { return title; }
std::string Document::get_author() { return author; }
std::string Document::get_date() { return date; }
std::vector<Block *> *Document::get_blocks() { return &blocks; }
std::string Document::get_author() {
   return author;
}
std::string Document::get_date() {
   return date;
}
std::vector<Block*>* Document::get_blocks() {
   return &blocks;
}
int Document::add_block(Block *b) {
int Document::add_block(Block *b)
{
   blocks.push_back(b);
   return 0;
}
void* Document::visit(ast_visitor *v) {
   return v->visit_Document(this);
}
void *Document::visit(ast_visitor *v) { return v->visit_Document(this); }