17 using const_iterator =
typename std::string_view::const_iterator;
25 std::optional<const_iterator> text_segment_start;
41 [[nodiscard]]
char const& operator*() const noexcept {
45 [[nodiscard]]
bool atEOF() const noexcept {
49 template_parse_context& operator++() noexcept {
56 template_parse_context& operator+=(ssize_t x)
noexcept {
57 for (ssize_t i = 0; i != x; ++i) {
63 bool starts_with(std::string_view text)
const noexcept {
64 return ::tt::starts_with(index, last, text.begin(), text.end());
67 bool starts_with_and_advance_over(std::string_view text)
noexcept {
68 if (starts_with(text)) {
76 bool advance_to(std::string_view text)
noexcept {
78 if (starts_with(text)) {
86 bool advance_over(std::string_view text)
noexcept {
87 if (advance_to(text)) {
99 template<
typename T,
typename... Args>
100 void push(Args &&... args) {
101 statement_stack.
push_back(std::make_unique<T>(std::forward<Args>(args)...));
106 template<
typename T,
typename... Args>
107 [[nodiscard]]
bool append(Args &&... args)
noexcept {
108 if (statement_stack.
size() > 0) {
109 return append(std::make_unique<T>(std::forward<Args>(args)...));
119 [[nodiscard]]
bool pop() noexcept;
121 void start_of_text_segment(
int back_track = 0) noexcept;
122 void end_of_text_segment();
124 [[nodiscard]]
bool top_statement_is_do() const noexcept;
158 [[nodiscard]]
virtual bool found_else(parse_location _location)
noexcept {
return false;}
161 virtual void post_process(expression_post_process_context &context) {}
176 auto tmp = evaluate(context);
177 if (tmp.is_break()) {
180 }
else if (tmp.is_continue()) {
181 TTAURI_THROW(invalid_operation_error(
"Found #continue not inside a loop statement.").set_location(location));
183 }
else if (tmp.is_undefined()) {
187 TTAURI_THROW(invalid_operation_error(
"Found #return not inside a function.").set_location(location));
192 auto context = expression_evaluation_context{};
193 return evaluate_output(context);
196 [[nodiscard]]
virtual std::string string() const noexcept {
197 return "<template_node>";
209 if (ssize(children) > 0 && new_child->should_left_align()) {
210 children.back()->left_align();
212 children.push_back(
std::move(new_child));
215 [[nodiscard]]
static datum evaluate_expression_without_output(expression_evaluation_context &context, expression_node
const &expression, parse_location
const &location) {
217 return expression.evaluate_without_output(context);
219 e.merge_location(location);
224 [[nodiscard]]
static datum evaluate_expression(expression_evaluation_context &context, expression_node
const &expression, parse_location
const &location) {
226 return expression.evaluate(context);
228 e.merge_location(location);
233 static void post_process_expression(expression_post_process_context &context, expression_node &expression, parse_location
const &location) {
235 return expression.post_process(context);
237 e.merge_location(location);
243 [[nodiscard]]
static datum evaluate_children(expression_evaluation_context &context, statement_vector
const &children) {
244 for (ttlet &child: children) {
245 ttlet tmp = child->evaluate(context);
246 if (!tmp.is_undefined()) {
virtual bool append(std::unique_ptr< template_node > x) noexcept
Append a template-piece to the current template.
Definition template.hpp:147