mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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'))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user