nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.38k stars 7.69k forks source link

stb_c_lexer: Adding support for octal and hexadecimal chars #1380

Open danil-kondr2016 opened 1 year ago

danil-kondr2016 commented 1 year ago

This commit adds support of octal and hexadecimal codes of characters in string and char literals.

nothings commented 1 year ago

if I'm reading the diffs right, there are multiple problems that should be straightforward to fix

style improvements:

danil-kondr2016 commented 1 year ago

Thank you for feedback. I'll fix these errors.

nothings commented 1 year ago

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);

danil-kondr2016 commented 1 year ago

I have fixed errors which you told about.