MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scan_string_start

Function scan_string_start

codegraph-kernel/grammars/kotlin/scanner.c:139–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137// Scanner functions
138
139static bool scan_string_start(TSLexer *lexer, Stack *stack) {
140 // The stack is serialized whole, two bytes per open string, so it holds at
141 // most TREE_SITTER_SERIALIZATION_BUFFER_SIZE / 2 of them. When it is full,
142 // decline the string start before consuming any input; the parser then
143 // recovers with an ERROR node instead of the scanner aborting the host.
144 if (stack->size + 2 > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) return false;
145
146 // Count leading '$' signs (the interpolation prefix). The counter stops one
147 // past PREFIX_LEN_MAX, which is enough to tell "too long" from an exact
148 // length and cannot wrap no matter how many '$' the input supplies.
149 uint32_t dollars = 0;
150 while (lexer->lookahead == '$') {
151 advance(lexer);
152 if (dollars <= PREFIX_LEN_MAX) dollars++;
153 }
154 uint16_t prefix_len;
155 if (dollars == 0) {
156 // Regular strings with no prefix still use a single '$' as the trigger.
157 prefix_len = 1;
158 } else if (dollars > PREFIX_LEN_MAX) {
159 prefix_len = PREFIX_LEN_UNREPRESENTABLE;
160 } else {
161 prefix_len = (uint16_t)dollars;
162 }
163
164 if (lexer->lookahead != '"') return false;
165 advance(lexer);
166 lexer->mark_end(lexer);
167 for (unsigned count = 1; count < DELIMITER_LENGTH; ++count) {
168 if (lexer->lookahead != '"') {
169 // It's not a triple quoted delimiter.
170 stack_push(stack, '"', false, prefix_len);
171 return true;
172 }
173 advance(lexer);
174 }
175 lexer->mark_end(lexer);
176 stack_push(stack, '"', true, prefix_len);
177 return true;
178}
179
180static bool scan_string_content(TSLexer *lexer, Stack *stack,
181 const bool *valid_symbols) {

Callers 1

scan_tokenFunction · 0.85

Calls 2

stack_pushFunction · 0.85
advanceFunction · 0.70

Tested by

no test coverage detected