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

Function scan_string_content

codegraph-kernel/grammars/scala/scanner.c:320–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318} StringMode;
319
320static bool scan_string_content(TSLexer *lexer, bool is_multiline, StringMode string_mode) {
321 LOG("scan_string_content(%d, %d, %c)\n", is_multiline, string_mode, lexer->lookahead);
322 unsigned closing_quote_count = 0;
323 for (;;) {
324 if (lexer->lookahead == '"') {
325 advance(lexer);
326 closing_quote_count++;
327 if (!is_multiline) {
328 lexer->result_symbol = SINGLE_LINE_STRING_END;
329 lexer->mark_end(lexer);
330 return true;
331 }
332 if (closing_quote_count >= 3 && lexer->lookahead != '"') {
333 lexer->result_symbol = MULTILINE_STRING_END;
334 lexer->mark_end(lexer);
335 return true;
336 }
337 } else if (lexer->lookahead == '$' && string_mode != STRING_MODE_SIMPLE) {
338 switch (string_mode) {
339 case STRING_MODE_INTERPOLATED:
340 lexer->result_symbol = is_multiline ? INTERPOLATED_MULTILINE_STRING_MIDDLE : INTERPOLATED_STRING_MIDDLE;
341 break;
342 case STRING_MODE_RAW:
343 lexer->result_symbol = is_multiline ? RAW_STRING_MULTILINE_MIDDLE : RAW_STRING_MIDDLE;
344 break;
345 default:
346 assert(false);
347 }
348 lexer->mark_end(lexer);
349 return true;
350 } else {
351 closing_quote_count = 0;
352 if (lexer->lookahead == '\\') {
353 // Multiline strings ignore escape sequences
354 if (is_multiline || string_mode == STRING_MODE_RAW) {
355 // FIXME: In raw string mode, we have to jump over escaped quotes.
356 advance(lexer);
357 // In single-line raw strings, `\"` is not translated to `"`, but it also does
358 // not close the string. Likewise, `\\` is not translated to `\`, but it does
359 // stop the second `\` from stopping a double-quote from closing the string.
360 if (!is_multiline && string_mode == STRING_MODE_RAW &&
361 (lexer->lookahead == '"' || lexer->lookahead == '\\')) {
362 advance(lexer);
363 }
364 } else {
365 lexer->result_symbol = string_mode == STRING_MODE_SIMPLE ? SIMPLE_STRING_MIDDLE : INTERPOLATED_STRING_MIDDLE;
366 lexer->mark_end(lexer);
367 return true;
368 }
369 // During error recovery and dynamic precedence resolution, the external
370 // scanner will be invoked with all valid_symbols set to true, which means
371 // we will be asked to scan a string token when we are not actually in a
372 // string context. Here we detect these cases and return false.
373 } else if (lexer->lookahead == '\n' && !is_multiline) {
374 return false;
375 } else if (lexer->eof(lexer)) {
376 return false;
377 } else {

Callers 1

scan_implFunction · 0.70

Calls 1

advanceFunction · 0.70

Tested by

no test coverage detected