fix compilation on non-C99 compilers
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parent ed05048 · Browse files · 2 files·+61 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+61 added−12 removed
- tests:+47 added−0 removed
- other:+14 added−12 removed
Provenance
- Commit
83a2489- Tree
d7a7e1e- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent
ed05048
2 files changed+61 added−12 removed
modified:tests/c_lexer_test.c+47 added
1+#define STB_C_LEX_C_DECIMAL_INTS Y // "0|[1-9][0-9]*" CLEX_intlit2+#define STB_C_LEX_C_HEX_INTS Y // "0x[0-9a-fA-F]+" CLEX_intlit3+#define STB_C_LEX_C_OCTAL_INTS Y // "[0-7]+" CLEX_intlit4+#define STB_C_LEX_C_DECIMAL_FLOATS Y // "[0-9]*(.[0-9]*([eE][-+]?[0-9]+)?) CLEX_floatlit5+#define STB_C_LEX_C99_HEX_FLOATS Y // "0x{hex}+(.{hex}*)?[pP][-+]?{hex}+ CLEX_floatlit6+#define STB_C_LEX_C_IDENTIFIERS Y // "[_a-zA-Z][_a-zA-Z0-9]*" CLEX_id7+#define STB_C_LEX_C_DQ_STRINGS Y // double-quote-delimited strings with escapes CLEX_dqstring8+#define STB_C_LEX_C_SQ_STRINGS Y // single-quote-delimited strings with escapes CLEX_ssstring9+#define STB_C_LEX_C_CHARS Y // single-quote-delimited character with escape CLEX_charlits10+#define STB_C_LEX_C_COMMENTS Y // "/* comment */"11+#define STB_C_LEX_CPP_COMMENTS Y // "// comment to end of line\n"12+#define STB_C_LEX_C_COMPARISONS Y // "==" CLEX_eq "!=" CLEX_noteq "<=" CLEX_lesseq ">=" CLEX_greatereq13+#define STB_C_LEX_C_LOGICAL Y // "&&" CLEX_andand "||" CLEX_oror14+#define STB_C_LEX_C_SHIFTS Y // "<<" CLEX_shl ">>" CLEX_shr15+#define STB_C_LEX_C_INCREMENTS Y // "++" CLEX_plusplus "--" CLEX_minusminus16+#define STB_C_LEX_C_ARROW Y // "->" CLEX_arrow17+#define STB_C_LEX_EQUAL_ARROW Y // "=>" CLEX_eqarrow18+#define STB_C_LEX_C_BITWISEEQ Y // "&=" CLEX_andeq "|=" CLEX_oreq "^=" CLEX_xoreq19+#define STB_C_LEX_C_ARITHEQ Y // "+=" CLEX_pluseq "-=" CLEX_minuseq20+ // "*=" CLEX_muleq "/=" CLEX_diveq "%=" CLEX_modeq21+ // if both STB_C_LEX_SHIFTS & STB_C_LEX_ARITHEQ:22+ // "<<=" CLEX_shleq ">>=" CLEX_shreq23+24+#define STB_C_LEX_PARSE_SUFFIXES Y // letters after numbers are parsed as part of those numbers, and must be in suffix list below25+#define STB_C_LEX_DECIMAL_SUFFIXES "uUlL" // decimal integer suffixes e.g. "uUlL" -- these are returned as-is in string storage26+#define STB_C_LEX_HEX_SUFFIXES "lL" // e.g. "uUlL"27+#define STB_C_LEX_OCTAL_SUFFIXES "lL" // e.g. "uUlL"28+#define STB_C_LEX_FLOAT_SUFFIXES "uulL" //29+30+#define STB_C_LEX_0_IS_EOF N // if Y, ends parsing at '\0'; if N, returns '\0' as token31+#define STB_C_LEX_INTEGERS_AS_DOUBLES N // parses integers as doubles so they can be larger than 'int', but only if STB_C_LEX_STDLIB==N32+#define STB_C_LEX_MULTILINE_DSTRINGS Y // allow newlines in double-quoted strings33+#define STB_C_LEX_MULTILINE_SSTRINGS Y // allow newlines in single-quoted strings34+#define STB_C_LEX_USE_STDLIB N // use strtod,strtol for parsing #s; otherwise inaccurate hack35+#define STB_C_LEX_DOLLAR_IDENTIFIER Y // allow $ as an identifier character36+#define STB_C_LEX_FLOAT_NO_DECIMAL Y // allow floats that have no decimal point if they have an exponent37+38+#define STB_C_LEX_DEFINE_ALL_TOKEN_NAMES Y // if Y, all CLEX_ token names are defined, even if never returned39+ // leaving it as N should help you catch config bugs40+41+#define STB_C_LEX_DISCARD_PREPROCESSOR Y // discard C-preprocessor directives (e.g. after prepocess42+ // still have #line, #pragma, etc)43+44+#define STB_C_LEXER_DEFINITIONS // This line prevents the header file from replacing your definitions45+46+47+48 #define STB_C_LEXER_IMPLEMENTATION49 #define STB_C_LEXER_SELF_TEST50 #include "../stb_c_lexer.h"modified:stb_c_lexer.h+14 added-12 removed
725 unmodified lines726 #ifdef STB__clex_hex_ints727 #ifdef STB__CLEX_use_stdlib728 lexer->int_number = strtol((char *) p, (char **) &q, 16);729 #else730+ {730- stb__clex_int n=0;731- for (q=p+2; q != lexer->eof; ++q) {732- if (*q >= '0' && *q <= '9')733- n = n*16 + (*q - '0');734- else if (*q >= 'a' && *q <= 'f')735- n = n*16 + (*q - 'a') + 10;736- else if (*q >= 'A' && *q <= 'F')737- n = n*16 + (*q - 'A') + 10;738- else739- break;731+ stb__clex_int n=0;732+ for (q=p+2; q != lexer->eof; ++q) {733+ if (*q >= '0' && *q <= '9')734+ n = n*16 + (*q - '0');735+ else if (*q >= 'a' && *q <= 'f')736+ n = n*16 + (*q - 'a') + 10;737+ else if (*q >= 'A' && *q <= 'F')738+ n = n*16 + (*q - 'A') + 10;739+ else740+ break;741+ }742+ lexer->int_number = n;743 }741- lexer->int_number = n;744 #endif745 if (q == p+2)746 return stb__clex_token(lexer, CLEX_parse_error, p-2,p-1);747 return stb__clex_parse_suffixes(lexer, CLEX_intlit, p,q, STB_C_LEX_HEX_SUFFIXES);133 unmodified lines881 void dummy(void)882 {883 double some_floats[] = {884 1.0501, -10.4e12, 5E+10,883-#ifdef STB__clex_hex_floats885+#if 0 // not support in C++ or C-pre-99, so don't try to compile it886 0x1.0p+24, 0xff.FP-8, 0x1p-23,887 #endif888 4.889 };71 unmodified lines