add scan_repeat_literal to scanner

This commit is contained in:
2025-12-07 18:11:34 +01:00
parent c0d6f53808
commit e3bfde5826
2 changed files with 9 additions and 0 deletions
+1
View File
@@ -233,6 +233,7 @@ void scanner_error(scanner_t *s, const char *message);
void scanner_error_and_recover(scanner_t *s, const char *message);
bool scan_eof(scanner_t *s);
bool scan_literal(scanner_t *s, const char *lit);
int scan_repeat_literal(scanner_t *s, const char *lit);
bool scan_whitespace(scanner_t *s);
bool scan_digit(scanner_t *s);
bool scan_i64(scanner_t *s);
+8
View File
@@ -76,6 +76,14 @@ bool scan_literal(scanner_t *s, const char *lit) {
return false;
}
int scan_repeat_literal(scanner_t *s, const char *lit) {
int n_repeats = 0;
while (scan_literal(s, lit)) {
n_repeats++;
}
return n_repeats;
}
bool scan_whitespace(scanner_t *s) {
const char *save = s->cur;
while (isspace((unsigned char)*s->cur)) s->cur++;