add digit scanning function to scanner

This commit is contained in:
2025-12-07 00:12:47 +01:00
parent e13f66b9e4
commit c0d6f53808
2 changed files with 11 additions and 0 deletions
+2
View File
@@ -203,6 +203,7 @@ typedef struct error_node {
} error_node_t;
typedef union scan_value {
int digit;
uint8_t u8;
int8_t i8;
uint16_t u16;
@@ -233,6 +234,7 @@ 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);
bool scan_whitespace(scanner_t *s);
bool scan_digit(scanner_t *s);
bool scan_i64(scanner_t *s);
bool scan_i32(scanner_t *s);
bool scan_i16(scanner_t *s);
+9
View File
@@ -82,6 +82,15 @@ bool scan_whitespace(scanner_t *s) {
return save != s->cur;
}
bool scan_digit(scanner_t *s) {
if (!isdigit((unsigned char)*s->cur)) {
return false;
}
s->value.digit = (*s->cur) - '0';
s->cur++;
return true;
}
bool scan_i64(scanner_t *s) {
const char *save = s->cur;
if (*s->cur == '-' || *s->cur == '+') s->cur++;