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

Function read_word

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

Reads one identifier-like word into `buf`. Returns -1 when the word cannot be an ASCII keyword. The whole word is always consumed, so a failed keyword check never leaves the lexer mid-identifier.

Source from the content-addressed store, hash-verified

449// cannot be an ASCII keyword. The whole word is always consumed, so a
450// failed keyword check never leaves the lexer mid-identifier.
451static int read_word(TSLexer *lexer, char *buf, int cap) {
452 int len = 0;
453 bool not_keyword = false;
454 while (is_alnum(lexer->lookahead) || lexer->lookahead == '_' ||
455 lexer->lookahead == '$') {
456 if (lexer->lookahead > 127 || len >= cap - 1) {
457 not_keyword = true;
458 } else {
459 buf[len] = (char)lexer->lookahead;
460 len++;
461 }
462 advance(lexer);
463 }
464 buf[len] = '\0';
465 return not_keyword ? -1 : len;
466}
467
468static bool word_in(const char *word, const char *const words[],
469 unsigned count) {

Callers 5

word_is_expression_tailFunction · 0.85
inline_modifier_followsFunction · 0.85
is_case_definition_wordFunction · 0.85
scan_rest_of_lineFunction · 0.85
scan_implFunction · 0.85

Calls 2

is_alnumFunction · 0.85
advanceFunction · 0.70

Tested by

no test coverage detected