From: Ben Pfaff Date: Sun, 30 May 2021 20:31:39 +0000 (-0700) Subject: segment: Refine treatment of start of macro body. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=74709d3f6d7c102bb3226f7f132c8be78ce8e8c2;p=pspp segment: Refine treatment of start of macro body. 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. --- diff --git a/src/language/lexer/segment.c b/src/language/lexer/segment.c index 1a8e8a6b5f..a4fea0b213 100644 --- a/src/language/lexer/segment.c +++ b/src/language/lexer/segment.c @@ -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 diff --git a/tests/language/lexer/scan.at b/tests/language/lexer/scan.at index d778d07fa2..d1fb66fcbe 100644 --- a/tests/language/lexer/scan.at +++ b/tests/language/lexer/scan.at @@ -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 + +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 diff --git a/tests/language/lexer/segment.at b/tests/language/lexer/segment.at index 65a271f698..67e647d221 100644 --- a/tests/language/lexer/segment.at +++ b/tests/language/lexer/segment.at @@ -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