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