From 5c4e844c2c9c25324c3c1cb6d47b2967f65c633d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 10 Jul 2015 07:31:55 -0700 Subject: Bugfix: lexer loses unmatched "hold char" between top-level forms. Test case: file containing 4(prinl 3). Scanner consumes 4 and (. The ( is lost when the scanner is reset for the next call to yyparse, resulting in jut prinl being read and interpreted as a variable. * parser.c (prime_parser): If present, append hold byte to priming string. Takes parser_t * instead of parser, and returns void now. * parser.l (reset_scanner): Now returns int value, the value of the scanner's yy_hold_char variable which is nonzero when the scanner is hanging on to an unmatched byte of input. * parser.h (reset_scanner, prime_parser): Declarations updated. * parser.y (parse): Pass hold byte returned by reset_scanner to prime_parser. --- parser.l | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 4739dd59..29a45ab1 100644 --- a/parser.l +++ b/parser.l @@ -960,12 +960,16 @@ void end_of_char(scanner_t *yyg) yy_pop_state(yyg); } -void reset_scanner(scanner_t *yyg) +int reset_scanner(scanner_t *yyg) { + int hold_byte = yyg->yy_hold_char; + while (YYSTATE != INITIAL) yy_pop_state(yyg); yy_flush_buffer(YY_CURRENT_BUFFER, yyg); + + return hold_byte; } val source_loc(val form) -- cgit v1.2.3