diff libinterp/parse-tree/lex.ll @ 18311:b14cdae65abd stable

prevent lexer from matching patterns across CR line endings (bug #41281) * lex.ll: Use [^\r\n]*{NL} instead of .*{NL} to avoid matching patterns across lines that use CR only as line endings.
author John W. Eaton <jwe@octave.org>
date Mon, 20 Jan 2014 01:34:26 -0500
parents 1f072ae35ede
children 7ac2a8b758fc f59459404f55
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Wed Jan 15 15:22:03 2014 -0500
+++ b/libinterp/parse-tree/lex.ll	Mon Jan 20 01:34:26 2014 -0500
@@ -256,6 +256,7 @@
 EXPON   ([DdEe][+-]?{D}+)
 NUMBER  (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+))
 
+ANY_EXCEPT_NL [^\r\n]
 ANY_INCLUDING_NL (.|{NL})
 
 %%
@@ -537,8 +538,8 @@
 // Body of a block comment.
 %}
 
-<BLOCK_COMMENT_START>.*{NL} {
-    curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>.*{NL}");
+<BLOCK_COMMENT_START>{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>{ANY_EXCEPT_NL}*{NL}");
 
     curr_lexer->input_line_number++;
     curr_lexer->current_input_column = 1;
@@ -549,15 +550,15 @@
 // Full-line or end-of-line comment.
 %}
 
-{S}*{CCHAR}.*{NL} {
-    curr_lexer->lexer_debug ("{S}*{CCHAR}.*{NL}");
+{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}");
 
     curr_lexer->push_start_state (LINE_COMMENT_START);
     yyless (0);
   }
 
-<LINE_COMMENT_START>{S}*{CCHAR}.*{NL} {
-    curr_lexer->lexer_debug ("<LINE_COMMENT_START>{S}*{CCHAR}.*{NL}");
+<LINE_COMMENT_START>{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("<LINE_COMMENT_START>{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}");
 
     bool full_line_comment = curr_lexer->current_input_column == 1;
     curr_lexer->input_line_number++;
@@ -770,8 +771,8 @@
   }
 
 <DQ_STRING_START>(\.\.\.){S}*{NL} |
-<DQ_STRING_START>(\.\.\.){S}*{CCHAR}.*{NL} {
-    curr_lexer->lexer_debug ("<DQ_STRING_START>(\\.\\.\\.){S}*{NL}|<DQ_STRING_START>(\\.\\.\\.){S}*{CCHAR}.*{NL}");
+<DQ_STRING_START>(\.\.\.){S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("<DQ_STRING_START>(\\.\\.\\.){S}*{NL}|<DQ_STRING_START>(\\.\\.\\.){S}*{CCHAR}{ANY_EXCEPT_NL}*{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";
 
@@ -788,8 +789,8 @@
   }
 
 <DQ_STRING_START>\\{S}+{NL} |
-<DQ_STRING_START>\\{S}*{CCHAR}.*{NL} {
-    curr_lexer->lexer_debug ("<DQ_STRING_START>\\\\{S}+{NL}|<DQ_STRING_START>\\\\{S}*{CCHAR}.*{NL}");
+<DQ_STRING_START>\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("<DQ_STRING_START>\\\\{S}+{NL}|<DQ_STRING_START>\\\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{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";
 
@@ -975,8 +976,8 @@
 // Continuation lines.  Allow arbitrary text after continuations.
 %}
 
-\.\.\..*{NL} {
-    curr_lexer->lexer_debug ("\\.\\.\\..*{NL}");
+\.\.\.{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("\\.\\.\\.{ANY_EXCEPT_NL}*{NL}");
 
     curr_lexer->handle_continuation ();
   }
@@ -986,8 +987,8 @@
 %}
 
 \\{S}*{NL} |
-\\{S}*{CCHAR}.*{NL} {
-    curr_lexer->lexer_debug ("\\\\{S}*{NL}|\\\\{S}*{CCHAR}.*{NL}");
+\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} {
+    curr_lexer->lexer_debug ("\\\\{S}*{NL}|\\\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}");
 
     static const char *msg = "using continuation marker \\ outside of double quoted strings is deprecated and will be removed in a future version of Octave";