From c0d6f5380854bcc9a4853c08c750f8a782e251d5 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Sun, 7 Dec 2025 00:12:47 +0100 Subject: [PATCH] add digit scanning function to scanner --- cig.h | 2 ++ scanner.c | 9 +++++++++ 2 files changed, 11 insertions(+) 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++;