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 hi::inline v1 {
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 (std::exception const &e) {
30 throw operation_error(std::format("{}: Could not post process placeholder.\n{}", location, e.what()));
31 }
32 }
33
34 std::string string() const noexcept override
35 {
36 return std::format("<placeholder {}>", *expression);
37 }
38
40 {
41 hilet output_size = context.output_size();
42
43 hilet tmp = evaluate_expression(context, *expression, location);
44 if (tmp.is_break()) {
45 throw operation_error(std::format("{}: Found #break not inside a loop statement.", location));
46
47 } else if (tmp.is_continue()) {
48 throw operation_error(std::format("{}: Found #continue not inside a loop statement.", location));
49
50 } else if (tmp.is_undefined()) {
51 return {};
52
53 } else {
54 // When a function returns, it should not have written data to the output.
55 context.set_output_size(output_size);
56 context.write(static_cast<std::string>(tmp));
57 return {};
58 }
59 }
60};
61
62} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
A dynamic data type.
Definition datum.hpp:219
Definition formula_evaluation_context.hpp:15
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:59
void write(std::string_view text) noexcept
Write data to the output.
Definition formula_evaluation_context.hpp:49
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:18
Definition skeleton_node.hpp:16
Definition skeleton_placeholder_node.hpp:11
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_placeholder_node.hpp:39
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
T move(T... args)
T what(T... args)