MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tf_string

Function tf_string

src/pipeline/pass_terraform.c:74–130  ·  view source on GitHub ↗

A string value of file text `src` in module directory `mdir`: a literal, or * a template of literals and ${path.module}. false when any part is something * else. */

Source from the content-addressed store, hash-verified

72 * a template of literals and ${path.module}. false when any part is something
73 * else. */
74static bool tf_string(const char *src, const char *mdir, TSNode n, char *out, size_t sz) {
75 size_t len = 0;
76 out[0] = '\0';
77 while (tf_type(n, "expression") || tf_type(n, "literal_value") || tf_type(n, "template_expr") ||
78 tf_type(n, "string_lit") || tf_type(n, "quoted_template")) {
79 if (tf_type(n, "string_lit") || tf_type(n, "quoted_template")) {
80 break;
81 }
82 if (ts_node_named_child_count(n) != SKIP_ONE) {
83 return false;
84 }
85 n = ts_node_named_child(n, 0);
86 }
87 if (!tf_type(n, "string_lit") && !tf_type(n, "quoted_template")) {
88 return false;
89 }
90 for (uint32_t i = 0; i < ts_node_named_child_count(n); i++) {
91 TSNode c = ts_node_named_child(n, i);
92 uint32_t b = ts_node_start_byte(c);
93 uint32_t e = ts_node_end_byte(c);
94 if (tf_type(c, "quoted_template_start") || tf_type(c, "quoted_template_end")) {
95 continue;
96 }
97 if (tf_type(c, "template_literal")) {
98 if (!tf_add(out, sz, &len, src + b, e - b)) {
99 return false;
100 }
101 continue;
102 }
103 if (!tf_type(c, "template_interpolation")) {
104 return false;
105 }
106 /* ${path.module} only */
107 TSNode expr = {0};
108 for (uint32_t j = 0; j < ts_node_named_child_count(c); j++) {
109 if (tf_type(ts_node_named_child(c, j), "expression")) {
110 expr = ts_node_named_child(c, j);
111 }
112 }
113 if (ts_node_is_null(expr)) {
114 return false;
115 }
116 uint32_t xb = ts_node_start_byte(expr);
117 uint32_t xe = ts_node_end_byte(expr);
118 static const char PATH_MODULE[] = "path.module";
119 if (xe - xb != sizeof(PATH_MODULE) - SKIP_ONE ||
120 strncmp(src + xb, PATH_MODULE, xe - xb) != 0) {
121 return false;
122 }
123 /* an absolute marker: the module directory, from the repo root */
124 if (!tf_add(out, sz, &len, "\x01", SKIP_ONE) ||
125 !tf_add(out, sz, &len, mdir, strlen(mdir))) {
126 return false;
127 }
128 }
129 return true;
130}
131

Callers 3

tf_helm_releaseFunction · 0.85
tf_mod_callFunction · 0.85
tf_literalFunction · 0.85

Calls 2

tf_typeFunction · 0.85
tf_addFunction · 0.85

Tested by

no test coverage detected