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

Function scan_import_dot

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

Scan a dot in import identifiers. Matches '.' normally, but when the dot is followed by a newline and then the 'import' keyword, produces an AUTOMATIC_SEMICOLON (zero-width, before the dot) instead. This cleanly terminates the current import_header, preventing malformed imports (e.g. trailing dots) from bleeding into subsequent valid imports.

Source from the content-addressed store, hash-verified

1440// terminates the current import_header, preventing malformed imports
1441// (e.g. trailing dots) from bleeding into subsequent valid imports.
1442static bool scan_import_dot(TSLexer *lexer) {
1443 if (lexer->lookahead != '.') return false;
1444
1445 // Mark end BEFORE consuming the dot — this is where ASI would go
1446 lexer->mark_end(lexer);
1447
1448 advance(lexer);
1449
1450 // Peek ahead: skip horizontal whitespace, check for newline
1451 bool found_newline = false;
1452 while (iswspace(lexer->lookahead)) {
1453 if (lexer->lookahead == '\n' || lexer->lookahead == '\r') {
1454 found_newline = true;
1455 }
1456 skip(lexer);
1457 }
1458
1459 if (found_newline && lexer->lookahead == 'i' &&
1460 scan_for_word(lexer, "mport", 5)) {
1461 // Trailing dot followed by 'import' on next line — produce ASI
1462 // instead of the dot. mark_end was set before the dot, so the
1463 // semicolon is zero-width at that position.
1464 lexer->result_symbol = AUTOMATIC_SEMICOLON;
1465 return true;
1466 }
1467
1468 // Normal dot — include it in the token
1469 lexer->result_symbol = IMPORT_DOT;
1470 lexer->mark_end(lexer);
1471 return true;
1472}
1473
1474static bool scan_token(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
1475 // Pending work takes priority over constructor, ASI, string and

Callers 1

scan_tokenFunction · 0.85

Calls 3

scan_for_wordFunction · 0.85
advanceFunction · 0.70
skipFunction · 0.70

Tested by

no test coverage detected