HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_index_node.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "formula_binary_operator_node.hpp"
8
9namespace hi::inline v1 {
10
14 {
15 }
16
17 datum evaluate(formula_evaluation_context &context) const override
18 {
19 auto lhs_ = lhs->evaluate(context);
20 auto rhs_ = rhs->evaluate(context);
21
22 if (holds_alternative<datum::map_type>(lhs_) and not lhs_.contains(rhs_)) {
23 throw operation_error(std::format("{}: Unknown key '{}'.", location, rhs_));
24 }
25
26 try {
27 return lhs_[rhs_];
28 } catch (std::exception const &e) {
29 throw operation_error(std::format("{}: Can not evaluate indexing operation.\n{}", location, e.what()));
30 }
31 }
32
34 {
35 auto &lhs_ = lhs->evaluate_lvalue(context);
36 auto rhs_ = rhs->evaluate(context);
37 try {
38 return lhs_[rhs_];
39 } catch (std::exception const &e) {
40 throw operation_error(std::format("{}: Can not evaluate indexing operation.\n{}", location, e.what()));
41 }
42 }
43
44 std::string string() const noexcept override
45 {
46 return std::format("({}[{}])", *lhs, *rhs);
47 }
48};
49
50} // namespace hi::inline v1
A dynamic data type.
Definition datum.hpp:209
Exception thrown during execution of a dynamic operation.
Definition exception.hpp:37
Definition formula_binary_operator_node.hpp:11
Definition formula_evaluation_context.hpp:16
Definition formula_index_node.hpp:11
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_index_node.hpp:17
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_index_node.hpp:33
Definition parse_location.hpp:17
T move(T... args)
T what(T... args)