HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
skeleton_placeholder_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 "skeleton_node.hpp"
8
9namespace tt {
10
13
15 skeleton_node(std::move(location)), expression(std::move(expression))
16 {
17 }
18
19 [[nodiscard]] bool should_left_align() const noexcept override
20 {
21 return false;
22 }
23
24 void post_process(formula_post_process_context &context) override
25 {
26 try {
27 expression->post_process(context);
28
29 } catch (...) {
30 auto error_location = location;
31 if (ttlet expression_location = error_info::peek<parse_location, "parse_location">()) {
32 error_location += *expression_location;
33 }
34 error_info(true).set<"parse_location">(error_location);
35 throw;
36 }
37 }
38
39 std::string string() const noexcept override
40 {
41 return fmt::format("<placeholder {}>", *expression);
42 }
43
45 {
46 ttlet output_size = context.output_size();
47
48 ttlet tmp = evaluate_expression(context, *expression, location);
49 if (tmp.is_break()) {
50 tt_error_info().set<"parse_location">(location);
51 throw operation_error("Found #break not inside a loop statement.");
52
53 } else if (tmp.is_continue()) {
54 tt_error_info().set<"parse_location">(location);
55 throw operation_error("Found #continue not inside a loop statement.");
56
57 } else if (tmp.is_undefined()) {
58 return {};
59
60 } else {
61 // When a function returns, it should not have written data to the output.
62 context.set_output_size(output_size);
63 context.write(static_cast<std::string>(tmp));
64 return {};
65 }
66 }
67};
68
69} // namespace tt
Exception thrown during execution of a dynamic operation.
Definition exception.hpp:37
Definition formula_evaluation_context.hpp:16
void write(std::string_view text) noexcept
Write data to the output.
Definition formula_evaluation_context.hpp:51
void set_output_size(ssize_t new_size) noexcept
Set the size of the output.
Definition formula_evaluation_context.hpp:67
ssize_t output_size() const noexcept
Get the size of the output.
Definition formula_evaluation_context.hpp:60
Definition formula_post_process_context.hpp:18
Definition parse_location.hpp:16
Definition skeleton_node.hpp:16
Definition skeleton_placeholder_node.hpp:11
bool should_left_align() const noexcept override
Should any spaces on the left side of a statement be removed?
Definition skeleton_placeholder_node.hpp:19
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_placeholder_node.hpp:44
T move(T... args)