~sircmpwn/harec

efc9cc3b09996522eece05d5a8dc126cfd568e2d — Ember Sawady 3 months ago d8db334
lex: make E and P in literals case-insensitive

Signed-off-by: Ember Sawady <ecs@d2evs.net>
2 files changed, 8 insertions(+), 0 deletions(-)

M src/lex.c
M tests/00-constants.ha
M src/lex.c => src/lex.c +4 -0
@@ 340,7 340,9 @@ lex_literal(struct lexer *lexer, struct token *out)
	static const char matching_states[0x80][6] = {
		['.'] = {DEC, HEX, 0},
		['e'] = {DEC, DEC | 1<<FLT, 0},
		['E'] = {DEC, DEC | 1<<FLT, 0},
		['p'] = {HEX, HEX | 1<<FLT, 0},
		['P'] = {HEX, HEX | 1<<FLT, 0},
		['+'] = {DEC | 1<<EXP | 1<<DIG, DEC | 1<<FLT | 1<<EXP | 1<<DIG, 0},
		['-'] = {DEC | 1<<EXP | 1<<DIG, DEC | 1<<FLT | 1<<EXP | 1<<DIG, 0},
		['i'] = {BIN, OCT, HEX, DEC, DEC | 1<<EXP, 0},


@@ 389,9 391,11 @@ lex_literal(struct lexer *lexer, struct token *out)
			break;
		case '-':
		case 'p':
		case 'P':
			state |= 1 << FLT;
			/* fallthrough */
		case 'e':
		case 'E':
		case '+':
			state |= DEC | 1 << EXP;
			exp = lexer->buflen - 1;

M tests/00-constants.ha => tests/00-constants.ha +4 -0
@@ 281,6 281,10 @@ fn numeric() void = {
		assert(_f64[j] == 0f64);
	};

	// capitalized exponent markers
	assert(0x0P0 == 0.0);
	assert(0E0 == 0);

	// double tuple subscript special case
	let tup = (('a', 'b'), 'c');
	assert(tup.0.0 == 'a');