✨ update
This commit is contained in:
parent
c95810b46c
commit
7d8f199c8e
|
@ -26,4 +26,23 @@ bool ast_visitor::visit_identifier(identifier* node) {
|
|||
|
||||
bool ast_visitor::visit_bool_literal(bool_literal* node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ast_visitor::visit_vector_expr(vector_expr* node) {
|
||||
for(auto i : node->get_elements()) {
|
||||
i->accept(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ast_visitor::visit_hash_expr(hash_expr* node) {
|
||||
for(auto i : node->get_members()) {
|
||||
i->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool ast_visitor::visit_hash_pair(hash_pair* node) {
|
||||
if (node->get_element()) {
|
||||
node->get_element()->accept(this);
|
||||
}
|
||||
}
|
|
@ -11,4 +11,7 @@ public:
|
|||
virtual bool visit_string_literal(string_literal*);
|
||||
virtual bool visit_identifier(identifier*);
|
||||
virtual bool visit_bool_literal(bool_literal*);
|
||||
virtual bool visit_vector_expr(vector_expr*);
|
||||
virtual bool visit_hash_expr(hash_expr*);
|
||||
virtual bool visit_hash_pair(hash_pair*);
|
||||
};
|
|
@ -27,4 +27,34 @@ void identifier::accept(ast_visitor* visitor) {
|
|||
|
||||
void bool_literal::accept(ast_visitor* visitor) {
|
||||
visitor->visit_bool_literal(this);
|
||||
}
|
||||
|
||||
vector_expr::~vector_expr() {
|
||||
for(auto i : elements) {
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
|
||||
void vector_expr::accept(ast_visitor* visitor) {
|
||||
visitor->visit_vector_expr(this);
|
||||
}
|
||||
|
||||
hash_expr::~hash_expr() {
|
||||
for(auto i : members) {
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
|
||||
void hash_expr::accept(ast_visitor* visitor) {
|
||||
visitor->visit_hash_expr(this);
|
||||
}
|
||||
|
||||
hash_pair::~hash_pair() {
|
||||
if (element) {
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
|
||||
void hash_pair::accept(ast_visitor* visitor) {
|
||||
visitor->visit_hash_pair(this);
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
#include "nasal.h"
|
||||
#include "nasal_err.h"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
enum class expr_type:u32 {
|
||||
ast_null=0, // null node
|
||||
ast_expr, // expression node
|
||||
|
@ -74,6 +77,7 @@ enum class expr_type:u32 {
|
|||
};
|
||||
|
||||
class ast_visitor;
|
||||
class hash_pair;
|
||||
|
||||
class expr {
|
||||
private:
|
||||
|
@ -115,10 +119,10 @@ public:
|
|||
|
||||
class string_literal:public expr {
|
||||
private:
|
||||
string content;
|
||||
std::string content;
|
||||
|
||||
public:
|
||||
string_literal(const span& location, const string& str):
|
||||
string_literal(const span& location, const std::string& str):
|
||||
expr(location, expr_type::ast_str), content(str) {}
|
||||
~string_literal() = default;
|
||||
virtual void accept(ast_visitor*) override;
|
||||
|
@ -126,10 +130,10 @@ public:
|
|||
|
||||
class identifier:public expr {
|
||||
private:
|
||||
string name;
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
identifier(const span& location, const string& str):
|
||||
identifier(const span& location, const std::string& str):
|
||||
expr(location, expr_type::ast_id), name(str) {}
|
||||
~identifier() = default;
|
||||
virtual void accept(ast_visitor*) override;
|
||||
|
@ -147,17 +151,44 @@ public:
|
|||
};
|
||||
|
||||
class vector_expr:public expr {
|
||||
private:
|
||||
std::vector<expr*> elements;
|
||||
|
||||
public:
|
||||
vector_expr(const span& location):
|
||||
expr(location, expr_type::ast_vec) {}
|
||||
~vector_expr();
|
||||
void add_element(expr* node) {elements.push_back(node);}
|
||||
std::vector<expr*>& get_elements() {return elements;}
|
||||
virtual void accept(ast_visitor*) override;
|
||||
};
|
||||
|
||||
class hash_expr:public expr {
|
||||
private:
|
||||
std::vector<hash_pair*> members;
|
||||
|
||||
public:
|
||||
hash_expr(const span& location):
|
||||
expr(location, expr_type::ast_hash) {}
|
||||
~hash_expr();
|
||||
void add_member(hash_pair* node) {members.push_back(node);}
|
||||
std::vector<hash_pair*>& get_members() {return members;}
|
||||
virtual void accept(ast_visitor*) override;
|
||||
};
|
||||
|
||||
class hash_pair:public expr {
|
||||
private:
|
||||
std::string name;
|
||||
expr* element;
|
||||
|
||||
public:
|
||||
hash_pair(const span& location):
|
||||
expr(location, expr_type::ast_pair) {}
|
||||
~hash_pair();
|
||||
void set_name(const std::string& field_name) {name = field_name;}
|
||||
void set_element(expr* node) {element = node;}
|
||||
const std::string& get_name() const {return name;}
|
||||
expr* get_element() {return element;}
|
||||
virtual void accept(ast_visitor*) override;
|
||||
};
|
||||
|
||||
|
@ -166,6 +197,11 @@ public:
|
|||
virtual void accept(ast_visitor*) override;
|
||||
};
|
||||
|
||||
class code_block:public expr {
|
||||
public:
|
||||
virtual void accept(ast_visitor*) override;
|
||||
};
|
||||
|
||||
class parameter:public expr {
|
||||
public:
|
||||
virtual void accept(ast_visitor*) override;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include "nasal_err.h"
|
||||
#include "nasal_builtin.h"
|
||||
#include "nasal_opcode.h"
|
||||
#include "nasal_ast.h"
|
||||
#include "nasal_parse.h"
|
||||
#include "nasal_import.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <list>
|
||||
|
|
Loading…
Reference in New Issue