diff --git a/include/utils/data.hh b/include/utils/data.hh index 0001345..d1ff35a 100644 --- a/include/utils/data.hh +++ b/include/utils/data.hh @@ -38,6 +38,9 @@ namespace ppc::data { bool is_number() const; bool is_string() const; bool is_bool() const; + bool is_true() { + return is_bool() && boolean(); + } array_t &array(const array_t &arr); map_t &map(const map_t &map); diff --git a/src/compiler/treeifier/ast/ast.cc b/src/compiler/treeifier/ast/ast.cc index 83abea1..13ba48b 100644 --- a/src/compiler/treeifier/ast/ast.cc +++ b/src/compiler/treeifier/ast/ast.cc @@ -20,5 +20,6 @@ ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector &tokens): messa .add_last("$_exp", parse_stat_exp); group("$_def") .add_last("$_func", parse_func) + .add_named("$_export", parse_export, { "export" }) .add_last("$_field", parse_field); } \ No newline at end of file diff --git a/src/compiler/treeifier/ast/parsers/export.cc b/src/compiler/treeifier/ast/parsers/export.cc new file mode 100644 index 0000000..dfd29a8 --- /dev/null +++ b/src/compiler/treeifier/ast/parsers/export.cc @@ -0,0 +1,12 @@ +#include "compiler/treeifier/ast/helper.hh" + +bool ast::parse_export(ast_ctx_t &ctx, size_t &res_i, map_t &out) { + tree_helper_t h(ctx, res_i); + + if (out["exported"].is_true()) { + ctx.messages.push(message_t(message_t::WARNING, "Export is alredy specified for this definition.", h.prev_loc())); + } + out["exported"] = true; + + return ctx.group("$_def")(ctx, res_i, out); +}