Open danil-kondr2016 opened 1 year ago
if I'm reading the diffs right, there are multiple problems that should be straightforward to fix
*q
, so a one-character octal value won't be parsed properly inside a string (e.g. "\1foo"), which actually breaks the previously-supported case of \0long int_number
and for string literals it's sizeof(char)
so just check the result fits in 8-bits (but use the full parse). Note that this overflow checking is NOT done elsewhere in stb_c_lexer, but we should improve that, so this is a good place to start.style improvements:
*q
once at end for clarity in both octal and hex constants, might be clearest by advancing p
as you read and then doing *q = p
.unsigned
type, since that's a more natural fit for hex constantsThank you for feedback. I'll fix these errors.
Note that it looks like STB_C_LEXER_SELF_TEST just prints back the input string for string literals and char literals, which means you can't tell from that test that they're computing the wrong value in those cases. If the end location of a char literal is misparsed, that may or may not be recognized, but getting the end of the char literal wrong inside of a string literal will not be visible as well. So you really need to test char literals, and maybe modify the output in print_token to print the value of int_number in parenthesies, i.e. case CLEX_charlit : printf("'%s'(%d)", lexer->string, lexer->int_number);
I have fixed errors which you told about.
This commit adds support of octal and hexadecimal codes of characters in string and char literals.