segment: Ignore !ENDDEFINE in /*comments*/ and "strings".
[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 identifier      my    space
512 identifier      title
513 end_command     .
514 newline         \n (first)
515
516 identifier      #
517 macro_id        !    space
518 punct           /
519 identifier      usr
520 punct           /
521 identifier      bin
522 punct           /
523 identifier      pspp
524 -newline         \n (later)
525 -
526 end
527 ])
528 PSPP_CHECK_SEGMENT([-i])
529 AT_CLEANUP
530 \f
531 AT_SETUP([* and COMMENT commands])
532 AT_KEYWORDS([segment])
533 AT_DATA([input], [dnl
534 * Comment commands "don't
535 have to contain valid tokens.
536
537 ** Check ambiguity with ** token.
538 ****************.
539
540 comment keyword works too.
541 COMM also.
542 com is ambiguous with COMPUTE.
543
544    * Comment need not start at left margin.
545
546 * Comment ends with blank line
547
548 next command.
549
550 ])
551 AT_DATA([expout-base], [dnl
552 comment_command *_Comment_commands_"don't
553 newline         \n (COMMENT)
554
555 comment_command have_to_contain_valid_tokens
556 end_command     .
557 newline         \n (first)
558
559 separate_commands
560 newline         \n (first)
561
562 comment_command **_Check_ambiguity_with_**_token
563 end_command     .
564 newline         \n (first)
565
566 comment_command ****************
567 end_command     .
568 newline         \n (first)
569
570 separate_commands
571 newline         \n (first)
572
573 comment_command comment_keyword_works_too
574 end_command     .
575 newline         \n (first)
576
577 comment_command COMM_also
578 end_command     .
579 newline         \n (first)
580
581 identifier      com    space
582 identifier      is    space
583 identifier      ambiguous    space
584 reserved_word   with    space
585 identifier      COMPUTE
586 end_command     .
587 newline         \n (first)
588
589 separate_commands
590 newline         \n (first)
591
592 spaces          ___
593 comment_command *_Comment_need_not_start_at_left_margin
594 end_command     .
595 newline         \n (first)
596
597 separate_commands
598 newline         \n (first)
599
600 comment_command *_Comment_ends_with_blank_line
601 newline         \n (COMMENT)
602
603 separate_commands
604 newline         \n (first)
605
606 identifier      next    space
607 identifier      command
608 end_command     .
609 newline         \n (first)
610
611 -separate_commands
612 -newline         \n (first)
613 -
614 end
615 ])
616 PSPP_CHECK_SEGMENT([-i])
617 AT_CLEANUP
618 \f
619 AT_SETUP([DOCUMENT command])
620 AT_KEYWORDS([segment])
621 AT_DATA([input], [dnl
622 DOCUMENT one line.
623 DOC more
624     than
625         one
626             line.
627 docu
628 first.paragraph
629 isn't parsed as tokens
630
631 second paragraph.
632 ])
633 AT_DATA([expout-base], [dnl
634 start_document
635 document        DOCUMENT_one_line.
636 end_command
637 separate_commands
638 newline         \n (first)
639
640 start_document
641 document        DOC_more
642 newline         \n (DOCUMENT)
643
644 document        ____than
645 newline         \n (DOCUMENT)
646
647 document        ________one
648 newline         \n (DOCUMENT)
649
650 document        ____________line.
651 end_command
652 separate_commands
653 newline         \n (first)
654
655 start_document
656 document        docu
657 newline         \n (DOCUMENT)
658
659 document        first.paragraph
660 newline         \n (DOCUMENT)
661
662 document        isn't_parsed_as_tokens
663 newline         \n (DOCUMENT)
664
665 document
666 newline         \n (DOCUMENT)
667
668 document        second_paragraph.
669 -end_command
670 -separate_commands
671 -newline         \n (first)
672 -
673 end
674 ])
675 PSPP_CHECK_SEGMENT([-i])
676 AT_CLEANUP
677 \f
678 AT_SETUP([FILE LABEL command])
679 AT_KEYWORDS([segment])
680 AT_DATA([input], [dnl
681 FIL label isn't quoted.
682 FILE
683   lab 'is quoted'.
684 FILE /*
685 /**/  lab not quoted here either
686
687 ])
688 AT_DATA([expout-base], [dnl
689 identifier      FIL    space
690 identifier      label    space
691 unquoted_string isn't_quoted
692 end_command     .
693 newline         \n (first)
694
695 identifier      FILE
696 newline         \n (later)
697
698 spaces          __
699 identifier      lab    space
700 quoted_string   'is_quoted'
701 end_command     .
702 newline         \n (first)
703
704 identifier      FILE    space
705 comment         /*
706 newline         \n (later)
707
708 comment         /**/
709 spaces          __
710 identifier      lab    space
711 unquoted_string not_quoted_here_either
712 newline         \n (later)
713
714 -separate_commands
715 -newline         \n (first)
716 -
717 end
718 ])
719 PSPP_CHECK_SEGMENT([-i])
720 AT_CLEANUP
721 \f
722 AT_SETUP([BEGIN DATA command])
723 AT_KEYWORDS([segment])
724 AT_DATA([input], [dnl
725 begin data.
726 end data.
727
728 begin data. /*
729 123
730 xxx
731 end data.
732
733 BEG /**/ DAT /*
734 5 6 7 /* x
735
736 end  data
737 end data
738 .
739
740 begin
741  data.
742 data
743 end data.
744
745 begin data "xxx".
746 begin data 123.
747 not data
748 ])
749 AT_DATA([expout-base], [dnl
750 identifier      begin    space
751 identifier      data
752 end_command     .
753 newline         \n (data)
754
755 identifier      end    space
756 identifier      data
757 end_command     .
758 newline         \n (first)
759
760 separate_commands
761 newline         \n (first)
762
763 identifier      begin    space
764 identifier      data
765 end_command     .    space
766 comment         /*
767 newline         \n (data)
768
769 inline_data     123
770 newline         \n (data)
771
772 inline_data     xxx
773 newline         \n (data)
774
775 identifier      end    space
776 identifier      data
777 end_command     .
778 newline         \n (first)
779
780 separate_commands
781 newline         \n (first)
782
783 identifier      BEG    space
784 comment         /**/    space
785 identifier      DAT    space
786 comment         /*
787 newline         \n (data)
788
789 inline_data     5_6_7_/*_x
790 newline         \n (data)
791
792 inline_data
793 newline         \n (data)
794
795 inline_data     end__data
796 newline         \n (data)
797
798 identifier      end    space
799 identifier      data
800 newline         \n (later)
801
802 start_command   .
803 newline         \n (first)
804
805 separate_commands
806 newline         \n (first)
807
808 identifier      begin
809 newline         \n (later)
810     space
811 identifier      data
812 end_command     .
813 newline         \n (data)
814
815 inline_data     data
816 newline         \n (data)
817
818 identifier      end    space
819 identifier      data
820 end_command     .
821 newline         \n (first)
822
823 separate_commands
824 newline         \n (first)
825
826 identifier      begin    space
827 identifier      data    space
828 quoted_string   "xxx"
829 end_command     .
830 newline         \n (first)
831
832 identifier      begin    space
833 identifier      data    space
834 number          123
835 end_command     .
836 newline         \n (first)
837
838 reserved_word   not    space
839 identifier      data
840 -newline         \n (later)
841 -
842 end
843 ])
844 PSPP_CHECK_SEGMENT([-i])
845 AT_CLEANUP
846 \f
847 AT_SETUP([DO REPEAT command])
848 AT_KEYWORDS([segment])
849 AT_DATA([input], [dnl
850 do repeat x=a b c
851           y=d e f.
852   do repeat a=1 thru 5.
853 another command.
854 second command
855 + third command.
856 end /* x */ /* y */ repeat print.
857 end
858  repeat.
859 do
860   repeat #a=1.
861   inner command.
862 end repeat.
863 ])
864 AT_DATA([expout-base], [dnl
865 identifier      do    space
866 identifier      repeat    space
867 identifier      x
868 punct           =
869 identifier      a    space
870 identifier      b    space
871 identifier      c
872 newline         \n (later)
873
874 spaces          __________
875 identifier      y
876 punct           =
877 identifier      d    space
878 identifier      e    space
879 identifier      f
880 end_command     .
881 newline         \n (DO REPEAT)
882
883 do_repeat_command __do_repeat_a=1_thru_5.
884 newline         \n (DO REPEAT)
885
886 do_repeat_command another_command.
887 newline         \n (DO REPEAT)
888
889 do_repeat_command second_command
890 newline         \n (DO REPEAT)
891
892 do_repeat_command +_third_command.
893 newline         \n (DO REPEAT)
894
895 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print.
896 newline         \n (DO REPEAT)
897
898 identifier      end
899 newline         \n (later)
900     space
901 identifier      repeat
902 end_command     .
903 newline         \n (first)
904
905 identifier      do
906 newline         \n (later)
907
908 spaces          __
909 identifier      repeat    space
910 identifier      #a
911 punct           =
912 number          1
913 end_command     .
914 newline         \n (DO REPEAT)
915
916 do_repeat_command __inner_command.
917 newline         \n (DO REPEAT)
918
919 identifier      end    space
920 identifier      repeat
921 end_command     .
922 -newline         \n (first)
923 -
924 end
925 ])
926 PSPP_CHECK_SEGMENT([-i])
927 AT_CLEANUP
928 \f
929 AT_SETUP([DO REPEAT command in batch mode])
930 AT_KEYWORDS([segment])
931 AT_DATA([input], [dnl
932 do repeat x=a b c
933           y=d e f
934 do repeat a=1 thru 5
935 another command
936 second command
937 + third command
938 end /* x */ /* y */ repeat print
939 end
940  repeat
941 do
942   repeat #a=1
943
944   inner command
945 end repeat
946 ])
947 AT_DATA([expout-base], [dnl
948 identifier      do    space
949 identifier      repeat    space
950 identifier      x
951 punct           =
952 identifier      a    space
953 identifier      b    space
954 identifier      c
955 newline         \n (later)
956
957 spaces          __________
958 identifier      y
959 punct           =
960 identifier      d    space
961 identifier      e    space
962 identifier      f
963 newline         \n (later)
964
965 start_command
966 do_repeat_command do_repeat_a=1_thru_5
967 newline         \n (DO REPEAT)
968
969 do_repeat_command another_command
970 newline         \n (DO REPEAT)
971
972 do_repeat_command second_command
973 newline         \n (DO REPEAT)
974
975 do_repeat_command +_third_command
976 newline         \n (DO REPEAT)
977
978 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print
979 newline         \n (DO REPEAT)
980
981 identifier      end
982 newline         \n (later)
983     space
984 identifier      repeat
985 newline         \n (later)
986
987 start_command
988 identifier      do
989 newline         \n (later)
990
991 spaces          __
992 identifier      repeat    space
993 identifier      #a
994 punct           =
995 number          1
996 newline         \n (later)
997
998 separate_commands
999 newline         \n (DO REPEAT)
1000
1001 do_repeat_command __inner_command
1002 newline         \n (DO REPEAT)
1003
1004 identifier      end    space
1005 identifier      repeat
1006 -newline         \n (later)
1007 -
1008 end
1009 ])
1010 PSPP_CHECK_SEGMENT([-b])
1011 AT_CLEANUP
1012 \f
1013 AT_SETUP([DEFINE command - simple])
1014 AT_KEYWORDS([segment])
1015 AT_DATA([input], [dnl
1016 define !macro1()
1017 var1 var2 var3 "!enddefine"
1018 !enddefine.
1019 ])
1020 AT_DATA([expout-base], [dnl
1021 identifier      define    space
1022 macro_id        !macro1
1023 punct           (
1024 punct           )
1025 spaces
1026 newline         \n (DEFINE)
1027
1028 macro_body      var1_var2_var3_"!enddefine"
1029 newline         \n (DEFINE)
1030
1031 macro_id        !enddefine
1032 end_command     .
1033 -newline         \n (first)
1034 -
1035 end
1036 ])
1037 PSPP_CHECK_SEGMENT([-i])
1038 AT_CLEANUP
1039 \f
1040 AT_SETUP([DEFINE command - no newline after parentheses])
1041 AT_KEYWORDS([segment])
1042 AT_DATA([input], [dnl
1043 define !macro1() var1 var2 var3 /* !enddefine
1044 !enddefine.
1045 ])
1046 AT_DATA([expout-base], [dnl
1047 identifier      define    space
1048 macro_id        !macro1
1049 punct           (
1050 punct           )
1051 macro_body      _var1_var2_var3_/*_!enddefine
1052 newline         \n (DEFINE)
1053
1054 macro_id        !enddefine
1055 end_command     .
1056 -newline         \n (first)
1057 -
1058 end
1059 ])
1060 PSPP_CHECK_SEGMENT([-i])
1061 AT_CLEANUP
1062 \f
1063 AT_SETUP([DEFINE command - no newline before !ENDDEFINE])
1064 AT_KEYWORDS([segment ENDDEFINE])
1065 AT_DATA([input], [dnl
1066 define !macro1()
1067 var1 var2 var3!enddefine.
1068 ])
1069 AT_DATA([expout-base], [dnl
1070 identifier      define    space
1071 macro_id        !macro1
1072 punct           (
1073 punct           )
1074 spaces
1075 newline         \n (DEFINE)
1076
1077 macro_body      var1_var2_var3
1078 macro_id        !enddefine
1079 end_command     .
1080 -newline         \n (first)
1081 -
1082 end
1083 ])
1084 PSPP_CHECK_SEGMENT([-i])
1085 AT_CLEANUP
1086 \f
1087 AT_SETUP([DEFINE command - all on one line])
1088 AT_KEYWORDS([segment])
1089 AT_DATA([input], [dnl
1090 define !macro1()var1 var2 var3!enddefine.
1091 ])
1092 AT_DATA([expout-base], [dnl
1093 identifier      define    space
1094 macro_id        !macro1
1095 punct           (
1096 punct           )
1097 macro_body      var1_var2_var3
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 - empty])
1108 AT_KEYWORDS([segment])
1109 AT_DATA([input], [dnl
1110 define !macro1()
1111 !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_id        !enddefine
1122 end_command     .
1123 -newline         \n (first)
1124 -
1125 end
1126 ])
1127 PSPP_CHECK_SEGMENT([-i])
1128 AT_CLEANUP
1129 \f
1130 AT_SETUP([DEFINE command - blank lines])
1131 AT_KEYWORDS([segment])
1132 AT_DATA([input], [dnl
1133 define !macro1()
1134
1135
1136 !enddefine.
1137 ])
1138 AT_DATA([expout-base], [dnl
1139 identifier      define    space
1140 macro_id        !macro1
1141 punct           (
1142 punct           )
1143 spaces
1144 newline         \n (DEFINE)
1145
1146 macro_body
1147 newline         \n (DEFINE)
1148
1149 macro_body
1150 newline         \n (DEFINE)
1151
1152 macro_id        !enddefine
1153 end_command     .
1154 -newline         \n (first)
1155 -
1156 end
1157 ])
1158 PSPP_CHECK_SEGMENT([-i])
1159 AT_CLEANUP
1160 \f
1161 AT_SETUP([DEFINE command - arguments])
1162 AT_KEYWORDS([segment])
1163 AT_DATA([input], [dnl
1164 define !macro1(a(), b(), c())
1165 !enddefine.
1166 ])
1167 AT_DATA([expout-base], [dnl
1168 identifier      define    space
1169 macro_id        !macro1
1170 punct           (
1171 identifier      a
1172 punct           (
1173 punct           )
1174 punct           ,    space
1175 identifier      b
1176 punct           (
1177 punct           )
1178 punct           ,    space
1179 identifier      c
1180 punct           (
1181 punct           )
1182 punct           )
1183 spaces
1184 newline         \n (DEFINE)
1185
1186 macro_id        !enddefine
1187 end_command     .
1188 -newline         \n (first)
1189 -
1190 end
1191 ])
1192 PSPP_CHECK_SEGMENT([-i])
1193 AT_CLEANUP
1194 \f
1195 AT_SETUP([DEFINE command - multiline arguments])
1196 AT_KEYWORDS([segment])
1197 AT_DATA([input], [dnl
1198 define !macro1(
1199   a(), b(
1200   ),
1201   c()
1202 )
1203 !enddefine.
1204 ])
1205 AT_DATA([expout-base], [dnl
1206 identifier      define    space
1207 macro_id        !macro1
1208 punct           (
1209 newline         \n (later)
1210
1211 spaces          __
1212 identifier      a
1213 punct           (
1214 punct           )
1215 punct           ,    space
1216 identifier      b
1217 punct           (
1218 newline         \n (later)
1219
1220 spaces          __
1221 punct           )
1222 punct           ,
1223 newline         \n (later)
1224
1225 spaces          __
1226 identifier      c
1227 punct           (
1228 punct           )
1229 newline         \n (later)
1230
1231 punct           )
1232 spaces
1233 newline         \n (DEFINE)
1234
1235 macro_id        !enddefine
1236 end_command     .
1237 -newline         \n (first)
1238 -
1239 end
1240 ])
1241 PSPP_CHECK_SEGMENT([-i])
1242 AT_CLEANUP
1243 \f
1244 AT_SETUP([DEFINE command - arguments start on second line])
1245 AT_KEYWORDS([segment])
1246 AT_DATA([input], [dnl
1247 define !macro1
1248 (x,y,z
1249 )
1250 content 1
1251 content 2
1252 !enddefine.
1253 ])
1254 AT_DATA([expout-base], [dnl
1255 identifier      define    space
1256 macro_id        !macro1
1257 newline         \n (later)
1258
1259 punct           (
1260 identifier      x
1261 punct           ,
1262 identifier      y
1263 punct           ,
1264 identifier      z
1265 newline         \n (later)
1266
1267 punct           )
1268 spaces
1269 newline         \n (DEFINE)
1270
1271 macro_body      content_1
1272 newline         \n (DEFINE)
1273
1274 macro_body      content_2
1275 newline         \n (DEFINE)
1276
1277 macro_id        !enddefine
1278 end_command     .
1279 -newline         \n (first)
1280 -
1281 end
1282 ])
1283 PSPP_CHECK_SEGMENT([-i])
1284 AT_CLEANUP
1285 \f
1286 AT_SETUP([DEFINE command - early end of command 1])
1287 AT_KEYWORDS([segment])
1288 AT_DATA([input], [dnl
1289 define !macro1.
1290 data list /x 1.
1291 ])
1292 AT_DATA([expout-base], [dnl
1293 identifier      define    space
1294 macro_id        !macro1
1295 end_command     .
1296 newline         \n (first)
1297
1298 identifier      data    space
1299 identifier      list    space
1300 punct           /
1301 identifier      x    space
1302 number          1
1303 end_command     .
1304 -newline         \n (first)
1305 -
1306 end
1307 ])
1308 PSPP_CHECK_SEGMENT([-i])
1309 AT_CLEANUP
1310 \f
1311 AT_SETUP([DEFINE command - early end of command 2])
1312 AT_KEYWORDS([segment])
1313 AT_DATA([input], [dnl
1314 define !macro1
1315 x.
1316 data list /x 1.
1317 ])
1318 AT_DATA([expout-base], [dnl
1319 identifier      define    space
1320 macro_id        !macro1
1321 newline         \n (later)
1322
1323 identifier      x
1324 end_command     .
1325 newline         \n (first)
1326
1327 identifier      data    space
1328 identifier      list    space
1329 punct           /
1330 identifier      x    space
1331 number          1
1332 end_command     .
1333 -newline         \n (first)
1334 -
1335 end
1336 ])
1337 PSPP_CHECK_SEGMENT([-i])
1338 AT_CLEANUP
1339 \f
1340 AT_SETUP([DEFINE command - early end of command 3])
1341 AT_KEYWORDS([segment])
1342 AT_DATA([input], [dnl
1343 define !macro1(.
1344 x.
1345 data list /x 1.
1346 ])
1347 AT_DATA([expout-base], [dnl
1348 identifier      define    space
1349 macro_id        !macro1
1350 punct           (
1351 end_command     .
1352 newline         \n (first)
1353
1354 identifier      x
1355 end_command     .
1356 newline         \n (first)
1357
1358 identifier      data    space
1359 identifier      list    space
1360 punct           /
1361 identifier      x    space
1362 number          1
1363 end_command     .
1364 -newline         \n (first)
1365 -
1366 end
1367 ])
1368 PSPP_CHECK_SEGMENT([-i])
1369 AT_CLEANUP
1370 \f
1371 AT_SETUP([DEFINE command - early end of command 4])
1372 AT_KEYWORDS([segment])
1373 AT_DATA([input], [dnl
1374 dnl Notice the command terminator at the end of the DEFINE command,
1375 dnl which should not be there and ends it early.
1376 define !macro1.
1377 data list /x 1.
1378 ])
1379 AT_DATA([expout-base], [dnl
1380 identifier      define    space
1381 macro_id        !macro1
1382 end_command     .
1383 newline         \n (first)
1384
1385 identifier      data    space
1386 identifier      list    space
1387 punct           /
1388 identifier      x    space
1389 number          1
1390 end_command     .
1391 -newline         \n (first)
1392 -
1393 end
1394 ])
1395 PSPP_CHECK_SEGMENT([-i])
1396 AT_CLEANUP
1397 \f
1398 AT_SETUP([DEFINE command - missing !ENDDEFINE])
1399 AT_KEYWORDS([segment])
1400 AT_DATA([input], [dnl
1401 define !macro1()
1402 content line 1
1403 content line 2
1404 ])
1405 AT_DATA([expout-base], [dnl
1406 identifier      define    space
1407 macro_id        !macro1
1408 punct           (
1409 punct           )
1410 spaces
1411 newline         \n (DEFINE)
1412
1413 macro_body      content_line_1
1414 newline         \n (DEFINE)
1415
1416 macro_body      content_line_2
1417 -newline         \n (DEFINE)
1418 -
1419 end
1420 ])
1421 PSPP_CHECK_SEGMENT([-i])
1422 AT_CLEANUP
1423 \f
1424 AT_SETUP([batch mode])
1425 AT_KEYWORDS([segment])
1426 AT_DATA([input], [dnl
1427 first command
1428      another line of first command
1429 +  second command
1430 third command
1431
1432 fourth command.
1433    fifth command.
1434 ])
1435 AT_DATA([expout-base], [dnl
1436 identifier      first    space
1437 identifier      command
1438 newline         \n (later)
1439
1440 spaces          _____
1441 identifier      another    space
1442 identifier      line    space
1443 identifier      of    space
1444 identifier      first    space
1445 identifier      command
1446 newline         \n (later)
1447
1448 start_command   +
1449 spaces          __
1450 identifier      second    space
1451 identifier      command
1452 newline         \n (later)
1453
1454 start_command
1455 identifier      third    space
1456 identifier      command
1457 newline         \n (later)
1458
1459 separate_commands
1460 newline         \n (first)
1461
1462 identifier      fourth    space
1463 identifier      command
1464 end_command     .
1465 newline         \n (first)
1466
1467 spaces          ___
1468 identifier      fifth    space
1469 identifier      command
1470 end_command     .
1471 -newline         \n (first)
1472 -
1473 end
1474 ])
1475 PSPP_CHECK_SEGMENT([-b])
1476 AT_CLEANUP
1477 \f
1478 AT_SETUP([auto mode])
1479 AT_KEYWORDS([segment])
1480 AT_DATA([input], [dnl
1481 command
1482      another line of command
1483 2sls
1484 +  another command
1485 another line of second command
1486 data list /x 1
1487 aggregate.
1488 print eject.
1489 twostep cluster
1490
1491
1492 fourth command.
1493    fifth command.
1494 ])
1495 AT_DATA([expout-base], [dnl
1496 identifier      command
1497 newline         \n (later)
1498
1499 spaces          _____
1500 identifier      another    space
1501 identifier      line    space
1502 identifier      of    space
1503 identifier      command
1504 newline         \n (later)
1505
1506 start_command
1507 number          2
1508 identifier      sls
1509 newline         \n (later)
1510
1511 start_command   +
1512 spaces          __
1513 identifier      another    space
1514 identifier      command
1515 newline         \n (later)
1516
1517 identifier      another    space
1518 identifier      line    space
1519 identifier      of    space
1520 identifier      second    space
1521 identifier      command
1522 newline         \n (later)
1523
1524 start_command
1525 identifier      data    space
1526 identifier      list    space
1527 punct           /
1528 identifier      x    space
1529 number          1
1530 newline         \n (later)
1531
1532 start_command
1533 identifier      aggregate
1534 end_command     .
1535 newline         \n (first)
1536
1537 identifier      print    space
1538 identifier      eject
1539 end_command     .
1540 newline         \n (first)
1541
1542 identifier      twostep    space
1543 identifier      cluster
1544 newline         \n (later)
1545
1546 separate_commands
1547 newline         \n (first)
1548
1549 separate_commands
1550 newline         \n (first)
1551
1552 identifier      fourth    space
1553 identifier      command
1554 end_command     .
1555 newline         \n (first)
1556
1557 spaces          ___
1558 identifier      fifth    space
1559 identifier      command
1560 end_command     .
1561 -newline         \n (first)
1562 -
1563 end
1564 ])
1565 PSPP_CHECK_SEGMENT([-a])
1566 AT_CLEANUP