6 using namespace Internal
;
8 template<typename Node
>
9 static Interpreter::Value
handle_import(Interpreter
& ip
, Node
& node
, Interpreter::Value
& expr
)
12 std::stringstream errstrm
;
13 auto modpath
= ip
.getModulePath();
15 for(auto path
: modpath
)
17 std::stringstream filepath
;
19 filepath
<< path
<< "/" << expr
.string() << ".aqm";
20 fh
.open(filepath
.str(), std::ios::in
);
24 (std::istreambuf_iterator
<char>(fh
)),
25 std::istreambuf_iterator
<char>()
28 return ip
.eval(filedata
);
33 errstrm
<< "could not import '" << expr
.string() << "' (path: [";
34 for(auto iter
=modpath
.begin(); iter
!=modpath
.end(); iter
++)
36 errstrm
<< "\"" << *iter
<< "\"";
37 if((iter
+ 1) != modpath
.end())
43 ip
.error(errstrm
.str(), node
);
45 return Interpreter::Value();
48 template<typename Node
>
49 static Interpreter::Value
import_main(Interpreter
& ip
, Node
& node
, Interpreter::Value
& expr
)
51 std::stringstream errstrm
;
54 case Interpreter::Value::Type::String
:
55 return handle_import(ip
, node
, expr
);
56 /*case Interpreter::Value::Type::Array:
57 for(auto& val: expr.array()->get())
59 return import_main(ip);
65 errstrm
<< "'import' expects a string, got " << expr
.typeName() << "instead";
66 ip
.error(errstrm
.str(), node
);
67 return Interpreter::Value();
70 Interpreter::Value
Interpreter::operator()(DoImport
<Iter
,Interpreter::Value
,FuncType
> &node
)
72 Interpreter::Value expr
;
73 expr
= node
.children
[0]->accept(*this);
74 std::cerr
<< "import: args = " << expr
<< std::endl
;
75 return import_main(*this, node
, expr
);
76 return Interpreter::Value();