mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Factor out isBinDigit and parseHexDigit utility functions
This commit is contained in:
@@ -1009,6 +1009,10 @@ static bool isValidDigit(char c) {
|
||||
return isAlphanumeric(c) || c == '.' || c == '#' || c == '@';
|
||||
}
|
||||
|
||||
static bool isBinDigit(int c) {
|
||||
return c == '0' || c == '1' || c == options.binDigits[0] || c == options.binDigits[1];
|
||||
}
|
||||
|
||||
static bool checkDigitErrors(char const *digits, size_t n, char const *type) {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
char c = digits[i];
|
||||
@@ -1074,10 +1078,7 @@ static uint32_t readBinaryNumber(char const *prefix) {
|
||||
if (value > (UINT32_MAX - bit) / 2) {
|
||||
warning(WARNING_LARGE_CONSTANT, "Integer constant is too large");
|
||||
// Discard any additional digits
|
||||
skipChars([](int d) {
|
||||
return d == '0' || d == '1' || d == options.binDigits[0]
|
||||
|| d == options.binDigits[1] || d == '_';
|
||||
});
|
||||
skipChars([](int d) { return isBinDigit(d) || d == '_'; });
|
||||
return 0;
|
||||
}
|
||||
value = value * 2 + bit;
|
||||
@@ -1107,11 +1108,10 @@ static uint32_t readOctalNumber(char const *prefix) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isOctDigit(c)) {
|
||||
c = c - '0';
|
||||
} else {
|
||||
if (!isOctDigit(c)) {
|
||||
break;
|
||||
}
|
||||
c = c - '0';
|
||||
empty = false;
|
||||
nonDigit = false;
|
||||
|
||||
@@ -1148,11 +1148,10 @@ static uint32_t readDecimalNumber(int initial) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isDigit(c)) {
|
||||
c = c - '0';
|
||||
} else {
|
||||
if (!isDigit(c)) {
|
||||
break;
|
||||
}
|
||||
c = c - '0';
|
||||
nonDigit = false;
|
||||
|
||||
if (value > (UINT32_MAX - c) / 10) {
|
||||
@@ -1185,15 +1184,10 @@ static uint32_t readHexNumber(char const *prefix) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c >= 'a' && c <= 'f') {
|
||||
c = c - 'a' + 10;
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
c = c - 'A' + 10;
|
||||
} else if (isDigit(c)) {
|
||||
c = c - '0';
|
||||
} else {
|
||||
if (!isHexDigit(c)) {
|
||||
break;
|
||||
}
|
||||
c = parseHexDigit(c);
|
||||
empty = false;
|
||||
nonDigit = false;
|
||||
|
||||
@@ -1834,8 +1828,7 @@ static Token yylex_NORMAL() {
|
||||
|
||||
case '%': // Either %=, MOD, or a binary constant
|
||||
c = peek();
|
||||
if (c == '0' || c == '1' || c == options.binDigits[0] || c == options.binDigits[1]
|
||||
|| c == '_') {
|
||||
if (isBinDigit(c) || c == '_') {
|
||||
return Token(T_(NUMBER), readBinaryNumber("'%'"));
|
||||
}
|
||||
return oneOrTwo('=', T_(POP_MODEQ), T_(OP_MOD));
|
||||
|
||||
Reference in New Issue
Block a user