MCPcopy Create free account
hub / github.com/covscript/covscript / parse_expr

Method parse_expr

sources/instance/runtime.cpp:410–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408 }
409
410 var runtime_type::parse_expr(const tree_type<token_base *>::iterator &it, bool disable_parallel)
411 {
412 if (!it.usable())
413 throw internal_error("The expression tree is not available.");
414 token_base *token = it.data();
415 if (token == nullptr)
416 return var();
417 switch (token->get_type()) {
418 default:
419 break;
420 case token_types::vargs:
421 throw runtime_error("Wrong declaration of variable argument list.");
422 break;
423 case token_types::expand:
424 throw runtime_error("Wrong expanding position.");
425 break;
426 case token_types::id:
427 return storage.get_var(static_cast<token_id *>(token)->get_id());
428 break;
429 case token_types::literal: {
430 token_literal *ptr = static_cast<token_literal *>(token);
431 return get_string_literal(ptr->get_data(), ptr->get_literal());
432 }
433 case token_types::value:
434 return static_cast<token_value *>(token)->get_value();
435 break;
436 case token_types::expr:
437 return parse_expr(static_cast<token_expr *>(token)->get_tree().root());
438 break;
439 case token_types::array: {
440 array arr;
441 token_base *ptr = nullptr;
442 for (auto &tree : static_cast<token_array *>(token)->get_array()) {
443 ptr = tree.root().data();
444 if (ptr != nullptr && ptr->get_type() == token_types::expand) {
445 var val = parse_expr(static_cast<token_expand *>(ptr)->get_tree().root());
446 const auto &child_arr = val.const_val<array>();
447 for (auto &it : child_arr)
448 arr.push_back(copy(it));
449 }
450 else
451 arr.push_back(copy(parse_expr(tree.root())));
452 }
453 return rvalue(var::make<array>(std::move(arr)));
454 }
455 case token_types::parallel: {
456 if (disable_parallel)
457 throw runtime_error("Do not allowed parallel list.");
458 var result;
459 for (auto &tree : static_cast<token_parallel *>(token)->get_parallel())
460 result = parse_expr(tree.root());
461 return result;
462 }
463 case token_types::signal: {
464 switch (static_cast<token_signal *>(token)->get_signal()) {
465 default:
466 break;
467 case signal_types::add_:

Callers 11

covscript_mainFunction · 0.80
evalFunction · 0.80
opt_exprMethod · 0.80
call_rlMethod · 0.80
call_elMethod · 0.80
do_inheritMethod · 0.80
operator()Method · 0.80
run_implMethod · 0.80
repl_run_implMethod · 0.80
parse_usingMethod · 0.80
solveFunction · 0.80

Calls 12

internal_errorClass · 0.85
runtime_errorClass · 0.85
rvalueFunction · 0.85
dataMethod · 0.80
get_signalMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80
copyFunction · 0.50
moveFunction · 0.50
usableMethod · 0.45
get_typeMethod · 0.45
rootMethod · 0.45

Tested by

no test coverage detected