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

Function parse_unwind_clause

src/cypher/cypher.c:1880–1924  ·  view source on GitHub ↗

Parse UNWIND [...] AS var clause into query */

Source from the content-addressed store, hash-verified

1878
1879/* Parse UNWIND [...] AS var clause into query */
1880static void parse_unwind_clause(parser_t *p, cbm_query_t *q) {
1881 advance(p);
1882 if (check(p, TOK_LBRACKET)) {
1883 /* Literal list: [1, 2, 3] — collect as JSON array string */
1884 advance(p);
1885 char buf[CBM_SZ_2K] = "[";
1886 int blen = SKIP_ONE;
1887 /* snprintf returns the length it WOULD have written, so a single
1888 * oversized token (string literals lex up to CBM_SZ_4K-1) can push
1889 * blen past sizeof(buf). Clamp after every write and guard the raw
1890 * buf[blen++] stores, mirroring format_collect_list(). */
1891 const int cap = (int)sizeof(buf);
1892 while (!check(p, TOK_RBRACKET) && !check(p, TOK_EOF)) {
1893 if (blen > SKIP_ONE && blen < cap - SKIP_ONE) {
1894 buf[blen++] = ',';
1895 }
1896 if (check(p, TOK_STRING)) {
1897 blen += snprintf(buf + blen, (size_t)(cap - blen), "\"%s\"", peek(p)->text);
1898 advance(p);
1899 } else if (check(p, TOK_NUMBER)) {
1900 blen += snprintf(buf + blen, (size_t)(cap - blen), "%s", peek(p)->text);
1901 advance(p);
1902 } else {
1903 advance(p);
1904 }
1905 if (blen >= cap) {
1906 blen = cap - SKIP_ONE;
1907 }
1908 match(p, TOK_COMMA);
1909 }
1910 expect(p, TOK_RBRACKET);
1911 if (blen < cap - SKIP_ONE) {
1912 buf[blen++] = ']';
1913 }
1914 buf[blen] = '\0';
1915 q->unwind_expr = heap_strdup(buf);
1916 } else if (check(p, TOK_IDENT)) {
1917 q->unwind_expr = heap_strdup(advance(p)->text);
1918 }
1919 expect(p, TOK_AS);
1920 const cbm_token_t *alias = expect(p, TOK_IDENT);
1921 if (alias) {
1922 q->unwind_alias = heap_strdup(alias->text);
1923 }
1924}
1925
1926/* Parse a chain of MATCH / OPTIONAL MATCH patterns into query.
1927 * Returns -1 on error (fills p->error). */

Callers 1

cbm_parseFunction · 0.85

Calls 6

advanceFunction · 0.85
peekFunction · 0.85
matchFunction · 0.85
expectFunction · 0.85
checkFunction · 0.70
heap_strdupFunction · 0.70

Tested by

no test coverage detected