passing scanner
This commit is contained in:
@@ -335,12 +335,26 @@ bool scanner_print_errors(scanner_t *s, FILE *fp) {
|
|||||||
|
|
||||||
bool looks_like_float(scanner_t *s) {
|
bool looks_like_float(scanner_t *s) {
|
||||||
const char *cur = s->cur;
|
const char *cur = s->cur;
|
||||||
if (*cur == '+' || *cur == '-') cur++;
|
if (
|
||||||
if (!isdigit((unsigned char)*(cur++))) return false;
|
((*cur) == '+') ||
|
||||||
while (isdigit((unsigned char)*(cur++)));
|
((*cur) == '-')
|
||||||
if (*cur != '.') return false;
|
) {
|
||||||
cur++;
|
cur++;
|
||||||
return isdigit((unsigned char)*cur);
|
}
|
||||||
|
if (!isdigit(((unsigned char)*cur))) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
cur++;
|
||||||
|
}
|
||||||
|
while (isdigit(((unsigned char)*cur))) {
|
||||||
|
cur++;
|
||||||
|
}
|
||||||
|
if ((*cur) != '.') {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
cur++;
|
||||||
|
}
|
||||||
|
return isdigit(((unsigned char)*cur));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool looks_like_int(scanner_t *s) {
|
bool looks_like_int(scanner_t *s) {
|
||||||
|
|||||||
+6
-3
@@ -21,7 +21,8 @@ Test(scanner, looks_like_float) {
|
|||||||
with_borrow(allocator) {
|
with_borrow(allocator) {
|
||||||
scanner_t scanner = make_scanner("test", buffer, allocator);
|
scanner_t scanner = make_scanner("test", buffer, allocator);
|
||||||
while (!scan_eof(&scanner)) {
|
while (!scan_eof(&scanner)) {
|
||||||
bool actual = looks_like_float(&scanner);
|
bool does_look_like_float = looks_like_float(&scanner);
|
||||||
|
bool does_look_like_int = looks_like_float(&scanner);
|
||||||
while (*scanner.cur++ != ' ');
|
while (*scanner.cur++ != ' ');
|
||||||
bool expect;
|
bool expect;
|
||||||
if (scan_literal(&scanner, "true")) {
|
if (scan_literal(&scanner, "true")) {
|
||||||
@@ -32,8 +33,10 @@ Test(scanner, looks_like_float) {
|
|||||||
assert(false && "invalid expectation");
|
assert(false && "invalid expectation");
|
||||||
}
|
}
|
||||||
scan_whitespace(&scanner);
|
scan_whitespace(&scanner);
|
||||||
cr_assert_eq(actual, expect);
|
cr_assert_eq(does_look_like_float, expect);
|
||||||
|
if (does_look_like_float) {
|
||||||
|
cr_assert(does_look_like_int);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user