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

Function tdx_argument

internal/cbm/extract_defs.c:5854–5921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5852}
5853
5854static bool tdx_argument(CBMExtractCtx *ctx, size_t at, int wanted, size_t *name_at,
5855 size_t *name_length, size_t *after, const TDXRule *rule, uint32_t line) {
5856 const char *s = ctx->source;
5857 size_t n = (size_t)ctx->source_len;
5858 if (!tdx_trivia(s, n, &at) || at >= n || s[at] != '(')
5859 return tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_FORM, rule->declaration, line);
5860 char closing[64] = {')'};
5861 size_t depth = 1, begin = ++at, selected_begin = 0, selected_end = 0;
5862 int argument = 0;
5863 bool selected = false, closed = false;
5864 while (at < n && depth) {
5865 if (!tdx_trivia(s, n, &at) || at >= n || s[at] == '\0' || tdx_splice(s, n, at))
5866 break;
5867 if (tdx_pp_number(s, n, &at))
5868 continue;
5869 char c = s[at];
5870 if (c == '"' || c == '\'') {
5871 if (!tdx_literal(s, n, &at))
5872 break;
5873 continue;
5874 }
5875 if (c == '(' || c == '[' || c == '{') {
5876 if (depth == sizeof(closing))
5877 break;
5878 closing[depth++] = c == '(' ? ')' : c == '[' ? ']' : '}';
5879 } else if (c == ')' || c == ']' || c == '}') {
5880 if (c != closing[depth - 1])
5881 break;
5882 if (--depth == 0) {
5883 if (argument == wanted) {
5884 selected_begin = begin;
5885 selected_end = at;
5886 selected = true;
5887 }
5888 *after = at + 1;
5889 closed = true;
5890 break;
5891 }
5892 } else if (c == ',' && depth == 1) {
5893 if (argument == wanted) {
5894 selected_begin = begin;
5895 selected_end = at;
5896 selected = true;
5897 }
5898 argument++;
5899 begin = at + 1;
5900 }
5901 at++;
5902 }
5903 if (!closed)
5904 return tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_FORM, rule->declaration, line);
5905 if (!selected)
5906 return tdx_issue(ctx->result, CBM_TEST_EXTRACT_MISSING_ARGUMENT, rule->declaration, line);
5907 at = selected_begin;
5908 if (!tdx_trivia(s, selected_end, &at) || at == selected_end)
5909 return tdx_issue(ctx->result, CBM_TEST_EXTRACT_MISSING_ARGUMENT, rule->declaration, line);
5910 if (!tdx_ident_first((unsigned char)s[at]))
5911 return tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_ARGUMENT, rule->declaration,

Callers 1

tdx_resolveFunction · 0.85

Calls 7

tdx_triviaFunction · 0.85
tdx_issueFunction · 0.85
tdx_spliceFunction · 0.85
tdx_pp_numberFunction · 0.85
tdx_literalFunction · 0.85
tdx_ident_firstFunction · 0.85
tdx_identFunction · 0.85

Tested by

no test coverage detected