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.
| 449 | // cannot be an ASCII keyword. The whole word is always consumed, so a |
| 450 | // failed keyword check never leaves the lexer mid-identifier. |
| 451 | static 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 | |
| 468 | static bool word_in(const char *word, const char *const words[], |
| 469 | unsigned count) { |
no test coverage detected