| 72 | } |
| 73 | |
| 74 | var method_import_as::get_namespace(const context_t &context, tree_type<token_base *>::iterator it) |
| 75 | { |
| 76 | token_base *token = it.data(); |
| 77 | if (token == nullptr) |
| 78 | return var(); |
| 79 | if (token->get_type() == token_types::id) { |
| 80 | const var_id &package_name = static_cast<token_id *>(token)->get_id(); |
| 81 | return make_namespace(context->instance->import(current_process->import_path, package_name)); |
| 82 | } |
| 83 | else if (token->get_type() == token_types::signal && |
| 84 | static_cast<token_signal *>(token)->get_signal() == signal_types::dot_) { |
| 85 | const var &ext = get_namespace(context, it.left()); |
| 86 | token_base *id = it.right().data(); |
| 87 | if (id == nullptr || id->get_type() != token_types::id) |
| 88 | throw compile_error( |
| 89 | "Wrong grammar for import-as statement, expect <package name> or <package name>.<namespace id>..."); |
| 90 | if (ext.is_type_of<namespace_t>()) |
| 91 | return ext.const_val<namespace_t>()->get_var(static_cast<token_id *>(id)->get_id()); |
| 92 | else |
| 93 | throw compile_error("Access non-namespace object."); |
| 94 | } |
| 95 | else |
| 96 | throw compile_error( |
| 97 | "Wrong grammar for import-as statement, expect <package name> or <package name>.<namespace id>..."); |
| 98 | } |
| 99 | |
| 100 | void method_import_as::preprocess(const context_t &context, const std::deque<std::deque<token_base *>> &raw) |
| 101 | { |
no test coverage detected