# HG changeset patch # User John W. Eaton # Date 1373222750 14400 # Node ID bc12849bb6cc7f35fe2665eeabce7f5789740ccd # Parent d0558ee259ad479a100c83684564d63c74ebc9b5 deprecate ... and whitespace/comments after continuation markers in strings * lex.ll (HANDLE_STRING_CONTINUATION): New macro. Accept ... as continuation marker in double quoted strings but warn that they are deprecated. Likewise for whitespace and comments after backslash continuation markers. diff -r d0558ee259ad -r bc12849bb6cc libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Sun Jul 07 18:26:25 2013 +0100 +++ b/libinterp/parse-tree/lex.ll Sun Jul 07 14:45:50 2013 -0400 @@ -208,6 +208,31 @@ } \ 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_STRING_CONTINUATION \ + do \ + { \ + curr_lexer->decrement_promptflag (); \ + curr_lexer->input_line_number++; \ + curr_lexer->current_input_column = 1; \ + \ + 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 (); \ + } \ + } \ + while (0) + + static bool Vdisplay_tokens = false; static unsigned int Vtoken_count = 0; @@ -718,29 +743,46 @@ curr_lexer->string_text += '\v'; } +(\.\.\.){S}*{NL} | +(\.\.\.){S}*{CCHAR}.*{NL} { + curr_lexer->lexer_debug ("(\\.\\.\\.){S}*{NL}|(\\.\\.\\.){S}*{CCHAR}.*{NL}"); + + static const char *msg = "'...' continuations in double-quoted character strings are obsolete and will not be allowed in a future version of Octave; please use '\\' instead"; + + std::string nm = curr_lexer->fcn_file_full_name; + + if (nm.empty ()) + warning_with_id ("Octave:deprecated-syntax", "%s", msg); + else + warning_with_id ("Octave:deprecated-syntax", + "%s; near line %d of file '%s'", msg, + curr_lexer->input_line_number, nm.c_str ()); + + HANDLE_STRING_CONTINUATION; + } + +\\{S}+{NL} | +\\{S}*{CCHAR}.*{NL} { + curr_lexer->lexer_debug ("\\\\{S}+{NL}|\\\\{S}*{CCHAR}.*{NL}"); + + static const char *msg = "white space and comments after continuation markers in double-quoted character strings are obsolete and will not be allowed in a future version of Octave"; + + std::string nm = curr_lexer->fcn_file_full_name; + + if (nm.empty ()) + warning_with_id ("Octave:deprecated-syntax", "%s", msg); + else + warning_with_id ("Octave:deprecated-syntax", + "%s; near line %d of file '%s'", msg, + curr_lexer->input_line_number, nm.c_str ()); + + HANDLE_STRING_CONTINUATION; + } + \\{NL} { curr_lexer->lexer_debug ("\\\\{NL}"); - curr_lexer->decrement_promptflag (); - curr_lexer->input_line_number++; - curr_lexer->current_input_column = 1; - - if (curr_lexer->is_push_lexer ()) - { - // 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. - - if (curr_lexer->at_end_of_buffer ()) - return -1; - - if (curr_lexer->at_end_of_file ()) - return curr_lexer->handle_end_of_input (); - } + HANDLE_STRING_CONTINUATION; } \\. { @@ -750,8 +792,15 @@ curr_lexer->string_text += yytext[1]; } -[^\\\r\n\"]+ { - curr_lexer->lexer_debug ("[^\\\\\\r\\n\\\"]+"); +\. { + curr_lexer->lexer_debug ("\\."); + + curr_lexer->current_input_column++; + curr_lexer->string_text += yytext[0]; + } + +[^\.\\\r\n\"]+ { + curr_lexer->lexer_debug ("[^\\.\\\\\\r\\n\\\"]+"); curr_lexer->current_input_column += yyleng; curr_lexer->string_text += yytext;