MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ parse()

static FieldSource MayaFlux::Kinesis::FieldSource::parse ( std::string  fn_name,
std::string_view  text 
)
inlinestatic

Extract return type, parameter list and body from lambda text.

Requires a trailing return type: the return type is read from between the arrow and the opening brace. A lambda without one yields an empty return_type, which valid() reports as a parse failure.

Parameters
fn_nameName the emitted GLSL function will carry.
textRaw text produced by MF_FIELD.
Returns
Populated FieldSource.

Definition at line 47 of file FieldSource.hpp.

48 {
49 FieldSource fs;
50 fs.name = std::move(fn_name);
51
52 const auto bracket = text.find('[');
53 const auto paren_open = text.find('(', bracket);
54 if (paren_open == std::string_view::npos)
55 return fs;
56
57 std::size_t depth = 1;
58 std::size_t paren_close = paren_open + 1;
59 while (paren_close < text.size() && depth > 0) {
60 if (text[paren_close] == '(') {
61 ++depth;
62 } else if (text[paren_close] == ')') {
63 --depth;
64 }
65 ++paren_close;
66 }
67 --paren_close;
68
69 fs.params = std::string(text.substr(paren_open + 1, paren_close - paren_open - 1));
70
71 const auto arrow = text.find("->", paren_close);
72 const auto brace_open = text.find('{', paren_close);
73 if (brace_open == std::string_view::npos)
74 return fs;
75
76 if (arrow != std::string_view::npos && arrow < brace_open) {
77 auto rt = text.substr(arrow + 2, brace_open - arrow - 2);
78 const auto b = rt.find_first_not_of(" \t\n\r");
79 const auto e = rt.find_last_not_of(" \t\n\r");
80 if (b != std::string_view::npos)
81 fs.return_type = std::string(rt.substr(b, e - b + 1));
82 }
83
84 depth = 1;
85 std::size_t brace_close = brace_open + 1;
86 while (brace_close < text.size() && depth > 0) {
87 if (text[brace_close] == '{') {
88 ++depth;
89 } else if (text[brace_close] == '}') {
90 --depth;
91 }
92 ++brace_close;
93 }
94 --brace_close;
95
96 fs.body = std::string(text.substr(brace_open + 1, brace_close - brace_open - 1));
97 return fs;
98 }
size_t b
uint32_t depth

References b, body, depth, name, params, and return_type.

Referenced by MayaFlux::Kinesis::dual_field(), and MayaFlux::Kinesis::temporal_field().

+ Here is the caller graph for this function: