segment: Properly handle DO REPEAT in batch mode.
[pspp] / tests / language / lexer / segment.at
index e1dd0b5eb4f313a519aa26a13352508db259394d..04a77a9b8fd103ebc0b09e3a2533cc7e13d7d32d 100644 (file)
@@ -1,7 +1,31 @@
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl
 AT_BANNER([syntax segmentation])
 m4_define([PSPP_CHECK_SEGMENT],
-  [AT_CHECK([segment-test $1 input], [0], [expout])
-   AT_CHECK([segment-test -1 $1 input], [0], [expout])])
+  [for strip in "" "-s"; do
+     case $strip in # (
+        '') sed 's/^-//' < expout-base > expout ;; # (
+       -s) sed '/^-/d' < expout-base > expout ;;
+     esac
+     AT_CHECK([segment-test $1 $strip input], [0], [expout])
+     AT_CHECK([segment-test -1 $strip $1 input], [0], [expout])
+     AT_CHECK([segment-test -0 $strip $1 input])
+     AT_CHECK([segment-test -01 $strip $1 input])
+   done])
 \f
 AT_SETUP([identifiers])
 AT_KEYWORDS([segment])
@@ -18,7 +42,7 @@ f@#_.#6
 GhIjK
 .x 1y _z
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      a    space
 identifier      ab    space
 identifier      abc    space
@@ -79,9 +103,9 @@ number          1
 identifier      y    space
 unexpected_char \_
 identifier      z
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -107,7 +131,7 @@ wxyz./* unterminated end of line comment
 WXYZ. /* unterminated end of line comment
 WxYz./* unterminated end of line comment @&t@
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      abcd.    space
 identifier      abcd
 end_command     .
@@ -185,9 +209,9 @@ newline         \n (first)
 identifier      WxYz
 end_command     .
 comment         /*_unterminated_end_of_line_comment_
-newline         \n (first)
-
-end             <U+0000>
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -200,7 +224,7 @@ AND OR NOT EQ GE GT LE LT NE ALL BY TO WITH
 andx orx notx eqx gex gtx lex ltx nex allx byx tox withx
 and. with.
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 reserved_word   and    space
 reserved_word   or    space
 reserved_word   not    space
@@ -249,9 +273,9 @@ newline         \n (later)
 identifier      and.    space
 reserved_word   with
 end_command     .
-newline         \n (first)
-
-end             <U+0000>
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -262,7 +286,7 @@ AT_DATA([input], [dnl
 ~ & | = >= > <= < ~= <> ( ) , - + * / [[ ]] **
 ~&|=>=><=<~=<>(),-+*/[[]]**
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 punct           ~    space
 punct           &    space
 punct           |    space
@@ -305,9 +329,9 @@ punct           /
 punct           [[
 punct           ]]
 punct           **
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -323,7 +347,7 @@ AT_DATA([input], [dnl
 1.23e1 45.6E-1 78.9e+1 99.9E+01 11.2e-03
 . 1e e1 1e+ 1e-
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 number          0    space
 number          1    space
 number          01    space
@@ -372,9 +396,9 @@ expected_exponent 1e    space
 identifier      e1    space
 expected_exponent 1e+    space
 expected_exponent 1e-
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -395,7 +419,7 @@ u'fffd' U"041"
 + /* also a punctuator on blank line
 - 'new command'
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 quoted_string   'x'    space
 quoted_string   "y"    space
 quoted_string   'abc'
@@ -444,9 +468,9 @@ newline         \n (later)
 
 start_command   -    space
 quoted_string   'new_command'
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -458,7 +482,7 @@ AT_DATA([input], [dnl
 title my title.
 #! /usr/bin/pspp
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 shbang          #!_/usr/bin/pspp
 newline         \n (first)
 
@@ -475,9 +499,9 @@ punct           /
 identifier      bin
 punct           /
 identifier      pspp
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -502,7 +526,7 @@ com is ambiguous with COMPUTE.
 next command.
 
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 comment_command *_Comment_commands_"don't
 newline         \n (COMMENT)
 
@@ -540,7 +564,7 @@ identifier      COMPUTE
 end_command     .
 newline         \n (first)
 
-separate_commands 
+separate_commands
 newline         \n (first)
 
 spaces          ___
@@ -548,7 +572,7 @@ comment_command *_Comment_need_not_start_at_left_margin
 end_command     .
 newline         \n (first)
 
-separate_commands 
+separate_commands
 newline         \n (first)
 
 comment_command *_Comment_ends_with_blank_line
@@ -562,10 +586,10 @@ identifier      command
 end_command     .
 newline         \n (first)
 
-separate_commands
-newline         \n (first)
-
-end             <U+0000>
+-separate_commands
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -584,10 +608,10 @@ isn't parsed as tokens
 
 second paragraph.
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 start_document
 document        DOCUMENT_one_line.
-end_command     
+end_command
 separate_commands
 newline         \n (first)
 
@@ -602,7 +626,7 @@ document        ________one
 newline         \n (DOCUMENT)
 
 document        ____________line.
-end_command     
+end_command
 separate_commands
 newline         \n (first)
 
@@ -620,11 +644,11 @@ document
 newline         \n (DOCUMENT)
 
 document        second_paragraph.
-end_command     
-separate_commands
-newline         \n (first)
-end             <U+0000>
+-end_command
+-separate_commands
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -648,7 +672,7 @@ FILE /*
 /**/  lab not quoted here either
 
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      title
 comment         /**/
 quoted_string   'Quoted_string_title'
@@ -710,10 +734,10 @@ identifier      lab    space
 unquoted_string not_quoted_here_either
 newline         \n (later)
 
-separate_commands
-newline         \n (first)
-
-end             <U+0000>
+-separate_commands
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -745,7 +769,7 @@ begin data "xxx".
 begin data 123.
 not data
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      begin    space
 identifier      data
 end_command     .
@@ -788,7 +812,7 @@ newline         \n (data)
 inline_data     5_6_7_/*_x
 newline         \n (data)
 
-inline_data     
+inline_data
 newline         \n (data)
 
 inline_data     end__data
@@ -836,9 +860,9 @@ newline         \n (first)
 
 reserved_word   not    space
 identifier      data
-newline         \n (later)
-
-end             <U+0000>
+-newline         \n (later)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
@@ -860,7 +884,7 @@ do
   inner command.
 end repeat.
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      do    space
 identifier      repeat    space
 identifier      x
@@ -918,13 +942,97 @@ newline         \n (DO REPEAT)
 identifier      end    space
 identifier      repeat
 end_command     .
-newline         \n (first)
-
-end             <U+0000>
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-i])
 AT_CLEANUP
 \f
+AT_SETUP([DO REPEAT command in batch mode])
+AT_KEYWORDS([segment])
+AT_DATA([input], [dnl
+do repeat x=a b c
+          y=d e f
+do repeat a=1 thru 5
+another command
+second command
++ third command
+end /* x */ /* y */ repeat print
+end
+ repeat
+do
+  repeat #a=1
+
+  inner command
+end repeat
+])
+AT_DATA([expout-base], [dnl
+identifier      do    space
+identifier      repeat    space
+identifier      x
+punct           =
+identifier      a    space
+identifier      b    space
+identifier      c
+newline         \n (later)
+
+spaces          __________
+identifier      y
+punct           =
+identifier      d    space
+identifier      e    space
+identifier      f
+newline         \n (later)
+
+start_command
+do_repeat_command do_repeat_a=1_thru_5
+newline         \n (DO REPEAT)
+
+do_repeat_command another_command
+newline         \n (DO REPEAT)
+
+do_repeat_command second_command
+newline         \n (DO REPEAT)
+
+do_repeat_command +_third_command
+newline         \n (DO REPEAT)
+
+do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print
+newline         \n (DO REPEAT)
+
+identifier      end
+newline         \n (later)
+    space
+identifier      repeat
+newline         \n (later)
+
+start_command
+identifier      do
+newline         \n (later)
+
+spaces          __
+identifier      repeat    space
+identifier      #a
+punct           =
+number          1
+newline         \n (later)
+
+separate_commands
+newline         \n (DO REPEAT)
+
+do_repeat_command __inner_command
+newline         \n (DO REPEAT)
+
+identifier      end    space
+identifier      repeat
+-newline         \n (later)
+-
+end
+])
+PSPP_CHECK_SEGMENT([-b])
+AT_CLEANUP
+\f
 AT_SETUP([batch mode])
 AT_KEYWORDS([segment])
 AT_DATA([input], [dnl
@@ -936,7 +1044,7 @@ third command
 fourth command.
    fifth command.
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      first    space
 identifier      command
 newline         \n (later)
@@ -972,9 +1080,9 @@ spaces          ___
 identifier      fifth    space
 identifier      command
 end_command     .
-newline         \n (first)
-
-end             <U+0000>
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-b])
 AT_CLEANUP
@@ -996,7 +1104,7 @@ twostep cluster
 fourth command.
    fifth command.
 ])
-AT_DATA([expout], [dnl
+AT_DATA([expout-base], [dnl
 identifier      command
 newline         \n (later)
 
@@ -1062,9 +1170,9 @@ spaces          ___
 identifier      fifth    space
 identifier      command
 end_command     .
-newline         \n (first)
-
-end             <U+0000>
+-newline         \n (first)
+-
+end
 ])
 PSPP_CHECK_SEGMENT([-a])
 AT_CLEANUP