Prevent trailing _ for all numbers (#1706)

* moved _ check to scan_number_suffix
* Skipping underscore on list-operators command
* Disallow # from operator, update release notes
This commit is contained in:
Aaron
2024-12-23 14:23:46 -06:00
committed by GitHub
parent bf74ef0e5e
commit f34eb7d9f3
3 changed files with 8 additions and 12 deletions

View File

@@ -17,6 +17,8 @@
- Fix bug outputting exported functions without predefined extname.
- Fix problem where crt1 was linked for dynamic libraries on Linux and BSD. #1710
- Fix CRT detection on Arch Linux.
- Fix lexer allowing a trailing underscore (_) with hex and binary literals.
- Fix `--list-operators` CLI command printing underscore (_) and hash (#).
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.

View File

@@ -939,7 +939,7 @@ void print_syntax(BuildOptions *options)
if (i == TOKEN_DOCS_START || i == TOKEN_DOCS_END) continue;
const char *name = token_type_to_string((TokenType)i);
char first_char = name[0];
if (first_char == '$' || first_char == '@'
if (first_char == '$' || first_char == '@' || first_char == '_' || first_char == '#'
|| (first_char >= 'a' && first_char <= 'z')
|| (first_char >= 'A' && first_char <= 'Z'))
{

View File

@@ -370,6 +370,11 @@ static inline bool scan_ident(Lexer *lexer, TokenType normal, TokenType const_to
*/
static bool scan_number_suffix(Lexer *lexer, bool *is_float)
{
if (prev(lexer) == '_')
{
backtrack(lexer);
return add_error_token_at_current(lexer, "The number ended with '_', which isn't allowed, please remove it.");
}
char c = peek(lexer);
if (!char_is_alphanum_(c)) return true;
switch (c | 32)
@@ -535,11 +540,6 @@ static inline bool scan_hex(Lexer *lexer)
is_float = true;
if (!scan_exponent(lexer)) return false;
}
if (prev(lexer) == '_')
{
backtrack(lexer);
return add_error_token_at_current(lexer, "The number ended with '_', which isn't allowed, please remove it.");
}
if (!scan_number_suffix(lexer, &is_float)) return false;
return new_token(lexer, is_float ? TOKEN_REAL : TOKEN_INTEGER, lexer->lexing_start);
}
@@ -581,12 +581,6 @@ static inline bool scan_dec(Lexer *lexer)
is_float = true;
if (!scan_exponent(lexer)) return false;
}
if (prev(lexer) == '_')
{
backtrack(lexer);
return add_error_token_at_current(lexer, "The number ended with '_', which isn't allowed, please remove it.");
}
if (!scan_number_suffix(lexer, &is_float)) return false;
return new_token(lexer, is_float ? TOKEN_REAL : TOKEN_INTEGER, lexer->lexing_start);
}