Ultra 0.9.4
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_STRING_PRIMITIVE_H)
14#define ULTRA_STRING_PRIMITIVE_H
15
16#include <cstdlib>
17#include <string>
18
19#include "kernel/terminal.h"
20#include "kernel/gp/function.h"
21
22namespace ultra::str
23{
24
25class literal : public terminal
26{
27public:
28 explicit literal(const std::string &s,
30 : terminal(s, c)
31 {
32 Expects(!s.empty());
33 }
34
35 [[nodiscard]] value_t instance() const final
36 {
37 return name();
38 }
39};
40
44class ife : public function
45{
46public:
47 explicit ife(return_type r, const param_data_types &pt)
48 : function("SIFE", r, pt)
49 {
50 Expects(pt.size() == 4);
51 Expects(r == pt[2]);
52 Expects(pt[0] == pt[1]);
53 Expects(pt[2] == pt[3]);
54 }
55
56 [[nodiscard]] std::string to_string(format f) const final
57 {
58 switch (f)
59 {
60 case python_format: return "({2} if {0} == {1} else {3})";
61 default: return "({0}=={1} ? {2} : {3})";
62 }
63 }
64
65 [[nodiscard]] value_t eval(const params &pars) const final
66 {
67 const auto v0(pars[0]);
68 if (!has_value(v0)) return v0;
69
70 const auto v1(pars[1]);
71 if (!has_value(v1)) return v1;
72
73 return v0 == v1 ? pars[2] : pars[3];
74 }
75};
76
77} // namespace ultra::str
78
79#endif // include guard
Definition function.h:108
std::vector< category_t > param_data_types
Definition function.h:49
function(const std::string &, return_type, param_data_types)
Definition function.cc:27
category_t return_type
Type used to describe the return category of the function.
Definition function.h:52
value_t eval(const params &pars) const final
Definition string.h:65
std::string to_string(format f) const final
Definition string.h:56
value_t instance() const final
Definition string.h:35
format
Supported rendering formats for symbol stringification.
Definition symbol.h:72
unsigned category_t
Definition symbol.h:55
static constexpr category_t default_category
Default category assigned when typing is not used.
Definition symbol.h:58
const std::string & name() const noexcept
Definition symbol.cc:51
Definition terminal.h:41
bool has_value(const value_t &v) noexcept
Definition value.cc:31
std::variant< D_VOID, D_INT, D_DOUBLE, D_STRING, const D_NULLARY *, D_ADDRESS, const D_VARIABLE *, D_IVECTOR > value_t
Definition value.h:54