add digit scanning function to scanner
This commit is contained in:
@@ -203,6 +203,7 @@ typedef struct error_node {
|
|||||||
} error_node_t;
|
} error_node_t;
|
||||||
|
|
||||||
typedef union scan_value {
|
typedef union scan_value {
|
||||||
|
int digit;
|
||||||
uint8_t u8;
|
uint8_t u8;
|
||||||
int8_t i8;
|
int8_t i8;
|
||||||
uint16_t u16;
|
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_eof(scanner_t *s);
|
||||||
bool scan_literal(scanner_t *s, const char *lit);
|
bool scan_literal(scanner_t *s, const char *lit);
|
||||||
bool scan_whitespace(scanner_t *s);
|
bool scan_whitespace(scanner_t *s);
|
||||||
|
bool scan_digit(scanner_t *s);
|
||||||
bool scan_i64(scanner_t *s);
|
bool scan_i64(scanner_t *s);
|
||||||
bool scan_i32(scanner_t *s);
|
bool scan_i32(scanner_t *s);
|
||||||
bool scan_i16(scanner_t *s);
|
bool scan_i16(scanner_t *s);
|
||||||
|
|||||||
@@ -82,6 +82,15 @@ bool scan_whitespace(scanner_t *s) {
|
|||||||
return save != s->cur;
|
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) {
|
bool scan_i64(scanner_t *s) {
|
||||||
const char *save = s->cur;
|
const char *save = s->cur;
|
||||||
if (*s->cur == '-' || *s->cur == '+') s->cur++;
|
if (*s->cur == '-' || *s->cur == '+') s->cur++;
|
||||||
|
|||||||
Reference in New Issue
Block a user