segment: Refine treatment of start of macro body.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 30 May 2021 20:31:39 +0000 (13:31 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 30 May 2021 20:31:45 +0000 (13:31 -0700)
Previously, if the first line of the macro body (the same line as the
closing parenthesis in the DEFINE) was blank, we reported it as a blank
line to the lexer.  The parser for DEFINE could check for that (by seeing
whether the first line of macro body was empty or all-spaces) but it seems
more elegant to do it in the segmenter.  This implements that.

src/language/lexer/segment.c
tests/language/lexer/scan.at
tests/language/lexer/segment.at

index 1a8e8a6b5fb54c479ba988855777aaf3834b0432..a4fea0b213118559d474b94a2bc4efa4008ff0d0 100644 (file)
@@ -1512,7 +1512,10 @@ segmenter_parse_define_2__ (struct segmenter *s,
     {
       s->nest--;
       if (!s->nest)
-        s->state = S_DEFINE_3;
+        {
+          s->state = S_DEFINE_3;
+          s->substate = 0;
+        }
       return ofs;
     }
 
@@ -1554,9 +1557,15 @@ segmenter_parse_define_3__ (struct segmenter *s,
 
          The line might be blank, whether completely empty or just spaces and
          comments.  That's OK: we need to report blank lines because they can
-         have significance. */
-      *type = SEG_MACRO_BODY;
+         have significance.
+
+         However, if the first line of the macro body (the same line as the
+         closing parenthesis in the argument definition) is blank, we just
+         report it as spaces because it's not significant. */
+      *type = (s->substate == 0 && is_all_spaces (input, ofs)
+               ? SEG_SPACES : SEG_MACRO_BODY);
       s->state = S_DEFINE_4;
+      s->substate = 1;
       return ofs;
     }
   else
index d778d07fa2097af516b0086748c14ee582997202..d1fb66fcbeb5dd90deefefc81c62a32f851149e4 100644 (file)
@@ -894,7 +894,7 @@ SKIP
 MACRO_ID "!macro1"
 LPAREN
 RPAREN
-STRING ""
+SKIP
 SKIP
 STRING "var1 var2 var3"
 SKIP
@@ -940,7 +940,7 @@ SKIP
 MACRO_ID "!macro1"
 LPAREN
 RPAREN
-STRING ""
+SKIP
 SKIP
 STRING "var1 var2 var3"
 MACRO_ID "!enddefine"
@@ -983,6 +983,34 @@ SKIP
 MACRO_ID "!macro1"
 LPAREN
 RPAREN
+SKIP
+SKIP
+MACRO_ID "!enddefine"
+ENDCMD
+-SKIP
+STOP
+])
+PSPP_CHECK_SCAN([-i])
+AT_CLEANUP
+\f
+AT_SETUP([DEFINE command - blank lines])
+AT_KEYWORDS([scan])
+AT_DATA([input], [dnl
+define !macro1()
+
+
+!enddefine.
+])
+AT_DATA([expout-base], [dnl
+ID "define"
+SKIP
+MACRO_ID "!macro1"
+LPAREN
+RPAREN
+SKIP
+SKIP
+STRING ""
+SKIP
 STRING ""
 SKIP
 MACRO_ID "!enddefine"
@@ -1018,7 +1046,7 @@ ID "c"
 LPAREN
 RPAREN
 RPAREN
-STRING ""
+SKIP
 SKIP
 MACRO_ID "!enddefine"
 ENDCMD
@@ -1063,7 +1091,7 @@ LPAREN
 RPAREN
 SKIP
 RPAREN
-STRING ""
+SKIP
 SKIP
 MACRO_ID "!enddefine"
 ENDCMD
@@ -1096,7 +1124,7 @@ COMMA
 ID "z"
 SKIP
 RPAREN
-STRING ""
+SKIP
 SKIP
 STRING "content 1"
 SKIP
@@ -1241,7 +1269,7 @@ SKIP
 MACRO_ID "!macro1"
 LPAREN
 RPAREN
-STRING ""
+SKIP
 SKIP
 STRING "content line 1"
 SKIP
index 65a271f69865d59b83305c63224985ad1f196c4a..67e647d2214ec8c22daa1bf753ed2c7fabe99114 100644 (file)
@@ -1066,7 +1066,7 @@ identifier      define    space
 macro_id        !macro1
 punct           (
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_body      var1_var2_var3
@@ -1115,7 +1115,7 @@ identifier      define    space
 macro_id        !macro1
 punct           (
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_body      var1_var2_var3
@@ -1159,7 +1159,7 @@ identifier      define    space
 macro_id        !macro1
 punct           (
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_id        !enddefine
@@ -1184,7 +1184,7 @@ identifier      define    space
 macro_id        !macro1
 punct           (
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_body
@@ -1224,7 +1224,7 @@ identifier      c
 punct           (
 punct           )
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_id        !enddefine
@@ -1273,7 +1273,7 @@ punct           )
 newline         \n (later)
 
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_id        !enddefine
@@ -1309,7 +1309,7 @@ identifier      z
 newline         \n (later)
 
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_body      content_1
@@ -1451,7 +1451,7 @@ identifier      define    space
 macro_id        !macro1
 punct           (
 punct           )
-macro_body
+spaces
 newline         \n (DEFINE)
 
 macro_body      content_line_1