Try to lex an identifier or keyword starting at position i. Returns true if matched. */
| 285 | |
| 286 | /* Try to lex an identifier or keyword starting at position i. Returns true if matched. */ |
| 287 | static bool lex_try_ident(const char *input, int len, int *i, cbm_lex_result_t *out) { |
| 288 | char c = input[*i]; |
| 289 | if (!isalpha((unsigned char)c) && c != '_') { |
| 290 | return false; |
| 291 | } |
| 292 | int start = *i; |
| 293 | while (*i < len && (isalnum((unsigned char)input[*i]) || input[*i] == '_')) { |
| 294 | (*i)++; |
| 295 | } |
| 296 | char word[CBM_SZ_256]; |
| 297 | int wlen = *i - start; |
| 298 | if (wlen >= (int)sizeof(word)) { |
| 299 | wlen = (int)sizeof(word) - SKIP_ONE; |
| 300 | } |
| 301 | memcpy(word, input + start, wlen); |
| 302 | word[wlen] = '\0'; |
| 303 | cbm_token_type_t type = keyword_lookup(word); |
| 304 | lex_push_n(out, type, input + start, *i - start, start); |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | /* Try to lex a number starting at position i. Returns true if matched. */ |
| 309 | static bool lex_try_number(const char *input, int len, int *i, cbm_lex_result_t *out) { |
no test coverage detected