diff --git a/cig.h b/cig.h index 5bb6b0d..fc09f5a 100644 --- a/cig.h +++ b/cig.h @@ -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); diff --git a/scanner.c b/scanner.c index e7722af..ee4f7cb 100644 --- a/scanner.c +++ b/scanner.c @@ -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++;