segment: Refine treatment of start of macro body.
[pspp] / tests / language / lexer / segment.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([syntax segmentation])
18 m4_define([PSPP_CHECK_SEGMENT],
19   [AT_CAPTURE_FILE([input])
20    for strip in "" "-s"; do
21      case $strip in # (
22         '') sed 's/^-//' < expout-base > expout ;; # (
23         -s) sed '/^-/d' < expout-base > expout ;;
24      esac
25      AT_CHECK([segment-test $1 $strip input], [0], [expout])
26      AT_CHECK([segment-test -1 $strip $1 input], [0], [expout])
27      AT_CHECK([segment-test -0 $strip $1 input])
28      AT_CHECK([segment-test -01 $strip $1 input])
29    done])
30 \f
31 AT_SETUP([identifiers])
32 AT_KEYWORDS([segment])
33 AT_DATA([input], [dnl
34 a ab abc abcd !abcd
35 A AB ABC ABCD !ABCD
36 aB aBC aBcD !aBcD
37 $x $y $z !$z
38 grève@<00A0>@Ângstrom@<00A0>@poté
39 #a #b #c ## #d !#d
40 @efg @ @@. @#@ !@ @&t@
41 ## # #12345 #.#
42 f@#_.#6
43 GhIjK
44 .x 1y _z
45 ])
46 AT_DATA([expout-base], [dnl
47 identifier      a    space
48 identifier      ab    space
49 identifier      abc    space
50 identifier      abcd    space
51 macro_id        !abcd
52 newline         \n (later)
53
54 identifier      A    space
55 identifier      AB    space
56 identifier      ABC    space
57 identifier      ABCD    space
58 macro_id        !ABCD
59 newline         \n (later)
60
61 identifier      aB    space
62 identifier      aBC    space
63 identifier      aBcD    space
64 macro_id        !aBcD
65 newline         \n (later)
66
67 identifier      $x    space
68 identifier      $y    space
69 identifier      $z    space
70 macro_id        !$z
71 newline         \n (later)
72
73 identifier      grève
74 spaces          <U+00A0>
75 identifier      Ângstrom
76 spaces          <U+00A0>
77 identifier      poté
78 newline         \n (later)
79
80 identifier      #a    space
81 identifier      #b    space
82 identifier      #c    space
83 identifier      ##    space
84 identifier      #d    space
85 macro_id        !#d
86 newline         \n (later)
87
88 identifier      @efg    space
89 identifier      @    space
90 identifier      @@.    space
91 identifier      @#@    space
92 macro_id        !@    space
93 newline         \n (later)
94
95 identifier      ##    space
96 identifier      #    space
97 identifier      #12345    space
98 identifier      #.#
99 newline         \n (later)
100
101 identifier      f@#\_.#6
102 newline         \n (later)
103
104 identifier      GhIjK
105 newline         \n (later)
106
107 start_command   .
108 identifier      x    space
109 number          1
110 identifier      y    space
111 punct           \_
112 identifier      z
113 -newline         \n (later)
114 -
115 end
116 ])
117 PSPP_CHECK_SEGMENT([-i])
118 AT_CLEANUP
119 \f
120 AT_SETUP([identifiers that end in '.'])
121 AT_KEYWORDS([segment])
122 AT_DATA([input], [dnl
123 abcd. abcd.
124 ABCD. ABCD.
125 aBcD. aBcD. @&t@
126 $y. $z. あいうえお.
127 #c. #d..
128 @@. @@....
129 #.#.
130 #abcd.
131 .
132 . @&t@
133 LMNOP. @&t@
134 QRSTUV./* end of line comment */
135 qrstuv. /* end of line comment */
136 QrStUv./* end of line comment */ @&t@
137 wxyz./* unterminated end of line comment
138 WXYZ. /* unterminated end of line comment
139 WxYz./* unterminated end of line comment @&t@
140 ])
141 AT_DATA([expout-base], [dnl
142 identifier      abcd.    space
143 identifier      abcd
144 end_command     .
145 newline         \n (first)
146
147 identifier      ABCD.    space
148 identifier      ABCD
149 end_command     .
150 newline         \n (first)
151
152 identifier      aBcD.    space
153 identifier      aBcD
154 end_command     .    space
155 newline         \n (first)
156
157 identifier      $y.    space
158 identifier      $z.    space
159 identifier      あいうえお
160 end_command     .
161 newline         \n (first)
162
163 identifier      #c.    space
164 identifier      #d.
165 end_command     .
166 newline         \n (first)
167
168 identifier      @@.    space
169 identifier      @@...
170 end_command     .
171 newline         \n (first)
172
173 identifier      #.#
174 end_command     .
175 newline         \n (first)
176
177 identifier      #abcd
178 end_command     .
179 newline         \n (first)
180
181 start_command   .
182 newline         \n (first)
183
184 start_command   .    space
185 newline         \n (first)
186
187 identifier      LMNOP
188 end_command     .    space
189 newline         \n (first)
190
191 identifier      QRSTUV
192 end_command     .
193 comment         /*_end_of_line_comment_*/
194 newline         \n (first)
195
196 identifier      qrstuv
197 end_command     .    space
198 comment         /*_end_of_line_comment_*/
199 newline         \n (first)
200
201 identifier      QrStUv
202 end_command     .
203 comment         /*_end_of_line_comment_*/    space
204 newline         \n (first)
205
206 identifier      wxyz
207 end_command     .
208 comment         /*_unterminated_end_of_line_comment
209 newline         \n (first)
210
211 identifier      WXYZ
212 end_command     .    space
213 comment         /*_unterminated_end_of_line_comment
214 newline         \n (first)
215
216 identifier      WxYz
217 end_command     .
218 comment         /*_unterminated_end_of_line_comment_
219 -newline         \n (first)
220 -
221 end
222 ])
223 PSPP_CHECK_SEGMENT([-i])
224 AT_CLEANUP
225 \f
226 AT_SETUP([reserved words])
227 AT_KEYWORDS([segment])
228 AT_DATA([input], [dnl
229 and or not eq ge gt le lt ne all by to with
230 AND OR NOT EQ GE GT LE LT NE ALL BY TO WITH
231 andx orx notx eqx gex gtx lex ltx nex allx byx tox withx
232 and. with.
233 ])
234 AT_DATA([expout-base], [dnl
235 reserved_word   and    space
236 reserved_word   or    space
237 reserved_word   not    space
238 reserved_word   eq    space
239 reserved_word   ge    space
240 reserved_word   gt    space
241 reserved_word   le    space
242 reserved_word   lt    space
243 reserved_word   ne    space
244 reserved_word   all    space
245 reserved_word   by    space
246 reserved_word   to    space
247 reserved_word   with
248 newline         \n (later)
249
250 reserved_word   AND    space
251 reserved_word   OR    space
252 reserved_word   NOT    space
253 reserved_word   EQ    space
254 reserved_word   GE    space
255 reserved_word   GT    space
256 reserved_word   LE    space
257 reserved_word   LT    space
258 reserved_word   NE    space
259 reserved_word   ALL    space
260 reserved_word   BY    space
261 reserved_word   TO    space
262 reserved_word   WITH
263 newline         \n (later)
264
265 identifier      andx    space
266 identifier      orx    space
267 identifier      notx    space
268 identifier      eqx    space
269 identifier      gex    space
270 identifier      gtx    space
271 identifier      lex    space
272 identifier      ltx    space
273 identifier      nex    space
274 identifier      allx    space
275 identifier      byx    space
276 identifier      tox    space
277 identifier      withx
278 newline         \n (later)
279
280 identifier      and.    space
281 reserved_word   with
282 end_command     .
283 -newline         \n (first)
284 -
285 end
286 ])
287 PSPP_CHECK_SEGMENT([-i])
288 AT_CLEANUP
289 \f
290 AT_SETUP([punctuation])
291 AT_KEYWORDS([segment])
292 AT_DATA([input], [dnl
293 ~ & | = >= > <= < ~= <> ( ) , - + * / [[ ]] **
294 ~&|=>=><=<~=<>(),-+*/[[]]**
295 % : ; ? _ ` { } ~
296 ])
297 AT_DATA([expout-base], [dnl
298 punct           ~    space
299 punct           &    space
300 punct           |    space
301 punct           =    space
302 punct           >=    space
303 punct           >    space
304 punct           <=    space
305 punct           <    space
306 punct           ~=    space
307 punct           <>    space
308 punct           (    space
309 punct           )    space
310 punct           ,    space
311 punct           -    space
312 punct           +    space
313 punct           *    space
314 punct           /    space
315 punct           [[    space
316 punct           ]]    space
317 punct           **
318 newline         \n (later)
319
320 punct           ~
321 punct           &
322 punct           |
323 punct           =
324 punct           >=
325 punct           >
326 punct           <=
327 punct           <
328 punct           ~=
329 punct           <>
330 punct           (
331 punct           )
332 punct           ,
333 punct           -
334 punct           +
335 punct           *
336 punct           /
337 punct           [[
338 punct           ]]
339 punct           **
340 newline         \n (later)
341
342 punct           %    space
343 punct           :    space
344 punct           ;    space
345 punct           ?    space
346 punct           \_    space
347 punct           `    space
348 punct           {    space
349 punct           }    space
350 punct           ~
351 -newline         \n (later)
352 -
353 end
354 ])
355 PSPP_CHECK_SEGMENT([-i])
356 AT_CLEANUP
357 \f
358 AT_SETUP([numbers])
359 AT_KEYWORDS([segment])
360 AT_DATA([input], [dnl
361 0 1 01 001. 1.
362 123. /* comment 1 */ /* comment 2 */
363 .1 0.1 00.1 00.10
364 5e1 6E-1 7e+1 6E+01 6e-03
365 .3E1 .4e-1 .5E+1 .6e+01 .7E-03
366 1.23e1 45.6E-1 78.9e+1 99.9E+01 11.2e-03
367 . 1e e1 1e+ 1e- 1.
368 ])
369 AT_DATA([expout-base], [dnl
370 number          0    space
371 number          1    space
372 number          01    space
373 number          001.    space
374 number          1
375 end_command     .
376 newline         \n (first)
377
378 number          123
379 end_command     .    space
380 comment         /*_comment_1_*/    space
381 comment         /*_comment_2_*/
382 newline         \n (first)
383
384 start_command   .
385 number          1    space
386 number          0.1    space
387 number          00.1    space
388 number          00.10
389 newline         \n (later)
390
391 number          5e1    space
392 number          6E-1    space
393 number          7e+1    space
394 number          6E+01    space
395 number          6e-03
396 newline         \n (later)
397
398 start_command   .
399 number          3E1    space
400 number          .4e-1    space
401 number          .5E+1    space
402 number          .6e+01    space
403 number          .7E-03
404 newline         \n (later)
405
406 number          1.23e1    space
407 number          45.6E-1    space
408 number          78.9e+1    space
409 number          99.9E+01    space
410 number          11.2e-03
411 newline         \n (later)
412
413 start_command   .    space
414 expected_exponent 1e    space
415 identifier      e1    space
416 expected_exponent 1e+    space
417 expected_exponent 1e-    space
418 number          1
419 end_command     .
420 -newline         \n (first)
421 -
422 end
423 ])
424 PSPP_CHECK_SEGMENT([-i])
425 AT_CLEANUP
426 \f
427 AT_SETUP([strings])
428 AT_KEYWORDS([segment])
429 AT_DATA([input], [dnl
430 'x' "y" 'abc'
431 'Don''t' "Can't" 'Won''t'
432 """quoted""" '"quoted"'
433 '' ""
434 'missing end quote
435 "missing double quote
436 x"4142" X'5152'
437 u'fffd' U"041"
438 + new command
439 + /* comment */ 'string continuation'
440 + /* also a punctuator on blank line
441 - 'new command'
442 ])
443 AT_DATA([expout-base], [dnl
444 quoted_string   'x'    space
445 quoted_string   "y"    space
446 quoted_string   'abc'
447 newline         \n (later)
448
449 quoted_string   'Don''t'    space
450 quoted_string   "Can't"    space
451 quoted_string   'Won''t'
452 newline         \n (later)
453
454 quoted_string   """quoted"""    space
455 quoted_string   '"quoted"'
456 newline         \n (later)
457
458 quoted_string   ''    space
459 quoted_string   ""
460 newline         \n (later)
461
462 expected_quote  'missing_end_quote
463 newline         \n (later)
464
465 expected_quote  "missing_double_quote
466 newline         \n (later)
467
468 hex_string      x"4142"    space
469 hex_string      X'5152'
470 newline         \n (later)
471
472 unicode_string  u'fffd'    space
473 unicode_string  U"041"
474 newline         \n (later)
475
476 start_command   +    space
477 identifier      new    space
478 identifier      command
479 newline         \n (later)
480
481 punct           +    space
482 comment         /*_comment_*/    space
483 quoted_string   'string_continuation'
484 newline         \n (later)
485
486 punct           +    space
487 comment         /*_also_a_punctuator_on_blank_line
488 newline         \n (later)
489
490 start_command   -    space
491 quoted_string   'new_command'
492 -newline         \n (later)
493 -
494 end
495 ])
496 PSPP_CHECK_SEGMENT([-i])
497 AT_CLEANUP
498 \f
499 AT_SETUP([@%:@! construct])
500 AT_KEYWORDS([segment])
501 AT_DATA([input], [dnl
502 #! /usr/bin/pspp
503 title my title.
504 #! /usr/bin/pspp
505 ])
506 AT_DATA([expout-base], [dnl
507 shbang          #!_/usr/bin/pspp
508 newline         \n (first)
509
510 identifier      title    space
511 unquoted_string my_title
512 end_command     .
513 newline         \n (first)
514
515 identifier      #
516 macro_id        !    space
517 punct           /
518 identifier      usr
519 punct           /
520 identifier      bin
521 punct           /
522 identifier      pspp
523 -newline         \n (later)
524 -
525 end
526 ])
527 PSPP_CHECK_SEGMENT([-i])
528 AT_CLEANUP
529 \f
530 AT_SETUP([* and COMMENT commands])
531 AT_KEYWORDS([segment])
532 AT_DATA([input], [dnl
533 * Comment commands "don't
534 have to contain valid tokens.
535
536 ** Check ambiguity with ** token.
537 ****************.
538
539 comment keyword works too.
540 COMM also.
541 com is ambiguous with COMPUTE.
542
543    * Comment need not start at left margin.
544
545 * Comment ends with blank line
546
547 next command.
548
549 ])
550 AT_DATA([expout-base], [dnl
551 comment_command *_Comment_commands_"don't
552 newline         \n (COMMENT)
553
554 comment_command have_to_contain_valid_tokens
555 end_command     .
556 newline         \n (first)
557
558 separate_commands
559 newline         \n (first)
560
561 comment_command **_Check_ambiguity_with_**_token
562 end_command     .
563 newline         \n (first)
564
565 comment_command ****************
566 end_command     .
567 newline         \n (first)
568
569 separate_commands
570 newline         \n (first)
571
572 comment_command comment_keyword_works_too
573 end_command     .
574 newline         \n (first)
575
576 comment_command COMM_also
577 end_command     .
578 newline         \n (first)
579
580 identifier      com    space
581 identifier      is    space
582 identifier      ambiguous    space
583 reserved_word   with    space
584 identifier      COMPUTE
585 end_command     .
586 newline         \n (first)
587
588 separate_commands
589 newline         \n (first)
590
591 spaces          ___
592 comment_command *_Comment_need_not_start_at_left_margin
593 end_command     .
594 newline         \n (first)
595
596 separate_commands
597 newline         \n (first)
598
599 comment_command *_Comment_ends_with_blank_line
600 newline         \n (COMMENT)
601
602 separate_commands
603 newline         \n (first)
604
605 identifier      next    space
606 identifier      command
607 end_command     .
608 newline         \n (first)
609
610 -separate_commands
611 -newline         \n (first)
612 -
613 end
614 ])
615 PSPP_CHECK_SEGMENT([-i])
616 AT_CLEANUP
617 \f
618 AT_SETUP([DOCUMENT command])
619 AT_KEYWORDS([segment])
620 AT_DATA([input], [dnl
621 DOCUMENT one line.
622 DOC more
623     than
624         one
625             line.
626 docu
627 first.paragraph
628 isn't parsed as tokens
629
630 second paragraph.
631 ])
632 AT_DATA([expout-base], [dnl
633 start_document
634 document        DOCUMENT_one_line.
635 end_command
636 separate_commands
637 newline         \n (first)
638
639 start_document
640 document        DOC_more
641 newline         \n (DOCUMENT)
642
643 document        ____than
644 newline         \n (DOCUMENT)
645
646 document        ________one
647 newline         \n (DOCUMENT)
648
649 document        ____________line.
650 end_command
651 separate_commands
652 newline         \n (first)
653
654 start_document
655 document        docu
656 newline         \n (DOCUMENT)
657
658 document        first.paragraph
659 newline         \n (DOCUMENT)
660
661 document        isn't_parsed_as_tokens
662 newline         \n (DOCUMENT)
663
664 document
665 newline         \n (DOCUMENT)
666
667 document        second_paragraph.
668 -end_command
669 -separate_commands
670 -newline         \n (first)
671 -
672 end
673 ])
674 PSPP_CHECK_SEGMENT([-i])
675 AT_CLEANUP
676 \f
677 AT_SETUP([TITLE, SUBTITLE, FILE LABEL commands])
678 AT_KEYWORDS([segment])
679 AT_DATA([input], [dnl
680 title/**/'Quoted string title'.
681 tit /*
682 "Quoted string on second line".
683 sub "Quoted string subtitle"
684  .
685
686 TITL /* Not a */ quoted string title.
687 SUBT Not a quoted string /* subtitle
688
689 FIL label isn't quoted.
690 FILE
691   lab 'is quoted'.
692 FILE /*
693 /**/  lab not quoted here either
694
695 ])
696 AT_DATA([expout-base], [dnl
697 identifier      title
698 comment         /**/
699 quoted_string   'Quoted_string_title'
700 end_command     .
701 newline         \n (first)
702
703 identifier      tit    space
704 comment         /*
705 newline         \n (later)
706
707 quoted_string   "Quoted_string_on_second_line"
708 end_command     .
709 newline         \n (first)
710
711 identifier      sub    space
712 quoted_string   "Quoted_string_subtitle"
713 newline         \n (later)
714     space
715 end_command     .
716 newline         \n (first)
717
718 separate_commands
719 newline         \n (first)
720
721 identifier      TITL    space
722 unquoted_string /*_Not_a_*/_quoted_string_title
723 end_command     .
724 newline         \n (first)
725
726 identifier      SUBT    space
727 unquoted_string Not_a_quoted_string_/*_subtitle
728 newline         \n (later)
729
730 separate_commands
731 newline         \n (first)
732
733 identifier      FIL    space
734 identifier      label    space
735 unquoted_string isn't_quoted
736 end_command     .
737 newline         \n (first)
738
739 identifier      FILE
740 newline         \n (later)
741
742 spaces          __
743 identifier      lab    space
744 quoted_string   'is_quoted'
745 end_command     .
746 newline         \n (first)
747
748 identifier      FILE    space
749 comment         /*
750 newline         \n (later)
751
752 comment         /**/
753 spaces          __
754 identifier      lab    space
755 unquoted_string not_quoted_here_either
756 newline         \n (later)
757
758 -separate_commands
759 -newline         \n (first)
760 -
761 end
762 ])
763 PSPP_CHECK_SEGMENT([-i])
764 AT_CLEANUP
765 \f
766 AT_SETUP([BEGIN DATA command])
767 AT_KEYWORDS([segment])
768 AT_DATA([input], [dnl
769 begin data.
770 end data.
771
772 begin data. /*
773 123
774 xxx
775 end data.
776
777 BEG /**/ DAT /*
778 5 6 7 /* x
779
780 end  data
781 end data
782 .
783
784 begin
785  data.
786 data
787 end data.
788
789 begin data "xxx".
790 begin data 123.
791 not data
792 ])
793 AT_DATA([expout-base], [dnl
794 identifier      begin    space
795 identifier      data
796 end_command     .
797 newline         \n (data)
798
799 identifier      end    space
800 identifier      data
801 end_command     .
802 newline         \n (first)
803
804 separate_commands
805 newline         \n (first)
806
807 identifier      begin    space
808 identifier      data
809 end_command     .    space
810 comment         /*
811 newline         \n (data)
812
813 inline_data     123
814 newline         \n (data)
815
816 inline_data     xxx
817 newline         \n (data)
818
819 identifier      end    space
820 identifier      data
821 end_command     .
822 newline         \n (first)
823
824 separate_commands
825 newline         \n (first)
826
827 identifier      BEG    space
828 comment         /**/    space
829 identifier      DAT    space
830 comment         /*
831 newline         \n (data)
832
833 inline_data     5_6_7_/*_x
834 newline         \n (data)
835
836 inline_data
837 newline         \n (data)
838
839 inline_data     end__data
840 newline         \n (data)
841
842 identifier      end    space
843 identifier      data
844 newline         \n (later)
845
846 start_command   .
847 newline         \n (first)
848
849 separate_commands
850 newline         \n (first)
851
852 identifier      begin
853 newline         \n (later)
854     space
855 identifier      data
856 end_command     .
857 newline         \n (data)
858
859 inline_data     data
860 newline         \n (data)
861
862 identifier      end    space
863 identifier      data
864 end_command     .
865 newline         \n (first)
866
867 separate_commands
868 newline         \n (first)
869
870 identifier      begin    space
871 identifier      data    space
872 quoted_string   "xxx"
873 end_command     .
874 newline         \n (first)
875
876 identifier      begin    space
877 identifier      data    space
878 number          123
879 end_command     .
880 newline         \n (first)
881
882 reserved_word   not    space
883 identifier      data
884 -newline         \n (later)
885 -
886 end
887 ])
888 PSPP_CHECK_SEGMENT([-i])
889 AT_CLEANUP
890 \f
891 AT_SETUP([DO REPEAT command])
892 AT_KEYWORDS([segment])
893 AT_DATA([input], [dnl
894 do repeat x=a b c
895           y=d e f.
896   do repeat a=1 thru 5.
897 another command.
898 second command
899 + third command.
900 end /* x */ /* y */ repeat print.
901 end
902  repeat.
903 do
904   repeat #a=1.
905   inner command.
906 end repeat.
907 ])
908 AT_DATA([expout-base], [dnl
909 identifier      do    space
910 identifier      repeat    space
911 identifier      x
912 punct           =
913 identifier      a    space
914 identifier      b    space
915 identifier      c
916 newline         \n (later)
917
918 spaces          __________
919 identifier      y
920 punct           =
921 identifier      d    space
922 identifier      e    space
923 identifier      f
924 end_command     .
925 newline         \n (DO REPEAT)
926
927 do_repeat_command __do_repeat_a=1_thru_5.
928 newline         \n (DO REPEAT)
929
930 do_repeat_command another_command.
931 newline         \n (DO REPEAT)
932
933 do_repeat_command second_command
934 newline         \n (DO REPEAT)
935
936 do_repeat_command +_third_command.
937 newline         \n (DO REPEAT)
938
939 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print.
940 newline         \n (DO REPEAT)
941
942 identifier      end
943 newline         \n (later)
944     space
945 identifier      repeat
946 end_command     .
947 newline         \n (first)
948
949 identifier      do
950 newline         \n (later)
951
952 spaces          __
953 identifier      repeat    space
954 identifier      #a
955 punct           =
956 number          1
957 end_command     .
958 newline         \n (DO REPEAT)
959
960 do_repeat_command __inner_command.
961 newline         \n (DO REPEAT)
962
963 identifier      end    space
964 identifier      repeat
965 end_command     .
966 -newline         \n (first)
967 -
968 end
969 ])
970 PSPP_CHECK_SEGMENT([-i])
971 AT_CLEANUP
972 \f
973 AT_SETUP([DO REPEAT command in batch mode])
974 AT_KEYWORDS([segment])
975 AT_DATA([input], [dnl
976 do repeat x=a b c
977           y=d e f
978 do repeat a=1 thru 5
979 another command
980 second command
981 + third command
982 end /* x */ /* y */ repeat print
983 end
984  repeat
985 do
986   repeat #a=1
987
988   inner command
989 end repeat
990 ])
991 AT_DATA([expout-base], [dnl
992 identifier      do    space
993 identifier      repeat    space
994 identifier      x
995 punct           =
996 identifier      a    space
997 identifier      b    space
998 identifier      c
999 newline         \n (later)
1000
1001 spaces          __________
1002 identifier      y
1003 punct           =
1004 identifier      d    space
1005 identifier      e    space
1006 identifier      f
1007 newline         \n (later)
1008
1009 start_command
1010 do_repeat_command do_repeat_a=1_thru_5
1011 newline         \n (DO REPEAT)
1012
1013 do_repeat_command another_command
1014 newline         \n (DO REPEAT)
1015
1016 do_repeat_command second_command
1017 newline         \n (DO REPEAT)
1018
1019 do_repeat_command +_third_command
1020 newline         \n (DO REPEAT)
1021
1022 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print
1023 newline         \n (DO REPEAT)
1024
1025 identifier      end
1026 newline         \n (later)
1027     space
1028 identifier      repeat
1029 newline         \n (later)
1030
1031 start_command
1032 identifier      do
1033 newline         \n (later)
1034
1035 spaces          __
1036 identifier      repeat    space
1037 identifier      #a
1038 punct           =
1039 number          1
1040 newline         \n (later)
1041
1042 separate_commands
1043 newline         \n (DO REPEAT)
1044
1045 do_repeat_command __inner_command
1046 newline         \n (DO REPEAT)
1047
1048 identifier      end    space
1049 identifier      repeat
1050 -newline         \n (later)
1051 -
1052 end
1053 ])
1054 PSPP_CHECK_SEGMENT([-b])
1055 AT_CLEANUP
1056 \f
1057 AT_SETUP([DEFINE command - simple])
1058 AT_KEYWORDS([segment])
1059 AT_DATA([input], [dnl
1060 define !macro1()
1061 var1 var2 var3
1062 !enddefine.
1063 ])
1064 AT_DATA([expout-base], [dnl
1065 identifier      define    space
1066 macro_id        !macro1
1067 punct           (
1068 punct           )
1069 spaces
1070 newline         \n (DEFINE)
1071
1072 macro_body      var1_var2_var3
1073 newline         \n (DEFINE)
1074
1075 macro_id        !enddefine
1076 end_command     .
1077 -newline         \n (first)
1078 -
1079 end
1080 ])
1081 PSPP_CHECK_SEGMENT([-i])
1082 AT_CLEANUP
1083 \f
1084 AT_SETUP([DEFINE command - no newline after parentheses])
1085 AT_KEYWORDS([segment])
1086 AT_DATA([input], [dnl
1087 define !macro1() var1 var2 var3
1088 !enddefine.
1089 ])
1090 AT_DATA([expout-base], [dnl
1091 identifier      define    space
1092 macro_id        !macro1
1093 punct           (
1094 punct           )
1095 macro_body      _var1_var2_var3
1096 newline         \n (DEFINE)
1097
1098 macro_id        !enddefine
1099 end_command     .
1100 -newline         \n (first)
1101 -
1102 end
1103 ])
1104 PSPP_CHECK_SEGMENT([-i])
1105 AT_CLEANUP
1106 \f
1107 AT_SETUP([DEFINE command - no newline before !ENDDEFINE])
1108 AT_KEYWORDS([segment ENDDEFINE])
1109 AT_DATA([input], [dnl
1110 define !macro1()
1111 var1 var2 var3!enddefine.
1112 ])
1113 AT_DATA([expout-base], [dnl
1114 identifier      define    space
1115 macro_id        !macro1
1116 punct           (
1117 punct           )
1118 spaces
1119 newline         \n (DEFINE)
1120
1121 macro_body      var1_var2_var3
1122 macro_id        !enddefine
1123 end_command     .
1124 -newline         \n (first)
1125 -
1126 end
1127 ])
1128 PSPP_CHECK_SEGMENT([-i])
1129 AT_CLEANUP
1130 \f
1131 AT_SETUP([DEFINE command - all on one line])
1132 AT_KEYWORDS([segment])
1133 AT_DATA([input], [dnl
1134 define !macro1()var1 var2 var3!enddefine.
1135 ])
1136 AT_DATA([expout-base], [dnl
1137 identifier      define    space
1138 macro_id        !macro1
1139 punct           (
1140 punct           )
1141 macro_body      var1_var2_var3
1142 macro_id        !enddefine
1143 end_command     .
1144 -newline         \n (first)
1145 -
1146 end
1147 ])
1148 PSPP_CHECK_SEGMENT([-i])
1149 AT_CLEANUP
1150 \f
1151 AT_SETUP([DEFINE command - empty])
1152 AT_KEYWORDS([segment])
1153 AT_DATA([input], [dnl
1154 define !macro1()
1155 !enddefine.
1156 ])
1157 AT_DATA([expout-base], [dnl
1158 identifier      define    space
1159 macro_id        !macro1
1160 punct           (
1161 punct           )
1162 spaces
1163 newline         \n (DEFINE)
1164
1165 macro_id        !enddefine
1166 end_command     .
1167 -newline         \n (first)
1168 -
1169 end
1170 ])
1171 PSPP_CHECK_SEGMENT([-i])
1172 AT_CLEANUP
1173 \f
1174 AT_SETUP([DEFINE command - blank lines])
1175 AT_KEYWORDS([segment])
1176 AT_DATA([input], [dnl
1177 define !macro1()
1178
1179
1180 !enddefine.
1181 ])
1182 AT_DATA([expout-base], [dnl
1183 identifier      define    space
1184 macro_id        !macro1
1185 punct           (
1186 punct           )
1187 spaces
1188 newline         \n (DEFINE)
1189
1190 macro_body
1191 newline         \n (DEFINE)
1192
1193 macro_body
1194 newline         \n (DEFINE)
1195
1196 macro_id        !enddefine
1197 end_command     .
1198 -newline         \n (first)
1199 -
1200 end
1201 ])
1202 PSPP_CHECK_SEGMENT([-i])
1203 AT_CLEANUP
1204 \f
1205 AT_SETUP([DEFINE command - arguments])
1206 AT_KEYWORDS([segment])
1207 AT_DATA([input], [dnl
1208 define !macro1(a(), b(), c())
1209 !enddefine.
1210 ])
1211 AT_DATA([expout-base], [dnl
1212 identifier      define    space
1213 macro_id        !macro1
1214 punct           (
1215 identifier      a
1216 punct           (
1217 punct           )
1218 punct           ,    space
1219 identifier      b
1220 punct           (
1221 punct           )
1222 punct           ,    space
1223 identifier      c
1224 punct           (
1225 punct           )
1226 punct           )
1227 spaces
1228 newline         \n (DEFINE)
1229
1230 macro_id        !enddefine
1231 end_command     .
1232 -newline         \n (first)
1233 -
1234 end
1235 ])
1236 PSPP_CHECK_SEGMENT([-i])
1237 AT_CLEANUP
1238 \f
1239 AT_SETUP([DEFINE command - multiline arguments])
1240 AT_KEYWORDS([segment])
1241 AT_DATA([input], [dnl
1242 define !macro1(
1243   a(), b(
1244   ),
1245   c()
1246 )
1247 !enddefine.
1248 ])
1249 AT_DATA([expout-base], [dnl
1250 identifier      define    space
1251 macro_id        !macro1
1252 punct           (
1253 newline         \n (later)
1254
1255 spaces          __
1256 identifier      a
1257 punct           (
1258 punct           )
1259 punct           ,    space
1260 identifier      b
1261 punct           (
1262 newline         \n (later)
1263
1264 spaces          __
1265 punct           )
1266 punct           ,
1267 newline         \n (later)
1268
1269 spaces          __
1270 identifier      c
1271 punct           (
1272 punct           )
1273 newline         \n (later)
1274
1275 punct           )
1276 spaces
1277 newline         \n (DEFINE)
1278
1279 macro_id        !enddefine
1280 end_command     .
1281 -newline         \n (first)
1282 -
1283 end
1284 ])
1285 PSPP_CHECK_SEGMENT([-i])
1286 AT_CLEANUP
1287 \f
1288 AT_SETUP([DEFINE command - arguments start on second line])
1289 AT_KEYWORDS([segment])
1290 AT_DATA([input], [dnl
1291 define !macro1
1292 (x,y,z
1293 )
1294 content 1
1295 content 2
1296 !enddefine.
1297 ])
1298 AT_DATA([expout-base], [dnl
1299 identifier      define    space
1300 macro_id        !macro1
1301 newline         \n (later)
1302
1303 punct           (
1304 identifier      x
1305 punct           ,
1306 identifier      y
1307 punct           ,
1308 identifier      z
1309 newline         \n (later)
1310
1311 punct           )
1312 spaces
1313 newline         \n (DEFINE)
1314
1315 macro_body      content_1
1316 newline         \n (DEFINE)
1317
1318 macro_body      content_2
1319 newline         \n (DEFINE)
1320
1321 macro_id        !enddefine
1322 end_command     .
1323 -newline         \n (first)
1324 -
1325 end
1326 ])
1327 PSPP_CHECK_SEGMENT([-i])
1328 AT_CLEANUP
1329 \f
1330 AT_SETUP([DEFINE command - early end of command 1])
1331 AT_KEYWORDS([segment])
1332 AT_DATA([input], [dnl
1333 define !macro1.
1334 data list /x 1.
1335 ])
1336 AT_DATA([expout-base], [dnl
1337 identifier      define    space
1338 macro_id        !macro1
1339 end_command     .
1340 newline         \n (first)
1341
1342 identifier      data    space
1343 identifier      list    space
1344 punct           /
1345 identifier      x    space
1346 number          1
1347 end_command     .
1348 -newline         \n (first)
1349 -
1350 end
1351 ])
1352 PSPP_CHECK_SEGMENT([-i])
1353 AT_CLEANUP
1354 \f
1355 AT_SETUP([DEFINE command - early end of command 2])
1356 AT_KEYWORDS([segment])
1357 AT_DATA([input], [dnl
1358 define !macro1
1359 x.
1360 data list /x 1.
1361 ])
1362 AT_DATA([expout-base], [dnl
1363 identifier      define    space
1364 macro_id        !macro1
1365 newline         \n (later)
1366
1367 identifier      x
1368 end_command     .
1369 newline         \n (first)
1370
1371 identifier      data    space
1372 identifier      list    space
1373 punct           /
1374 identifier      x    space
1375 number          1
1376 end_command     .
1377 -newline         \n (first)
1378 -
1379 end
1380 ])
1381 PSPP_CHECK_SEGMENT([-i])
1382 AT_CLEANUP
1383 \f
1384 AT_SETUP([DEFINE command - early end of command 3])
1385 AT_KEYWORDS([segment])
1386 AT_DATA([input], [dnl
1387 define !macro1(.
1388 x.
1389 data list /x 1.
1390 ])
1391 AT_DATA([expout-base], [dnl
1392 identifier      define    space
1393 macro_id        !macro1
1394 punct           (
1395 end_command     .
1396 newline         \n (first)
1397
1398 identifier      x
1399 end_command     .
1400 newline         \n (first)
1401
1402 identifier      data    space
1403 identifier      list    space
1404 punct           /
1405 identifier      x    space
1406 number          1
1407 end_command     .
1408 -newline         \n (first)
1409 -
1410 end
1411 ])
1412 PSPP_CHECK_SEGMENT([-i])
1413 AT_CLEANUP
1414 \f
1415 AT_SETUP([DEFINE command - early end of command 4])
1416 AT_KEYWORDS([segment])
1417 AT_DATA([input], [dnl
1418 dnl Notice the command terminator at the end of the DEFINE command,
1419 dnl which should not be there and ends it early.
1420 define !macro1.
1421 data list /x 1.
1422 ])
1423 AT_DATA([expout-base], [dnl
1424 identifier      define    space
1425 macro_id        !macro1
1426 end_command     .
1427 newline         \n (first)
1428
1429 identifier      data    space
1430 identifier      list    space
1431 punct           /
1432 identifier      x    space
1433 number          1
1434 end_command     .
1435 -newline         \n (first)
1436 -
1437 end
1438 ])
1439 PSPP_CHECK_SEGMENT([-i])
1440 AT_CLEANUP
1441 \f
1442 AT_SETUP([DEFINE command - missing !ENDDEFINE])
1443 AT_KEYWORDS([segment])
1444 AT_DATA([input], [dnl
1445 define !macro1()
1446 content line 1
1447 content line 2
1448 ])
1449 AT_DATA([expout-base], [dnl
1450 identifier      define    space
1451 macro_id        !macro1
1452 punct           (
1453 punct           )
1454 spaces
1455 newline         \n (DEFINE)
1456
1457 macro_body      content_line_1
1458 newline         \n (DEFINE)
1459
1460 macro_body      content_line_2
1461 -newline         \n (DEFINE)
1462 -
1463 end
1464 ])
1465 PSPP_CHECK_SEGMENT([-i])
1466 AT_CLEANUP
1467 \f
1468 AT_SETUP([batch mode])
1469 AT_KEYWORDS([segment])
1470 AT_DATA([input], [dnl
1471 first command
1472      another line of first command
1473 +  second command
1474 third command
1475
1476 fourth command.
1477    fifth command.
1478 ])
1479 AT_DATA([expout-base], [dnl
1480 identifier      first    space
1481 identifier      command
1482 newline         \n (later)
1483
1484 spaces          _____
1485 identifier      another    space
1486 identifier      line    space
1487 identifier      of    space
1488 identifier      first    space
1489 identifier      command
1490 newline         \n (later)
1491
1492 start_command   +
1493 spaces          __
1494 identifier      second    space
1495 identifier      command
1496 newline         \n (later)
1497
1498 start_command
1499 identifier      third    space
1500 identifier      command
1501 newline         \n (later)
1502
1503 separate_commands
1504 newline         \n (first)
1505
1506 identifier      fourth    space
1507 identifier      command
1508 end_command     .
1509 newline         \n (first)
1510
1511 spaces          ___
1512 identifier      fifth    space
1513 identifier      command
1514 end_command     .
1515 -newline         \n (first)
1516 -
1517 end
1518 ])
1519 PSPP_CHECK_SEGMENT([-b])
1520 AT_CLEANUP
1521 \f
1522 AT_SETUP([auto mode])
1523 AT_KEYWORDS([segment])
1524 AT_DATA([input], [dnl
1525 command
1526      another line of command
1527 2sls
1528 +  another command
1529 another line of second command
1530 data list /x 1
1531 aggregate.
1532 print eject.
1533 twostep cluster
1534
1535
1536 fourth command.
1537    fifth command.
1538 ])
1539 AT_DATA([expout-base], [dnl
1540 identifier      command
1541 newline         \n (later)
1542
1543 spaces          _____
1544 identifier      another    space
1545 identifier      line    space
1546 identifier      of    space
1547 identifier      command
1548 newline         \n (later)
1549
1550 start_command
1551 number          2
1552 identifier      sls
1553 newline         \n (later)
1554
1555 start_command   +
1556 spaces          __
1557 identifier      another    space
1558 identifier      command
1559 newline         \n (later)
1560
1561 identifier      another    space
1562 identifier      line    space
1563 identifier      of    space
1564 identifier      second    space
1565 identifier      command
1566 newline         \n (later)
1567
1568 start_command
1569 identifier      data    space
1570 identifier      list    space
1571 punct           /
1572 identifier      x    space
1573 number          1
1574 newline         \n (later)
1575
1576 start_command
1577 identifier      aggregate
1578 end_command     .
1579 newline         \n (first)
1580
1581 identifier      print    space
1582 identifier      eject
1583 end_command     .
1584 newline         \n (first)
1585
1586 identifier      twostep    space
1587 identifier      cluster
1588 newline         \n (later)
1589
1590 separate_commands
1591 newline         \n (first)
1592
1593 separate_commands
1594 newline         \n (first)
1595
1596 identifier      fourth    space
1597 identifier      command
1598 end_command     .
1599 newline         \n (first)
1600
1601 spaces          ___
1602 identifier      fifth    space
1603 identifier      command
1604 end_command     .
1605 -newline         \n (first)
1606 -
1607 end
1608 ])
1609 PSPP_CHECK_SEGMENT([-a])
1610 AT_CLEANUP