Skip to content

Commit cffb2a8

Browse files
authored
Do not permit empty binary/hexadecimal constants (#130)
Initially I wanted to support the syntax `#b`, but this was never properly added and can be accomplished by `(eo::to_bin 0 0)`. Currently we give an unintuitive error, this fixes this case.
1 parent 5e09d99 commit cffb2a8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/lexer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,19 @@ Token Lexer::computeNextToken()
239239
{
240240
case 'b':
241241
pushToToken(ch);
242-
// parse [01]*
243-
parseCharList(CharacterClass::BIT);
242+
// parse [01]+
243+
if (!parseNonEmptyCharList(CharacterClass::BIT))
244+
{
245+
parseError("Error expected bit string");
246+
}
244247
return Token::BINARY_LITERAL;
245248
case 'x':
246249
pushToToken(ch);
247-
// parse [0-9a-fA-F]*
248-
parseCharList(CharacterClass::HEXADECIMAL_DIGIT);
250+
// parse [0-9a-fA-F]+
251+
if (!parseNonEmptyCharList(CharacterClass::HEXADECIMAL_DIGIT))
252+
{
253+
parseError("Error expected hexadecimal string");
254+
}
249255
return Token::HEX_LITERAL;
250256
default:
251257
// otherwise error

0 commit comments

Comments
 (0)