# HG changeset patch # User John W. Eaton # Date 1583763921 14400 # Node ID a04cb1364af450e105a6305a774737bbc1f8c587 # Parent 27c0b26e5a9f7716c7a21450012ea389fd72797a# Parent 648202bebcb0cbb4f7cedbcae2398040bc2f6636 maint: merge stable to default. diff -r 27c0b26e5a9f -r a04cb1364af4 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Sun Mar 08 17:54:55 2020 -0400 +++ b/libinterp/parse-tree/lex.ll Mon Mar 09 10:25:21 2020 -0400 @@ -237,25 +237,29 @@ } \ while (0) -// We can't rely on the trick used elsewhere of sticking ASCII 1 in -// the input buffer and recognizing it as a special case because ASCII -// 1 is a valid character for a character string. If we are at the -// end of the buffer, ask for more input. If we are at the end of the -// file, deal with it. Otherwise, just keep going with the text from -// the current buffer. +#define HANDLE_EOB_OR_EOF(STATUS) \ + do \ + { \ + if (curr_lexer->is_push_lexer ()) \ + { \ + if (curr_lexer->at_end_of_buffer ()) \ + return STATUS; \ + \ + if (curr_lexer->at_end_of_file ()) \ + return curr_lexer->handle_end_of_input (); \ + } \ + } \ + while (0) + +// If we are at the end of the buffer, ask for more input. +// If we are at the end of the file, deal with it. +// Otherwise, just keep going with the text from the current buffer. #define HANDLE_STRING_CONTINUATION \ do \ { \ curr_lexer->m_filepos.next_line (); \ \ - if (curr_lexer->is_push_lexer ()) \ - { \ - if (curr_lexer->at_end_of_buffer ()) \ - return -1; \ - \ - if (curr_lexer->at_end_of_file ()) \ - return curr_lexer->handle_end_of_input (); \ - } \ + HANDLE_EOB_OR_EOF (-1); \ } \ while (0) @@ -666,6 +670,8 @@ curr_lexer->m_comment_text = "\n"; curr_lexer->m_block_comment_nesting_level++; + + HANDLE_EOB_OR_EOF (-1); } %{ @@ -690,8 +696,16 @@ curr_lexer->m_block_comment_nesting_level--; + int status = -1; + if (curr_lexer->m_block_comment_nesting_level == 0) - curr_lexer->pop_start_state (); + { + status = -2; + + curr_lexer->pop_start_state (); + } + + HANDLE_EOB_OR_EOF (status); } %{ @@ -703,6 +717,8 @@ curr_lexer->m_filepos.next_line (); curr_lexer->m_comment_text += yytext; + + HANDLE_EOB_OR_EOF (-1); } %{ @@ -802,15 +818,17 @@ {ANY_INCLUDING_NL} { curr_lexer->lexer_debug ("{ANY_INCLUDING_NL}"); + curr_lexer->finish_comment (octave::comment_elt::full_line); + + curr_lexer->pop_start_state (); + + HANDLE_EOB_OR_EOF (-2); + // Restore all characters except the ASCII 1 marker that was // inserted by push_lexer::fill_flex_buffer. if (yytext[0] != '\001') curr_lexer->xunput (yytext[0]); - - curr_lexer->finish_comment (octave::comment_elt::full_line); - - curr_lexer->pop_start_state (); } %{ diff -r 27c0b26e5a9f -r a04cb1364af4 libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy Sun Mar 08 17:54:55 2020 -0400 +++ b/libinterp/parse-tree/oct-parse.yy Mon Mar 09 10:25:21 2020 -0400 @@ -4661,7 +4661,12 @@ if (token < 0) { - status = -1; + // TOKEN == -2 means that the lexer recognized a comment + // and we should be at the end of the buffer but not the + // end of the file so we should return 0 to indicate + // "complete input" instead of -1 to request more input. + + status = (token == -2 ? 0 : -1); if (! eof && m_lexer.at_end_of_buffer ()) return status;