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

Function cs_lex_code

internal/cbm/doclink_cs.c:1699–1750  ·  view source on GitHub ↗

Scan code from src[i]. In a `hole` (the code of an interpolation) nothing * is reported and the scan returns just past the brace that closes it. */

Source from the content-addressed store, hash-verified

1697/* Scan code from src[i]. In a `hole` (the code of an interpolation) nothing
1698 * is reported and the scan returns just past the brace that closes it. */
1699static uint32_t cs_lex_code(cs_lex_t *lx, uint32_t i, bool hole) {
1700 const char *src = lx->src;
1701 uint32_t n = lx->n;
1702 int depth = 0;
1703 bool line_start = !hole;
1704 while (i < n) {
1705 unsigned char c = (unsigned char)src[i];
1706 lx->steps++;
1707 if (isspace(c)) {
1708 line_start = line_start || c == '\n';
1709 i++;
1710 continue;
1711 }
1712 if (c == '#' && line_start) {
1713 i = cs_lex_directive(lx, i, hole);
1714 continue;
1715 }
1716 line_start = false;
1717 uint32_t e = cs_lex_comment(lx, i);
1718 if (e > i) {
1719 i = e;
1720 continue;
1721 }
1722 bool sep = c == ':' || c == ',';
1723 bool partial = false;
1724 if (c == '\'') {
1725 e = cs_lex_char(lx, i);
1726 } else if (c == '{' || c == '}') {
1727 if (hole && c == '}' && depth == 0) {
1728 return i + SKIP_ONE;
1729 }
1730 if (hole) {
1731 depth += c == '{' ? SKIP_ONE : -SKIP_ONE;
1732 } else {
1733 cs_lex_brace(lx->ud, i, c == '{');
1734 }
1735 e = i + SKIP_ONE;
1736 } else {
1737 e = (c == '"' || c == '$' || c == '@') ? cs_lex_literal(lx, i) : i;
1738 if (e == i && (cs_lex_word(c) || c == '@')) {
1739 e = cs_lex_identifier(lx, i, hole, &partial);
1740 }
1741 if (e == i) {
1742 e = i + SKIP_ONE;
1743 }
1744 }
1745 lx->prev_sep = sep;
1746 lx->prev_partial = partial;
1747 i = e;
1748 }
1749 return n;
1750}
1751
1752/* Scan the file's braces and declaration keywords, pair the braces. The
1753 * first brace without a partner (or conditional whose branches disagree)

Callers 2

cs_lex_holeFunction · 0.85
cs_scan_tokensFunction · 0.85

Calls 7

cs_lex_directiveFunction · 0.85
cs_lex_commentFunction · 0.85
cs_lex_charFunction · 0.85
cs_lex_braceFunction · 0.85
cs_lex_literalFunction · 0.85
cs_lex_wordFunction · 0.85
cs_lex_identifierFunction · 0.85

Tested by

no test coverage detected