macro: Continue expanding macro even in face of errors in call.
[pspp] / tests / language / control / define.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 nGeneral 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([DEFINE])
18
19 AT_SETUP([simple macro expansion])
20 AT_DATA([define.sps], [dnl
21 DEFINE !macro()
22 a b c d
23 e f g h.
24 i j k l
25 1,2,3,4.
26 5+6+7.
27 m(n,o).
28 "a" "b" "c" 'a' 'b' 'c'.
29 "x "" y".
30 !ENDDEFINE.
31 DEBUG EXPAND.
32 !macro
33 ])
34 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
35 a b c d e f g h.
36 i j k l 1, 2, 3, 4.
37 5 + 6 + 7.
38 m(n, o).
39 "a" "b" "c" 'a' 'b' 'c'.
40 "x "" y".
41 ])
42 AT_CLEANUP
43
44 AT_SETUP([macro expansion - one !TOKENS(1) positional argument])
45 AT_KEYWORDS([TOKENS])
46 AT_DATA([define.sps], [dnl
47 DEFINE !t1(!positional=!tokens(1)) t1 (!1) !ENDDEFINE.
48 DEBUG EXPAND.
49 !t1 a.
50 !t1 b.
51 !t1 a b.
52 ])
53 AT_CAPTURE_FILE([define.sps])
54 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
55 t1(a)
56
57 t1(b)
58
59 t1(a)
60
61 note: unexpanded token "b"
62 ])
63 AT_CLEANUP
64
65 AT_SETUP([macro expansion with positional arguments])
66 AT_DATA([define.sps], [dnl
67 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
68 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
69 DEFINE !t2(!positional !tokens(2)) t2 (!1) !ENDDEFINE.
70
71 DEFINE !ce(!positional=!charend('/')) ce (!1) !ENDDEFINE.
72 DEFINE !ce2(!positional=!charend('(')
73            /!positional !charend(')'))
74 ce2 (!1, !2)
75 !ENDDEFINE.
76
77 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
78
79 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
80 DEFINE !cmd2(!positional !cmdend
81             /!positional !tokens(1))
82 cmd2(!1, !2)
83 !ENDDEFINE.
84
85 DEFINE !p(!positional !tokens(1)
86          /!positional !tokens(1)
87          /!positional !tokens(1))
88 p(!1, !2, !3)(!*)
89 !ENDDEFINE.
90
91 DEBUG EXPAND.
92 !title "!TOKENS(1) argument."
93 !t1 a.
94 !t1 b.
95 !t1 a b.
96
97 !title "!TOKENS(2) argument."
98 !t2 a b.
99 !t2 b c d.
100
101 !title "!CHAREND argument."
102 !ce/.
103 !ce x/.
104 !ce x y/.
105 !ce x y z/.
106
107 !title "Two !CHAREND arguments."
108 !ce2 x(y).
109 !ce2 1 2 3 4().
110
111 !title "!ENCLOSE argument."
112 !e {}.
113 !e {a}.
114 !e {a b}.
115
116 !title "!CMDEND argument."
117 !cmd 1 2 3 4.
118 !cmd2 5 6.
119 7.
120
121 !title "Three !TOKENS(1) arguments."
122 !p a b c.
123 !p 1 -2 -3.
124 ])
125 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
126 "!TOKENS(1) argument."
127
128 t1(a)
129
130 t1(b)
131
132 t1(a)
133
134 note: unexpanded token "b"
135
136 "!TOKENS(2) argument."
137
138 t2(a b)
139
140 t2(b c)
141
142 note: unexpanded token "d"
143
144 "!CHAREND argument."
145
146 ce( )
147
148 ce(x)
149
150 ce(x y)
151
152 ce(x y z)
153
154 "Two !CHAREND arguments."
155
156 ce2(x, y)
157
158 ce2(1 2 3 4, )
159
160 "!ENCLOSE argument."
161
162 e( )
163
164 e(a)
165
166 e(a b)
167
168 "!CMDEND argument."
169
170 cmd(1 2 3 4)
171
172 cmd2(5 6, )
173
174 note: unexpanded token "7"
175
176 "Three !TOKENS(1) arguments."
177
178 p(a, b, c) (a b c)
179
180 p(1, -2, -3) (1 -2 -3)
181 ])
182 AT_CLEANUP
183
184 AT_SETUP([macro call missing positional !TOKENS arguments])
185 AT_KEYWORDS([TOKENS])
186 AT_DATA([define.sps], [dnl
187 DEFINE !p(!positional !tokens(1) !default(x)
188          /!positional !tokens(1) !default(y)
189          /!positional !tokens(1) !default(z))
190 (!1, !2, !3)
191 !ENDDEFINE.
192 DEBUG EXPAND.
193 !p a b c.
194 !p a b.
195 !p a.
196 !p.
197 ])
198 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
199 (a, b, c)
200
201 (a, b, z)
202
203 (a, y, z)
204
205 (x, y, z)
206 ])
207 AT_CLEANUP
208
209 AT_SETUP([macro call incomplete positional !TOKENS arguments])
210 AT_KEYWORDS([TOKENS])
211 AT_DATA([define.sps], [dnl
212 DEFINE !p(!positional !tokens(2) !default(x)
213          /!positional !tokens(2) !default(y)
214          /!positional !tokens(2) !default(z))
215 (!1, !2, !3)
216 !ENDDEFINE.
217 DEBUG EXPAND.
218 !p a1 a2 b1 b2 c1 c2.
219 !p a1 a2 b1 b2 c1.
220 !p a1 a2 b1 b2.
221 !p a1 a2 b1.
222 !p a1 a2.
223 !p a1.
224 !p.
225 ])
226 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
227 (a1 a2, b1 b2, c1 c2)
228
229 define.sps:8.18: error: DEBUG EXPAND: Reached end of command expecting 1 more
230 token in argument !3 to macro !p.
231
232 (a1 a2, b1 b2, c1)
233
234 (a1 a2, b1 b2, z)
235
236 define.sps:10.12: error: DEBUG EXPAND: Reached end of command expecting 1 more
237 token in argument !2 to macro !p.
238
239 (a1 a2, b1, z)
240
241 (a1 a2, y, z)
242
243 define.sps:12.6: error: DEBUG EXPAND: Reached end of command expecting 1 more
244 token in argument !1 to macro !p.
245
246 (a1, y, z)
247
248 (x, y, z)
249 ])
250 AT_CLEANUP
251
252 AT_SETUP([macro call empty positional !CHAREND arguments])
253 AT_KEYWORDS([CHAREND])
254 AT_DATA([define.sps], [dnl
255 DEFINE !p(!positional !charend(',') !default(x)
256          /!positional !charend(';') !default(y)
257          /!positional !charend(':') !default(z))
258 (!1, !2, !3)
259 !ENDDEFINE.
260 DEBUG EXPAND.
261 !p a,b;c:.
262 !p a,b;:.
263 !p a,;c:.
264 !p a,;:.
265 !p,b;c:.
266 !p,b;:.
267 !p,;c:.
268 !p,;:.
269 ])
270 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
271 (a, b, c)
272
273 (a, b, )
274
275 (a, , c)
276
277 (a, , )
278
279 (, b, c)
280
281 (, b, )
282
283 (, , c)
284
285 (, , )
286 ])
287 AT_CLEANUP
288
289 AT_SETUP([macro call missing positional !CHAREND arguments])
290 AT_DATA([define.sps], [dnl
291 DEFINE !p(!positional !charend(',') !default(x)
292          /!positional !charend(';') !default(y)
293          /!positional !charend(':') !default(z))
294 (!1, !2, !3)
295 !ENDDEFINE.
296 DEBUG EXPAND.
297 !p a,b;c:.
298 !p a,b;.
299 !p a,;.
300 !p ,b;.
301 !p ,;.
302
303 !p a,.
304 !p ,.
305
306 !p.
307 ])
308 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
309 (a, b, c)
310
311 (a, b, z)
312
313 (a, , z)
314
315 (, b, z)
316
317 (, , z)
318
319 (a, y, z)
320
321 (, y, z)
322
323 (x, y, z)
324 ])
325 AT_CLEANUP
326
327 AT_SETUP([macro call incomplete positional !CHAREND arguments])
328 AT_KEYWORDS([CHAREND])
329 AT_DATA([define.sps], [dnl
330 DEFINE !p(!positional !charend(',') !default(x)
331          /!positional !charend(';') !default(y)
332          /!positional !charend(':') !default(z))
333 (!1, !2, !3)
334 !ENDDEFINE.
335 DEBUG EXPAND.
336 !p a,b;c:.
337 !p a,b;c.
338 !p a,b;.
339 !p a,b.
340 !p a,.
341 !p a.
342 !p.
343 ])
344 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
345 (a, b, c)
346
347 define.sps:8.9: error: DEBUG EXPAND: Reached end of command expecting ":" in
348 argument !3 to macro !p.
349
350 (a, b, c)
351
352 (a, b, z)
353
354 define.sps:10.7: error: DEBUG EXPAND: Reached end of command expecting ";" in
355 argument !2 to macro !p.
356
357 (a, b, z)
358
359 (a, y, z)
360
361 define.sps:12.5: error: DEBUG EXPAND: Reached end of command expecting "," in
362 argument !1 to macro !p.
363
364 (a, y, z)
365
366 (x, y, z)
367 ])
368 AT_CLEANUP
369
370 AT_SETUP([macro call missing positional !ENCLOSE arguments])
371 AT_KEYWORDS([ENCLOSE])
372 AT_DATA([define.sps], [dnl
373 DEFINE !p(!positional !enclose('(',')') !default(x)
374          /!positional !enclose('<','>') !default(y)
375          /!positional !enclose('{','}') !default(z))
376 (!1, !2, !3)
377 !ENDDEFINE.
378 DEBUG EXPAND.
379 !p (a)<b>{c}.
380 !p (a)<b>.
381 !p (a).
382 !p.
383 ])
384 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
385 (a, b, c)
386
387 (a, b, z)
388
389 (a, y, z)
390
391 (x, y, z)
392 ])
393 AT_CLEANUP
394
395 AT_SETUP([macro call incomplete positional !ENCLOSE arguments])
396 AT_KEYWORDS([ENCLOSE])
397 AT_DATA([define.sps], [dnl
398 DEFINE !p(!positional !enclose('(',')') !default(x)
399          /!positional !enclose('<','>') !default(y)
400          /!positional !enclose('{','}') !default(z))
401 (!1, !2, !3)
402 !ENDDEFINE.
403 DEBUG EXPAND.
404 !p (a)<b>{c}.
405 !p (a)<b>{c.
406 !p (a)<b>{.
407 !p (a)<b>.
408 !p (a)<b.
409 !p (a)<.
410 !p (a).
411 !p (a.
412 !p (.
413 !p.
414 ])
415 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
416 (a, b, c)
417
418 define.sps:8.12: error: DEBUG EXPAND: Reached end of command expecting "}" in
419 argument !3 to macro !p.
420
421 (a, b, c)
422
423 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "}" in
424 argument !3 to macro !p.
425
426 (a, b, )
427
428 (a, b, z)
429
430 define.sps:11.9: error: DEBUG EXPAND: Reached end of command expecting ">" in
431 argument !2 to macro !p.
432
433 (a, b, z)
434
435 define.sps:12.8: error: DEBUG EXPAND: Reached end of command expecting ">" in
436 argument !2 to macro !p.
437
438 (a, , z)
439
440 (a, y, z)
441
442 define.sps:14.6: error: DEBUG EXPAND: Reached end of command expecting ")" in
443 argument !1 to macro !p.
444
445 (a, y, z)
446
447 define.sps:15.5: error: DEBUG EXPAND: Reached end of command expecting ")" in
448 argument !1 to macro !p.
449
450 (, y, z)
451
452 (x, y, z)
453 ])
454 AT_CLEANUP
455
456 AT_SETUP([keyword macro argument name with ! prefix])
457 AT_DATA([define.sps], [dnl
458 DEFINE !macro(!x !TOKENS(1).
459 ])
460 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
461 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `!x': Keyword macro parameter must be named in definition without ""!"" prefix."
462 ])
463 AT_CLEANUP
464
465 AT_SETUP([reserved macro keyword argument name])
466 AT_DATA([define.sps], [dnl
467 DEFINE !macro(if=!TOKENS(1).
468 ])
469 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
470 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `if': Cannot use macro keyword ""if"" as an argument name."
471 ])
472 AT_CLEANUP
473
474 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument])
475 AT_KEYWORDS([TOKENS])
476 AT_DATA([define.sps], [dnl
477 DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.
478 DEBUG EXPAND.
479 !k arg1=x.
480 !k arg1=x y.
481 !k.
482 ])
483 AT_CAPTURE_FILE([define.sps])
484 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
485 k(x)
486
487 k(x)
488
489 note: unexpanded token "y"
490
491 k( )
492 ])
493 AT_CLEANUP
494
495 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument - negative])
496 AT_KEYWORDS([TOKENS])
497 AT_DATA([define.sps], [dnl
498 DEFINE !k(arg1 !TOKENS(1)) k(!arg1) !ENDDEFINE.
499 DEBUG EXPAND.
500 !k arg1.
501 !k arg1=.
502 ])
503 AT_CAPTURE_FILE([define.sps])
504 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
505 define.sps:3.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
506 argument !arg1 to macro !k.
507
508 k( )
509
510 define.sps:4.9: error: DEBUG EXPAND: Reached end of command expecting 1 more
511 token in argument !arg1 to macro !k.
512
513 k( )
514 ])
515 AT_CLEANUP
516
517 AT_SETUP([macro expansion - !CHAREND keyword arguments])
518 AT_KEYWORDS([CHAREND])
519 AT_DATA([define.sps], [dnl
520 DEFINE !k(arg1 = !CHAREND('/')
521          /arg2 = !CHAREND('/'))
522 k(!arg1, !arg2)
523 !ENDDEFINE.
524 DEBUG EXPAND.
525 !k arg1=x/ arg2=y/.
526 !k arg1=x/.
527 !k arg2=y/.
528 !k.
529 ])
530 AT_CAPTURE_FILE([define.sps])
531 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
532 k(x, y)
533
534 k(x, )
535
536 k(, y)
537
538 k(, )
539 ])
540 AT_CLEANUP
541
542 AT_SETUP([macro expansion - !CHAREND keyword arguments - negative])
543 AT_KEYWORDS([CHAREND])
544 AT_DATA([define.sps], [dnl
545 DEFINE !k(arg1 = !CHAREND('/')
546          /arg2 = !CHAREND('/'))
547 k(!arg1, !arg2)
548 !ENDDEFINE.
549 DEBUG EXPAND.
550 !k arg1.
551 !k arg1=.
552 !k arg1=x.
553 !k arg1=x/ arg2=y.
554 ])
555 AT_CAPTURE_FILE([define.sps])
556 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
557 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
558 argument !arg1 to macro !k.
559
560 k(, )
561
562 define.sps:7.9: error: DEBUG EXPAND: Reached end of command expecting "/" in
563 argument !arg1 to macro !k.
564
565 k(, )
566
567 define.sps:8.10: error: DEBUG EXPAND: Reached end of command expecting "/" in
568 argument !arg1 to macro !k.
569
570 k(x, )
571
572 define.sps:9.18: error: DEBUG EXPAND: Reached end of command expecting "/" in
573 argument !arg2 to macro !k.
574
575 k(x, y)
576 ])
577 AT_CLEANUP
578
579 AT_SETUP([macro expansion - !ENCLOSE keyword arguments])
580 AT_KEYWORDS([ENCLOSE])
581 AT_DATA([define.sps], [dnl
582 DEFINE !k(arg1 = !ENCLOSE('(',')')
583          /arg2 = !ENCLOSE('{','}'))
584 k(!arg1, !arg2)
585 !ENDDEFINE.
586 DEBUG EXPAND.
587 !k arg1=(x) arg2={y}.
588 !k arg1=(x).
589 !k arg2={y}.
590 !k.
591 ])
592 AT_CAPTURE_FILE([define.sps])
593 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
594 k(x, y)
595
596 k(x, )
597
598 k(, y)
599
600 k(, )
601 ])
602 AT_CLEANUP
603
604 AT_SETUP([macro expansion - !ENCLOSE keyword arguments - negative])
605 AT_KEYWORDS([ENCLOSE])
606 AT_DATA([define.sps], [dnl
607 DEFINE !k(arg1 = !ENCLOSE('(',')')
608          /arg2 = !ENCLOSE('{','}'))
609 k(!arg1, !arg2)
610 !ENDDEFINE.
611 DEBUG EXPAND.
612 !k arg1.
613 !k arg1=.
614 !k arg1=x.
615 !k arg1=(x.
616 !k arg1=(x) arg2.
617 !k arg1=(x) arg2=.
618 !k arg1=(x) arg2=y.
619 !k arg1=(x) arg2=(y.
620 ])
621 AT_CAPTURE_FILE([define.sps])
622 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
623 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
624 argument !arg1 to macro !k.
625
626 k(, )
627
628 define.sps:7.9: error: DEBUG EXPAND: Found `.' while expecting `@{:@' reading
629 argument !arg1 to macro !k.
630
631 k(, )
632
633 define.sps:8.9: error: DEBUG EXPAND: Found `x' while expecting `@{:@' reading
634 argument !arg1 to macro !k.
635
636 k(, )
637
638 note: unexpanded token "x"
639
640 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "@:}@" in
641 argument !arg1 to macro !k.
642
643 k(x, )
644
645 define.sps:10.17: error: DEBUG EXPAND: Found `.' while expecting `=' reading
646 argument !arg2 to macro !k.
647
648 k(x, )
649
650 define.sps:11.18: error: DEBUG EXPAND: Found `.' while expecting `{' reading
651 argument !arg2 to macro !k.
652
653 k(x, )
654
655 define.sps:12.18: error: DEBUG EXPAND: Found `y' while expecting `{' reading
656 argument !arg2 to macro !k.
657
658 k(x, )
659
660 note: unexpanded token "y"
661
662 define.sps:13.18: error: DEBUG EXPAND: Found `@{:@' while expecting `{' reading
663 argument !arg2 to macro !k.
664
665 k(x, )
666
667 note: unexpanded token "@{:@"
668
669 note: unexpanded token "y"
670 ])
671 AT_CLEANUP
672
673 dnl Keep this test in sync with the examples for !BLANKS in the manual.
674 AT_SETUP([macro expansion - !BLANKS])
675 AT_KEYWORDS([BLANKS])
676 AT_DATA([define.sps], [dnl
677 DEFINE !b()
678 !BLANKS(0).
679 !QUOTE(!BLANKS(0)).
680 !BLANKS(1).
681 !QUOTE(!BLANKS(1)).
682 !BLANKS(2).
683 !QUOTE(!BLANKS(2)).
684 !BLANKS(5).
685 !QUOTE(!BLANKS(5)).
686 !ENDDEFINE.
687 DEBUG EXPAND.
688 !b.
689 ])
690 AT_CAPTURE_FILE([define.sps])
691 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
692 .
693 ''.
694 .
695 ' '.
696 .
697 '  '.
698 .
699 '     '.
700 ])
701 AT_CLEANUP
702
703 dnl Keep this test in sync with the examples for !CONCAT in the manual.
704 AT_SETUP([macro expansion - !CONCAT])
705 AT_KEYWORDS([CONCAT])
706 AT_DATA([define.sps], [dnl
707 DEFINE !c()
708 !CONCAT(x, y).
709 !CONCAT('x', 'y').
710 !CONCAT(12, 34).
711 !CONCAT(!NULL, 123).
712 !CONCAT(x, 0).
713 !CONCAT(x, 0, y).
714 !CONCAT(0, x).
715 !CONCAT(0, x, y).
716 !ENDDEFINE.
717 DEBUG EXPAND.
718 !c
719 ])
720 AT_CAPTURE_FILE([define.sps])
721 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
722 xy.
723 xy.
724 1234.
725 123.
726 x0.
727 x0y.
728 0 x.
729 0 xy.
730 ])
731 AT_CLEANUP
732
733 dnl Keep this test in sync with the examples for !EVAL in the manual.
734 AT_SETUP([macro expansion - !EVAL])
735 AT_KEYWORDS([EVAL])
736 AT_DATA([define.sps], [dnl
737 DEFINE !vars() a b c !ENDDEFINE.
738
739 DEFINE !e()
740 !vars.
741 !QUOTE(!vars).
742 !EVAL(!vars).
743 !QUOTE(!EVAL(!vars)).
744 !ENDDEFINE
745
746 DEFINE !e2(!positional !enclose('(',')'))
747 !1.
748 !QUOTE(!1).
749 !EVAL(!1).
750 !QUOTE(!EVAL(!1)).
751 !ENDDEFINE.
752 DEBUG EXPAND.
753 !e.
754 !e2(!vars).
755 ])
756 AT_CAPTURE_FILE([define.sps])
757 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
758 a b c.
759 '!vars'.
760 a b c.
761 'a b c'.
762
763 a b c.
764 '!vars'.
765 a b c.
766 'a b c'.
767 ])
768 AT_CLEANUP
769
770 dnl Keep this test in sync with the examples for !HEAD in the manual.
771 AT_SETUP([macro expansion - !HEAD])
772 AT_KEYWORDS([HEAD])
773 AT_DATA([define.sps], [dnl
774 DEFINE !h()
775 !HEAD('a b c').
776 !HEAD('a').
777 !HEAD(!NULL).
778 !HEAD('').
779 !ENDDEFINE.
780 DEBUG EXPAND.
781 !h.
782 ])
783 AT_CAPTURE_FILE([define.sps])
784 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
785 a.
786 a.
787 .
788 .
789 ])
790 AT_CLEANUP
791
792 dnl Keep this test in sync with the examples for !TAIL in the manual.
793 AT_SETUP([macro expansion - !TAIL])
794 AT_KEYWORDS([TAIL])
795 AT_DATA([define.sps], [dnl
796 DEFINE !t()
797 !TAIL('a b c').
798 !TAIL('a').
799 !TAIL(!NULL).
800 !TAIL('').
801 !ENDDEFINE.
802 DEBUG EXPAND.
803 !t.
804 ])
805 AT_CAPTURE_FILE([define.sps])
806 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
807 b c.
808 .
809 .
810 .
811 ])
812 AT_CLEANUP
813
814 dnl Keep this test in sync with the examples for !INDEX in the manual.
815 AT_SETUP([macro expansion - !INDEX])
816 AT_KEYWORDS([INDEX])
817 AT_DATA([define.sps], [dnl
818 DEFINE !i()
819 !INDEX(banana, an).
820 !INDEX(banana, nan).
821 !INDEX(banana, apple).
822 !INDEX("banana", nan).
823 !INDEX("banana", "nan").
824 !INDEX(!UNQUOTE("banana"), !UNQUOTE("nan")).
825 !ENDDEFINE.
826 DEBUG EXPAND.
827 !i.
828 ])
829 AT_CAPTURE_FILE([define.sps])
830 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
831 2.
832 3.
833 0.
834 4.
835 0.
836 3.
837 ])
838 AT_CLEANUP
839
840 dnl Keep this test in sync with the examples for !LENGTH in the manual.
841 AT_SETUP([macro expansion - !LENGTH])
842 AT_KEYWORDS([LENGTH])
843 AT_DATA([define.sps], [dnl
844 DEFINE !l()
845 !LENGTH(123).
846 !LENGTH(123.00).
847 !LENGTH( 123 ).
848 !LENGTH("123").
849 !LENGTH(xyzzy).
850 !LENGTH("xyzzy").
851 !LENGTH("xy""zzy").
852 !LENGTH(!UNQUOTE("xyzzy")).
853 !LENGTH(!UNQUOTE("xy""zzy")).
854 !LENGTH(!NULL).
855 !ENDDEFINE.
856 DEFINE !la(!positional !enclose('(',')'))
857 !LENGTH(!1).
858 !ENDDEFINE.
859 DEBUG EXPAND.
860 !l.
861 !la(a b c).
862 !la().
863 ])
864 AT_CAPTURE_FILE([define.sps])
865 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
866 3.
867 6.
868 3.
869 5.
870 5.
871 7.
872 9.
873 5.
874 6.
875 0.
876
877 5.
878
879 0.
880 ])
881 AT_CLEANUP
882
883 dnl Keep this test in sync with the examples for !SUBSTR in the manual.
884 AT_SETUP([macro expansion - !SUBSTR])
885 AT_KEYWORDS([SUBSTR])
886 AT_DATA([define.sps], [dnl
887 DEFINE !s()
888 !SUBSTR(banana, 3).
889 !SUBSTR(banana, 3, 3).
890 !SUBSTR("banana", 1, 3).
891 !SUBSTR(!UNQUOTE("banana"), 3).
892 !SUBSTR("banana", 3, 3).
893 !SUBSTR(banana, 3, 0).
894 !SUBSTR(banana, 3, 10).
895 !SUBSTR(banana, 10, 3).
896 !ENDDEFINE.
897 DEBUG EXPAND.
898 !s.
899 ])
900 AT_CAPTURE_FILE([define.sps])
901 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
902 define.sps:1-10: At `"ba' in the expansion of `!s',dnl "
903
904 define.sps:12.1-12.2: error: DEBUG EXPAND: Unterminated string constant.
905
906 nana.
907 nan.
908 .
909 nana.
910 ana.
911 .
912 nana.
913 .
914 ])
915 AT_CLEANUP
916
917 dnl Keep this test in sync with the examples for !UPCASE in the manual.
918 AT_SETUP([macro expansion - !UPCASE])
919 AT_KEYWORDS([UPCASE])
920 AT_DATA([define.sps], [dnl
921 DEFINE !u()
922 !UPCASE(freckle).
923 !UPCASE('freckle').
924 !UPCASE('a b c').
925 !UPCASE('A B C').
926 !ENDDEFINE.
927 DEBUG EXPAND.
928 !u.
929 ])
930 AT_CAPTURE_FILE([define.sps])
931 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
932 FRECKLE.
933 FRECKLE.
934 A B C.
935 A B C.
936 ])
937 AT_CLEANUP
938
939 dnl !* is implemented separately inside and outside function arguments
940 dnl so this test makes sure to include both.
941 AT_SETUP([macro expansion - !*])
942 AT_DATA([define.sps], [dnl
943 DEFINE !m(!POSITIONAL !TOKENS(1)
944          /!POSITIONAL !TOKENS(1))
945 !*/
946 !LENGTH(!*)/
947 !SUBSTR(!*, 3)/
948 !QUOTE(!*).
949 !ENDDEFINE.
950 DEBUG EXPAND.
951 !m 123 b
952 !m 2 3
953 !m '' 'b'.
954 ])
955 AT_CAPTURE_FILE([define.sps])
956 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
957 123 b / 5 / 3 b / '123 b'.
958
959 2 3 / 3 / 3 / '2 3'.
960
961 '' 'b' / 6 / 'b' / ''''' ''b'''.
962 ])
963 AT_CLEANUP
964
965 AT_SETUP([macro maximum nesting level (MNEST)])
966 AT_KEYWORDS([MNEST])
967 AT_DATA([define.sps], [dnl
968 DEFINE !macro()
969 !macro
970 !ENDDEFINE.
971 !macro.
972 ])
973 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
974 "define.sps:1-3: In the expansion of `!macro',
975 define.sps:1-3: inside the expansion of `!macro',
976 define.sps:1-3: inside the expansion of `!macro',
977 define.sps:1-3: inside the expansion of `!macro',
978 define.sps:1-3: inside the expansion of `!macro',
979 define.sps:1-3: inside the expansion of `!macro',
980 define.sps:1-3: inside the expansion of `!macro',
981 define.sps:1-3: inside the expansion of `!macro',
982 define.sps:1-3: inside the expansion of `!macro',
983 define.sps:1-3: inside the expansion of `!macro',
984 define.sps:1-3: inside the expansion of `!macro',
985 define.sps:1-3: inside the expansion of `!macro',
986 define.sps:1-3: inside the expansion of `!macro',
987 define.sps:1-3: inside the expansion of `!macro',
988 define.sps:1-3: inside the expansion of `!macro',
989 define.sps:1-3: inside the expansion of `!macro',
990 define.sps:1-3: inside the expansion of `!macro',
991 define.sps:1-3: inside the expansion of `!macro',
992 define.sps:1-3: inside the expansion of `!macro',
993 define.sps:1-3: inside the expansion of `!macro',
994 define.sps:1-3: inside the expansion of `!macro',
995 define.sps:1-3: inside the expansion of `!macro',
996 define.sps:1-3: inside the expansion of `!macro',
997 define.sps:1-3: inside the expansion of `!macro',
998 define.sps:1-3: inside the expansion of `!macro',
999 define.sps:1-3: inside the expansion of `!macro',
1000 define.sps:1-3: inside the expansion of `!macro',
1001 define.sps:1-3: inside the expansion of `!macro',
1002 define.sps:1-3: inside the expansion of `!macro',
1003 define.sps:1-3: inside the expansion of `!macro',
1004 define.sps:1-3: inside the expansion of `!macro',
1005 define.sps:1-3: inside the expansion of `!macro',
1006 define.sps:1-3: inside the expansion of `!macro',
1007 define.sps:1-3: inside the expansion of `!macro',
1008 define.sps:1-3: inside the expansion of `!macro',
1009 define.sps:1-3: inside the expansion of `!macro',
1010 define.sps:1-3: inside the expansion of `!macro',
1011 define.sps:1-3: inside the expansion of `!macro',
1012 define.sps:1-3: inside the expansion of `!macro',
1013 define.sps:1-3: inside the expansion of `!macro',
1014 define.sps:1-3: inside the expansion of `!macro',
1015 define.sps:1-3: inside the expansion of `!macro',
1016 define.sps:1-3: inside the expansion of `!macro',
1017 define.sps:1-3: inside the expansion of `!macro',
1018 define.sps:1-3: inside the expansion of `!macro',
1019 define.sps:1-3: inside the expansion of `!macro',
1020 define.sps:1-3: inside the expansion of `!macro',
1021 define.sps:1-3: inside the expansion of `!macro',
1022 define.sps:1-3: inside the expansion of `!macro',
1023 define.sps:1-3: inside the expansion of `!macro',
1024 define.sps:1-3: inside the expansion of `!macro',
1025 define.sps:4.1-4.6: error: DEFINE: Maximum nesting level 50 exceeded.  (Use SET MNEST to change the limit.)"
1026
1027 define.sps:4.1-4.6: error: Syntax error at `!macro' (in expansion of `!macro'): expecting command name.
1028 ])
1029 AT_CLEANUP
1030
1031 AT_SETUP([macro !IF condition])
1032 AT_KEYWORDS([if])
1033 for operators in \
1034     '!eq !ne !lt !gt !le !ge' \
1035     '  =  <>   <   >  <=  >='
1036 do
1037     set $operators
1038     AS_BOX([$operators])
1039     cat > define.sps <<EOF
1040 DEFINE !test(!positional !tokens(1))
1041 !if (!1 $1 1) !then true !else false !ifend
1042 !if (!1 $2 1) !then true !else false !ifend
1043 !if (!1 $3 1) !then true !else false !ifend
1044 !if (!1 $4 1) !then true !else false !ifend
1045 !if (!1 $5 1) !then true !else false !ifend
1046 !if (!1 $6 1) !then true !else false !ifend.
1047 !ENDDEFINE.
1048 DEBUG EXPAND.
1049 !test 0
1050 !test 1
1051 !test 2
1052 !test '1'
1053 !test 1.0
1054 EOF
1055     AT_CAPTURE_FILE([define.sps])
1056     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1057 false true true false true false.
1058
1059 true false false false true true.
1060
1061 false true false true false true.
1062
1063 true false false false true true.
1064
1065 false true false true false true.
1066 ])
1067 done
1068 AT_CLEANUP
1069
1070 AT_SETUP([macro !IF condition -- case sensitivity])
1071 AT_KEYWORDS([if])
1072 for operators in \
1073     '!eq !ne !lt !gt !le !ge' \
1074     '  =  <>   <   >  <=  >='
1075 do
1076     set $operators
1077     AS_BOX([$operators])
1078     cat > define.sps <<EOF
1079 DEFINE !test(!positional !tokens(1))
1080 !if (!1 $1 a) !then true !else false !ifend
1081 !if (!1 $1 A) !then true !else false !ifend
1082 !if (!1 $2 a) !then true !else false !ifend
1083 !if (!1 $2 A) !then true !else false !ifend
1084 !if (!1 $3 a) !then true !else false !ifend
1085 !if (!1 $3 A) !then true !else false !ifend
1086 !if (!1 $4 a) !then true !else false !ifend
1087 !if (!1 $4 A) !then true !else false !ifend
1088 !if (!1 $5 a) !then true !else false !ifend
1089 !if (!1 $5 A) !then true !else false !ifend
1090 !if (!1 $6 a) !then true !else false !ifend
1091 !if (!1 $6 A) !then true !else false !ifend
1092 !if (!1 $1 !null) !then true !else false !ifend
1093 !if (!1 $2 !null) !then true !else false !ifend.
1094 !ENDDEFINE.
1095 DEBUG EXPAND.
1096 !test a
1097 !test A
1098 !test b
1099 !test B
1100 EOF
1101     AT_CAPTURE_FILE([define.sps])
1102     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1103 true false false true false false false true true false true true false true.
1104
1105 false true true false true false false false true true false true false true.
1106
1107 false false true true false false true true false false true true false true.
1108
1109 false false true true true false false true true false false true false true.
1110 ])
1111 done
1112 AT_CLEANUP
1113
1114 AT_SETUP([macro !IF condition -- logical operators])
1115 AT_KEYWORDS([if])
1116 for operators in \
1117     '!and !or !not' \
1118     '   &   |    ~'
1119 do
1120     set $operators
1121     AS_BOX([$operators])
1122     cat > define.sps <<EOF
1123 DEFINE !test_binary(!positional !tokens(1)/!positional !tokens(1))
1124 !if !1 $1 !2 !then true !else false !ifend
1125 !if !1 $2 !2 !then true !else false !ifend.
1126 !ENDDEFINE.
1127
1128 DEFINE !test_unary(!positional !tokens(1))
1129 !if $3 !1 !then true !else false !ifend.
1130 !ENDDEFINE.
1131
1132 * These are:
1133   ((not A) and B) or C
1134   not (A and B) or C
1135   not A and (B or C)
1136 DEFINE !test_prec(!pos !tokens(1)/!pos !tokens(1)/!pos !tokens(1))
1137 !if $3 !1 $1 !2 $2 !3 !then true !else false !ifend
1138 !if $3 (!1 $1 !2) $2 !3 !then true !else false !ifend
1139 !if $3 !1 $1 (!2 $2 !3) !then true !else false !ifend
1140 !ENDDEFINE.
1141
1142 DEBUG EXPAND.
1143 !test_binary 0 0
1144 !test_binary 0 1
1145 !test_binary 1 0
1146 !test_binary 1 1
1147 !test_unary 0
1148 !test_unary 1
1149 !test_prec 0 0 0 !test_prec 0 0 1 !test_prec 0 1 0 !test_prec 0 1 1.
1150 !test_prec 1 0 0 !test_prec 1 0 1 !test_prec 1 1 0 !test_prec 1 1 1.
1151 EOF
1152     AT_CAPTURE_FILE([define.sps])
1153     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1154 false false.
1155
1156 false true.
1157
1158 false true.
1159
1160 true true.
1161
1162 true.
1163
1164 false.
1165
1166 false true false
1167 true true true
1168 true true true
1169 true true true
1170
1171 false true false
1172 true true false
1173 false false false
1174 true true false
1175 ])
1176 done
1177 AT_CLEANUP
1178
1179 AT_SETUP([macro !LET])
1180 AT_KEYWORDS([let])
1181 AT_DATA([define.sps], [dnl
1182 DEFINE !macro(!POS !CMDEND)
1183 !LET !v1 = !CONCAT('x',!1,'y')
1184 !LET !v2 = !QUOTE(!v1)
1185 !LET !v3 = (!LENGTH(!1) = 1)
1186 !LET !v4 = (!SUBSTR(!1, 3) = !NULL)
1187 v1=!v1.
1188 v2=!v2.
1189 v3=!v3.
1190 v4=!v4.
1191 !ENDDEFINE.
1192 DEBUG EXPAND.
1193 !macro 0.
1194 !macro.
1195 !macro xyzzy.
1196 ])
1197 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1198 v1 = x0y.
1199 v2 = x0y.
1200 v3 = 1.
1201 v4 = 1.
1202
1203 v1 = xy.
1204 v2 = xy.
1205 v3 = 0.
1206 v4 = 1.
1207
1208 v1 = xxyzzyy.
1209 v2 = xxyzzyy.
1210 v3 = 0.
1211 v4 = 0.
1212 ])
1213 AT_CLEANUP
1214
1215 AT_SETUP([macro indexed !DO])
1216 AT_KEYWORDS([index do])
1217 AT_DATA([define.sps], [dnl
1218 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1219
1220 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1221 !DO !var = !1 !TO !2 !var !DOEND.
1222 !ENDDEFINE.
1223
1224 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1225 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1226 !ENDDEFINE.
1227
1228 DEBUG EXPAND.
1229 !title "increasing".
1230 !for 1 5.
1231 !forby 1 5 1.
1232 !forby 1 5 2.
1233 !forby 1 5 2.5.
1234 !forby 1 5 -1.
1235
1236 !title "decreasing".
1237 !for 5 1.
1238 !forby 5 1 1.
1239 !forby 5 1 -1.
1240 !forby 5 1 -2.
1241 !forby 5 1 -3.
1242
1243 !title "non-integer".
1244 !for 1.5 3.5.
1245 ])
1246 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1247 "increasing".
1248
1249 1 2 3 4 5.
1250
1251 1 2 3 4 5.
1252
1253 1 3 5.
1254
1255 1 3.5.
1256
1257 .
1258
1259 "decreasing".
1260
1261 .
1262
1263 .
1264
1265 5 4 3 2 1.
1266
1267 5 3 1.
1268
1269 5 2.
1270
1271 "non-integer".
1272
1273 1.5 2.5 3.5.
1274 ])
1275 AT_CLEANUP
1276
1277 AT_SETUP([macro !DO invalid variable names])
1278 AT_KEYWORDS([index do])
1279 AT_DATA([define.sps], [dnl
1280 DEFINE !for(x=!TOKENS(1) / y=!TOKENS(1))
1281 !DO !x = !x !TO !y !var !DOEND.
1282 !ENDDEFINE.
1283
1284 DEFINE !for2(x=!TOKENS(1) / y=!TOKENS(1))
1285 !DO !noexpand = !x !TO !y !var !DOEND.
1286 !ENDDEFINE.
1287
1288 DEBUG EXPAND.
1289 !for x=1 y=5.
1290 !for2 x=1 y=5.
1291 ])
1292 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1293 define.sps:1-3: At `!x' in the expansion of `!for',
1294 define.sps:10.1-10.12: error: DEBUG EXPAND: Cannot use argument name or macro
1295 keyword as !DO variable.
1296
1297 !DO 1 = 1 !TO 5 !var !DOEND.
1298
1299 define.sps:5-7: At `!noexpand' in the expansion of `!for2',
1300 define.sps:11.1-11.13: error: DEBUG EXPAND: Cannot use argument name or macro
1301 keyword as !DO variable.
1302
1303 !DO !noexpand = 1 !TO 5 !var !DOEND.
1304 ])
1305 AT_CLEANUP
1306
1307 AT_SETUP([macro indexed !DO reaches MITERATE])
1308 AT_KEYWORDS([index do])
1309 AT_DATA([define.sps], [dnl
1310 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1311
1312 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1313 !DO !var = !1 !TO !2 !var !DOEND.
1314 !ENDDEFINE.
1315
1316 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1317 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1318 !ENDDEFINE.
1319
1320 SET MITERATE=3.
1321 DEBUG EXPAND.
1322 !title "increasing".
1323 !for 1 5.
1324 !forby 1 5 1.
1325 !forby 1 5 2.
1326 !forby 1 5 2.5.
1327 !forby 1 5 -1.
1328
1329 !title "decreasing".
1330 !for 5 1.
1331 !forby 5 1 1.
1332 !forby 5 1 -1.
1333 !forby 5 1 -2.
1334 !forby 5 1 -3.
1335
1336 !title "non-integer".
1337 !for 1.5 3.5.
1338 ])
1339 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1340 "increasing".
1341
1342 In the expansion of `!DO',
1343 define.sps:3-5: inside the expansion of `!for',
1344 define.sps:14.1-14.8: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1345 number of iterations 3.  (Use SET MITERATE to change the limit.)
1346
1347 1 2 3 4.
1348
1349 In the expansion of `!DO',
1350 define.sps:7-9: inside the expansion of `!forby',
1351 define.sps:15.1-15.12: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1352 number of iterations 3.  (Use SET MITERATE to change the limit.)
1353
1354 1 2 3 4.
1355
1356 1 3 5.
1357
1358 1 3.5.
1359
1360 .
1361
1362 "decreasing".
1363
1364 .
1365
1366 .
1367
1368 In the expansion of `!DO',
1369 define.sps:7-9: inside the expansion of `!forby',
1370 define.sps:23.1-23.13: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1371 number of iterations 3.  (Use SET MITERATE to change the limit.)
1372
1373 5 4 3 2.
1374
1375 5 3 1.
1376
1377 5 2.
1378
1379 "non-integer".
1380
1381 1.5 2.5 3.5.
1382 ])
1383 AT_CLEANUP
1384
1385 AT_SETUP([!BREAK with macro indexed !DO])
1386 AT_KEYWORDS([index do break])
1387 AT_DATA([define.sps], [dnl
1388 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1389
1390 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1391 !DO !var = !1 !TO !2
1392   !var
1393   !IF 1 !THEN
1394     !IF !var = !3 !THEN
1395       x
1396       !BREAK
1397       y
1398     !IFEND
1399     ,
1400   !IFEND
1401 !DOEND.
1402 !ENDDEFINE.
1403
1404 DEBUG EXPAND.
1405 !for 1 5 4.
1406 ])
1407 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1408 1, 2, 3, 4 x.
1409 ])
1410 AT_CLEANUP
1411
1412 AT_SETUP([macro list !DO])
1413 AT_KEYWORDS([index do])
1414 AT_DATA([define.sps], [dnl
1415 DEFINE !for(!POS !CMDEND)
1416 (!DO !i !IN (!1) (!i) !DOEND).
1417 !ENDDEFINE.
1418
1419 DEBUG EXPAND.
1420 !for a b c.
1421 !for 'foo bar baz quux'.
1422 !for.
1423 ])
1424 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1425 ( (a) (b) (c) ).
1426
1427 ( (foo) (bar) (baz) (quux) ).
1428
1429 ( ).
1430 ])
1431 AT_CLEANUP
1432
1433 AT_SETUP([macro list !DO reaches MITERATE])
1434 AT_KEYWORDS([index do])
1435 AT_DATA([define.sps], [dnl
1436 DEFINE !for(!POS !CMDEND)
1437 (!DO !i !IN (!1) (!i) !DOEND).
1438 !ENDDEFINE.
1439
1440 SET MITERATE=2.
1441 DEBUG EXPAND.
1442 !for a b c.
1443 !for 'foo bar baz quux'.
1444 !for.
1445 ])
1446 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1447 In the expansion of `!DO',
1448 define.sps:1-3: inside the expansion of `!for',
1449 define.sps:7.1-7.10: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1450 number of iterations 2.  (Use SET MITERATE to change the limit.)
1451
1452 ( (a) (b) ).
1453
1454 In the expansion of `!DO',
1455 define.sps:1-3: inside the expansion of `!for',
1456 define.sps:8.1-8.23: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1457 number of iterations 2.  (Use SET MITERATE to change the limit.)
1458
1459 ( (foo) (bar) ).
1460
1461 ( ).
1462 ])
1463 AT_CLEANUP
1464
1465 AT_SETUP([!BREAK with macro list !DO])
1466 AT_KEYWORDS([index break do])
1467 AT_DATA([define.sps], [dnl
1468 DEFINE !for(!POS !TOKENS(1) / !POS !CMDEND)
1469 (!DO !i !IN (!2)
1470   (!i)
1471   !IF 1 !THEN
1472     !IF !i = !1 !THEN
1473       x
1474       !BREAK
1475       y
1476     !IFEND
1477     ,
1478   !IFEND
1479 !DOEND).
1480 !ENDDEFINE.
1481
1482 DEBUG EXPAND.
1483 !for d a b c.
1484 !for baz 'foo bar baz quux'.
1485 !for e.
1486 ])
1487 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1488 ( (a), (b), (c), ).
1489
1490 ( (foo), (bar), (baz)x).
1491
1492 ( ).
1493 ])
1494 AT_CLEANUP
1495
1496 AT_SETUP([macro !LET])
1497 AT_DATA([define.sps], [dnl
1498 DEFINE !macro(!pos !enclose('(',')'))
1499 !LET !x=!1
1500 !LET !y=!QUOTE(!1)
1501 !LET !z=(!y="abc")
1502 !y !z
1503 !ENDDEFINE.
1504
1505 DEBUG EXPAND.
1506 !macro(1+2).
1507 !macro(abc).
1508 ])
1509 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
1510 1 + 2 0
1511
1512 abc 1
1513 ])
1514 AT_CLEANUP
1515
1516 AT_SETUP([macro !LET invalid variable names])
1517 AT_DATA([define.sps], [dnl
1518 DEFINE !macro(x=!tokens(1))
1519 !LET !x=!x
1520 !ENDDEFINE.
1521
1522 DEFINE !macro2()
1523 !LET !do=x
1524 !ENDDEFINE.
1525
1526 DEBUG EXPAND.
1527 !macro x=1.
1528 !macro2.
1529 ])
1530 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [1], [dnl
1531 "define.sps:1-3: At `!x' in the expansion of `!macro',
1532 define.sps:10.1-10.10: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!x"" as !LET variable."
1533
1534 !LET 1 = 1
1535
1536 "define.sps:5-7: At `!do' in the expansion of `!macro2',
1537 define.sps:11.1-11.7: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!do"" as !LET variable."
1538
1539 "define.sps:5-7: At `=' in the expansion of `!macro2',
1540 define.sps:11.1-11.7: error: DEBUG EXPAND: Expected macro variable name following !DO."
1541
1542 !LET !do = x
1543 ])
1544 AT_CLEANUP
1545
1546 AT_SETUP([BEGIN DATA inside a macro])
1547 AT_DATA([define.sps], [dnl
1548 DEFINE !macro()
1549 DATA LIST NOTABLE /x 1.
1550 BEGIN DATA
1551 1
1552 2
1553 3
1554 END DATA.
1555 LIST.
1556 !ENDDEFINE.
1557
1558 !macro
1559 ])
1560 AT_CHECK([pspp define.sps -O format=csv], [0], [dnl
1561 Table: Data List
1562 x
1563 1
1564 2
1565 3
1566 ])
1567 AT_CLEANUP
1568
1569 AT_SETUP([TITLE and SUBTITLE with macros])
1570 AT_KEYWORDS([macro])
1571 for command in TITLE SUBTITLE; do
1572     cat >title.sps <<EOF
1573 DEFINE !paste(!POS !TOKENS(1) / !POS !TOKENS(1))
1574 !CONCAT(!1,!2)
1575 !ENDDEFINE.
1576 $command prefix !paste foo bar suffix.
1577 SHOW $command.
1578 EOF
1579     cat >expout <<EOF
1580 title.sps:5: note: SHOW: $command is prefix foobar suffix.
1581 EOF
1582     AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
1583 done
1584 AT_CLEANUP
1585
1586 AT_SETUP([error message within macro expansion])
1587 AT_DATA([define.sps], [dnl
1588 DEFINE !vars(!POS !TOKENS(1)) a b C !ENDDEFINE.
1589 DATA LIST NOTABLE /a b 1-2.
1590 COMPUTE x = !vars x.
1591 ])
1592 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1593 define.sps:3.13-3.19: error: COMPUTE: Syntax error at `b' (in expansion of `!vars x'): expecting end of command.
1594 ])
1595 AT_CLEANUP
1596
1597 dnl A macro with keyword arguments needs a token of lookahead
1598 dnl to find out whether another keyword is present.  Test that
1599 dnl this special case works OK.
1600 AT_SETUP([macro calls in each others' lookahead])
1601 AT_DATA([define.sps], [dnl
1602 DEFINE !k(x=!DEFAULT(0) !TOKENS(1)/y=!DEFAULT(0) !TOKENS(1))
1603 (x=!x)(y=!y)
1604 !ENDDEFINE.
1605 DEBUG EXPAND.
1606 !k
1607 !k x=1
1608 !k y=2
1609 !k y=2 x=1
1610 !k x=1 y=2.
1611 ])
1612 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1613 (x = 0) (y = 0)
1614
1615 (x = 1) (y = 0)
1616
1617 (x = 0) (y = 2)
1618 (x = 1) (y = 2)
1619
1620 (x = 1) (y = 2)
1621 ])
1622 AT_CLEANUP
1623
1624 AT_SETUP([bad token in macro body])
1625 AT_DATA([define.sps], [dnl
1626 DEFINE !x()
1627 x'123'
1628 !ENDDEFINE.
1629 ])
1630 AT_CHECK([pspp define.sps], [1], [dnl
1631 define.sps:3: error: DEFINE: String of hex digits has 3 characters, which is
1632 not a multiple of 2.
1633 ])
1634 AT_CLEANUP
1635
1636 AT_SETUP([generic macro function syntax errors])
1637 AT_DATA([define.sps], [dnl
1638 DEFINE !a() !SUBSTR !ENDDEFINE.
1639 DEFINE !b() !SUBSTR x !ENDDEFINE.
1640 DEFINE !c() !SUBSTR(1x) !ENDDEFINE.
1641 DEFINE !d() !SUBSTR(1 !ENDDEFINE.
1642 DEFINE !narg_blanks() !BLANKS() !ENDDEFINE.
1643 DEFINE !narg_concat() !CONCAT() !ENDDEFINE.
1644 DEFINE !narg_eval() !EVAL() !ENDDEFINE.
1645 DEFINE !narg_head() !HEAD() !ENDDEFINE.
1646 DEFINE !narg_index() !INDEX() !ENDDEFINE.
1647 DEFINE !narg_length() !LENGTH() !ENDDEFINE.
1648 DEFINE !narg_null() !NULL() !ENDDEFINE.
1649 DEFINE !narg_quote() !QUOTE() !ENDDEFINE.
1650 DEFINE !narg_substr() !SUBSTR() !ENDDEFINE.
1651 DEFINE !narg_tail() !TAIL() !ENDDEFINE.
1652 DEFINE !narg_unquote() !UNQUOTE() !ENDDEFINE.
1653 DEFINE !narg_upcase() !UPCASE() !ENDDEFINE.
1654 dnl )
1655 DEBUG EXPAND.
1656 !a.
1657 !b.
1658 !c.
1659 !d.
1660 !narg_blanks.
1661 !narg_concat.
1662 !narg_eval.
1663 !narg_head.
1664 !narg_index.
1665 !narg_length.
1666 !narg_null.
1667 !narg_quote.
1668 !narg_substr.
1669 !narg_tail.
1670 !narg_unquote.
1671 !narg_upcase.
1672 ])
1673 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1674 define.sps:1: In the expansion of `!a',
1675 define.sps:18.1-18.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR.
1676
1677 !SUBSTR
1678
1679 define.sps:2: At `x' in the expansion of `!b',
1680 define.sps:19.1-19.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR.
1681
1682 !SUBSTR x
1683
1684 define.sps:3: At `x' in the expansion of `!c',
1685 define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro
1686 function !SUBSTR.
1687
1688 !SUBSTR(1 x)
1689
1690 define.sps:4: In the expansion of `!d',
1691 define.sps:21.1-21.2: error: DEBUG EXPAND: Missing `@:}@' in call to macro
1692 function !SUBSTR.
1693
1694 !SUBSTR@{:@1
1695
1696 define.sps:5: In the expansion of `!narg_blanks',
1697 define.sps:22.1-22.12: error: DEBUG EXPAND: Macro function !BLANKS takes one
1698 argument (not 0).
1699
1700 !BLANKS( )
1701
1702 define.sps:6: In the expansion of `!narg_concat',
1703 define.sps:23.1-23.12: error: DEBUG EXPAND: Macro function !CONCAT needs at
1704 least one argument.
1705
1706 !CONCAT( )
1707
1708 define.sps:7: In the expansion of `!narg_eval',
1709 define.sps:24.1-24.10: error: DEBUG EXPAND: Macro function !EVAL takes one
1710 argument (not 0).
1711
1712 !EVAL( )
1713
1714 define.sps:8: In the expansion of `!narg_head',
1715 define.sps:25.1-25.10: error: DEBUG EXPAND: Macro function !HEAD takes one
1716 argument (not 0).
1717
1718 !HEAD( )
1719
1720 define.sps:9: In the expansion of `!narg_index',
1721 define.sps:26.1-26.11: error: DEBUG EXPAND: Macro function !INDEX takes two
1722 arguments (not 0).
1723
1724 !INDEX( )
1725
1726 define.sps:10: In the expansion of `!narg_length',
1727 define.sps:27.1-27.12: error: DEBUG EXPAND: Macro function !LENGTH takes one
1728 argument (not 0).
1729
1730 !LENGTH( )
1731
1732 ( )
1733
1734 define.sps:12: In the expansion of `!narg_quote',
1735 define.sps:29.1-29.11: error: DEBUG EXPAND: Macro function !QUOTE takes one
1736 argument (not 0).
1737
1738 !QUOTE( )
1739
1740 define.sps:13: In the expansion of `!narg_substr',
1741 define.sps:30.1-30.12: error: DEBUG EXPAND: Macro function !SUBSTR takes two or
1742 three arguments (not 0).
1743
1744 !SUBSTR( )
1745
1746 define.sps:14: In the expansion of `!narg_tail',
1747 define.sps:31.1-31.10: error: DEBUG EXPAND: Macro function !TAIL takes one
1748 argument (not 0).
1749
1750 !TAIL( )
1751
1752 define.sps:15: In the expansion of `!narg_unquote',
1753 define.sps:32.1-32.13: error: DEBUG EXPAND: Macro function !UNQUOTE takes one
1754 argument (not 0).
1755
1756 !UNQUOTE( )
1757
1758 define.sps:16: In the expansion of `!narg_upcase',
1759 define.sps:33.1-33.12: error: DEBUG EXPAND: Macro function !UPCASE takes one
1760 argument (not 0).
1761
1762 !UPCASE( )
1763 ])
1764 AT_CLEANUP
1765
1766 AT_SETUP([specific macro function syntax errors])
1767 AT_DATA([define.sps], [dnl
1768 DEFINE !a() !BLANKS(x). !ENDDEFINE.
1769 DEFINE !b() !SUBSTR(x, y). !ENDDEFINE.
1770 DEFINE !c() !SUBSTR(x, 1, z). !ENDDEFINE.
1771 DEBUG EXPAND.
1772 !a.
1773 !b.
1774 !c.
1775 ])
1776 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1777 define.sps:1: In the expansion of `!a',
1778 define.sps:5.1-5.2: error: DEBUG EXPAND: Argument to !BLANKS must be non-
1779 negative integer (not "x").
1780
1781 !BLANKS(x).
1782
1783 define.sps:2: In the expansion of `!b',
1784 define.sps:6.1-6.2: error: DEBUG EXPAND: Second argument of !SUBSTR must be
1785 positive integer (not "y").
1786
1787 !SUBSTR(x, y).
1788
1789 define.sps:3: In the expansion of `!c',
1790 define.sps:7.1-7.2: error: DEBUG EXPAND: Third argument of !SUBSTR must be non-
1791 negative integer (not "z").
1792
1793 !SUBSTR(x, 1, z).
1794 ])
1795 AT_CLEANUP
1796
1797 AT_SETUP([macro expression errors])
1798 AT_DATA([define.sps], [dnl
1799 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
1800
1801 DEFINE !b() !DO !x = x. !ENDDEFINE.
1802 DEFINE !c() !LET !x = (). !ENDDEFINE.
1803 DEBUG EXPAND.
1804 !a.
1805 !b.
1806 !c.
1807 ])
1808 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1809 define.sps:1-2: At `.' in the expansion of `!a',
1810 define.sps:5.1-5.2: error: DEBUG EXPAND: Expecting ')' in macro expression.
1811
1812 !LET !x = (1.
1813
1814 At `x' in the expansion of `!DO',
1815 define.sps:2: inside the expansion of `!b',
1816 define.sps:6.1-6.2: error: DEBUG EXPAND: Macro expression must evaluate to a
1817 number (not "x").
1818
1819 !DO !x = x.
1820
1821 define.sps:3: At `)' in the expansion of `!c',
1822 define.sps:7.1-7.2: error: DEBUG EXPAND: Expecting literal or function
1823 invocation in macro expression.
1824
1825 !LET !x = ( ).
1826 ])
1827 AT_CLEANUP
1828
1829 AT_SETUP([macro !IF errors])
1830 AT_KEYWORDS([IF])
1831 AT_DATA([define.sps], [dnl
1832 DEFINE !a() !IF 1 !ENDDEFINE.
1833 DEFINE !b() !IF 1 !THEN !ENDDEFINE.
1834 DEFINE !c() !IF 1 !THEN !ELSE !ENDDEFINE.
1835 DEBUG EXPAND.
1836 !a.
1837 !b.
1838 !c.
1839 ])
1840 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1841 define.sps:1: In the expansion of `!a',
1842 define.sps:5.1-5.2: error: DEBUG EXPAND: !THEN expected in macro !IF construct.
1843
1844 !IF 1
1845
1846 define.sps:2: In the expansion of `!b',
1847 define.sps:6.1-6.2: error: DEBUG EXPAND: !ELSE or !IFEND expected in macro !IF
1848 construct.
1849
1850 !IF 1 !THEN
1851
1852 define.sps:3: In the expansion of `!c',
1853 define.sps:7.1-7.2: error: DEBUG EXPAND: !IFEND expected in macro !IF
1854 construct.
1855
1856 !IF 1 !THEN !ELSE
1857 ])
1858 AT_CLEANUP
1859
1860 AT_SETUP([macro !LET errors])
1861 AT_KEYWORDS([LET])
1862 AT_DATA([define.sps], [dnl
1863 DEFINE !a() !LET !ENDDEFINE.
1864 DEFINE !b() !LET 0 !ENDDEFINE.
1865 DEFINE !c() !LET !x !ENDDEFINE.
1866 DEFINE !d() !LET !x y !ENDDEFINE.
1867 DEBUG EXPAND.
1868 !a.
1869 !b.
1870 !c.
1871 !d.
1872 ])
1873 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1874 define.sps:1: In the expansion of `!a',
1875 define.sps:6.1-6.2: error: DEBUG EXPAND: Expected macro variable name following
1876 !LET.
1877
1878 !LET
1879
1880 define.sps:2: At `0' in the expansion of `!b',
1881 define.sps:7.1-7.2: error: DEBUG EXPAND: Expected macro variable name following
1882 !LET.
1883
1884 !LET 0
1885
1886 define.sps:3: In the expansion of `!c',
1887 define.sps:8.1-8.2: error: DEBUG EXPAND: Expected `=' following !LET.
1888
1889 !LET !x
1890
1891 define.sps:4: At `y' in the expansion of `!d',
1892 define.sps:9.1-9.2: error: DEBUG EXPAND: Expected `=' following !LET.
1893
1894 !LET !x y
1895 ])
1896 AT_CLEANUP
1897
1898 AT_SETUP([macro !DO errors])
1899 AT_KEYWORDS([DO])
1900 AT_DATA([define.sps], [dnl
1901 DEFINE !a() !DO !ENDDEFINE.
1902 DEFINE !b() !DO 0 !ENDDEFINE.
1903 DEFINE !c() !DO !x !ENDDEFINE.
1904 DEFINE !d() !DO !x !in (x) !ENDDEFINE.
1905 DEFINE !e() !DO !x = x. !ENDDEFINE.
1906 DEFINE !f() !DO !x = 5 x !ENDDEFINE.
1907 DEFINE !g() !DO !x = 5 !TO 6 !BY 0 !ENDDEFINE.
1908 DEFINE !h() !DO !x !ENDDEFINE.
1909 DEFINE !i() !DO !x 0 !ENDDEFINE.
1910 DEFINE !j() !BREAK !ENDDEFINE.
1911 DEBUG EXPAND.
1912 !a.
1913 !b.
1914 !c.
1915 !d.
1916 !e.
1917 !f.
1918 !g.
1919 !h.
1920 !i.
1921 !j.
1922 ])
1923 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1924 define.sps:1: In the expansion of `!a',
1925 define.sps:12.1-12.2: error: DEBUG EXPAND: Expected macro variable name
1926 following !DO.
1927
1928 !DO
1929
1930 define.sps:2: At `0' in the expansion of `!b',
1931 define.sps:13.1-13.2: error: DEBUG EXPAND: Expected macro variable name
1932 following !DO.
1933
1934 !DO 0
1935
1936 define.sps:3: In the expansion of `!c',
1937 define.sps:14.1-14.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1938
1939 !DO !x
1940
1941 In the expansion of `!DO',
1942 define.sps:4: inside the expansion of `!d',
1943 define.sps:15.1-15.2: error: DEBUG EXPAND: Missing !DOEND.
1944
1945 !DO !x !in(x)
1946
1947 At `x' in the expansion of `!DO',
1948 define.sps:5: inside the expansion of `!e',
1949 define.sps:16.1-16.2: error: DEBUG EXPAND: Macro expression must evaluate to a
1950 number (not "x").
1951
1952 !DO !x = x.
1953
1954 At `x' in the expansion of `!DO',
1955 define.sps:6: inside the expansion of `!f',
1956 define.sps:17.1-17.2: error: DEBUG EXPAND: Expected !TO in numerical !DO loop.
1957
1958 !DO !x = 5 x
1959
1960 In the expansion of `!DO',
1961 define.sps:7: inside the expansion of `!g',
1962 define.sps:18.1-18.2: error: DEBUG EXPAND: !BY value cannot be zero.
1963
1964 !DO !x = 5 !TO 6 !BY 0
1965
1966 define.sps:8: In the expansion of `!h',
1967 define.sps:19.1-19.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1968
1969 !DO !x
1970
1971 define.sps:9: At `0' in the expansion of `!i',
1972 define.sps:20.1-20.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1973
1974 !DO !x 0
1975
1976 define.sps:10: At `!BREAK' in the expansion of `!j',
1977 define.sps:21.1-21.2: error: DEBUG EXPAND: !BREAK outside !DO.
1978
1979 ])
1980 AT_CLEANUP
1981
1982 AT_SETUP([macros in comments])
1983 AT_KEYWORDS([macro])
1984 AT_DATA([define.sps], [dnl
1985 DEFINE !macro() x y z !ENDDEFINE.
1986 /* !macro.
1987 *!macro.
1988 DEBUG EXPAND.
1989 !macro.
1990 ])
1991 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1992 x y z
1993 ])
1994 AT_CLEANUP
1995
1996 AT_SETUP([DEFINE syntax errors])
1997 AT_KEYWORDS([macro])
1998 AT_DATA([define.sps], [dnl
1999 DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2000 DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2001 DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2002 DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2003 DEFINE 0() !ENDDEFINE.
2004 DEFINE x y () !ENDDEFINE.
2005 DEFINE !macro(1) !ENDDEFINE.
2006 DEFINE !macro(x 2) !ENDDEFINE.
2007 DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2008 DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2009 DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2010 DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2011 DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2012 DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2013 DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2014 DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2015 DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2016 DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2017 DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2018 DEFINE !macro(x=!WTF) !ENDDEFINE.
2019 DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2020 DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2021 DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2022 DEFINE !macro()
2023 ])
2024 AT_CHECK([pspp define.sps], [1], [dnl
2025 define.sps:1.36-1.40: error: DEFINE: Syntax error at `'x y'': String must
2026 contain exactly one token.
2027
2028 define.sps:2.40-2.46: error: DEFINE: Syntax error at `!TOKENS': Positional
2029 parameters must precede keyword parameters.
2030
2031 define.sps:3.15-3.16: error: DEFINE: Syntax error at `!a': Keyword macro
2032 parameter must be named in definition without "!" prefix.
2033
2034 define.sps:4.15-4.16: error: DEFINE: Syntax error at `do': Cannot use macro
2035 keyword "do" as an argument name.
2036
2037 define.sps:5.8: error: DEFINE: Syntax error at `0': expecting identifier.
2038
2039 define.sps:6.10: error: DEFINE: Syntax error at `y': expecting `@{:@'.
2040
2041 define.sps:7.15: error: DEFINE: Syntax error at `1': expecting identifier.
2042
2043 define.sps:8.17: error: DEFINE: Syntax error at `2': expecting !TOKENS, !
2044 CHAREND, !ENCLOSE, or !CMDEND.
2045
2046 define.sps:9.26: error: DEFINE: Syntax error at `3': expecting `@{:@'.
2047
2048 define.sps:10.25: error: DEFINE: Syntax error at `4': expecting `('.
2049
2050 define.sps:11.25: error: DEFINE: Syntax error at `x': Expected positive integer
2051 for !TOKENS.
2052
2053 define.sps:12.27: error: DEFINE: Syntax error at `5': expecting `)'.
2054
2055 define.sps:13.26: error: DEFINE: Syntax error at `6': expecting `('.
2056
2057 define.sps:14.30: error: DEFINE: Syntax error at `y': expecting `,'.
2058
2059 define.sps:15.30: error: DEFINE: Syntax error at `y': expecting string.
2060
2061 define.sps:16.34: error: DEFINE: Syntax error at `z': expecting `)'.
2062
2063 define.sps:17.26: error: DEFINE: Syntax error at `7': expecting `('.
2064
2065 define.sps:18.26: error: DEFINE: Syntax error at `8': expecting string.
2066
2067 define.sps:19.30: error: DEFINE: Syntax error at `9': expecting `)'.
2068
2069 define.sps:20.17-20.20: error: DEFINE: Syntax error at `!WTF': expecting !
2070 TOKENS, !CHAREND, !ENCLOSE, or !CMDEND.
2071
2072 define.sps:21.28: error: DEFINE: Syntax error at `x': expecting `/'.
2073
2074 define.sps:22.36: error: DEFINE: Syntax error at `(': !DEFAULT is allowed only
2075 once per argument.
2076
2077 define.sps:23.35: error: DEFINE: Syntax error at `)': Only one of !TOKENS, !
2078 CHAREND, !ENCLOSE, or !CMDEND is allowed.
2079
2080 define.sps:25.1: error: DEFINE: Syntax error at end of command: Expecting macro
2081 body or !ENDDEFINE.
2082 ])
2083 AT_CLEANUP
2084
2085 AT_SETUP([macro expansion with token merging])
2086 AT_DATA([define.sps], [dnl
2087 DEFINE !foo() "foo" !ENDDEFINE.
2088 DEFINE !bar() "bar" !ENDDEFINE.
2089 DEFINE !plus() + !ENDDEFINE.
2090 DEFINE !minus() - !ENDDEFINE.
2091 DEFINE !one() 1 !ENDDEFINE.
2092 ECHO "foo" + "bar".
2093 ECHO !foo.
2094 ECHO !bar.
2095 ECHO !foo + "quux".
2096 ECHO "baz" + !bar.
2097 ECHO !foo + !bar.
2098 ECHO !foo !plus !bar.
2099 ECHO "two" "strings".
2100 N OF CASES -/**/1.
2101 N OF CASES !minus 1.
2102 N OF CASES - !one.
2103 N OF CASES !minus !one.
2104 ])
2105 AT_CHECK([pspp define.sps], [1], [dnl
2106 foobar
2107
2108 foo
2109
2110 bar
2111
2112 fooquux
2113
2114 bazbar
2115
2116 foobar
2117
2118 foobar
2119
2120 two
2121
2122 define.sps:13.12-13.20: error: ECHO: Syntax error at `"strings"': expecting end
2123 of command.
2124
2125 define.sps:14.12-14.17: error: N OF CASES: Syntax error at `-/**/1': Expected
2126 positive integer for N OF CASES.
2127
2128 define.sps:15.12-15.19: error: N OF CASES: Syntax error at `!minus 1': Expected
2129 positive integer for N OF CASES.
2130
2131 define.sps:16.12-16.17: error: N OF CASES: Syntax error at `- !one': Expected
2132 positive integer for N OF CASES.
2133
2134 define.sps:17.12-17.22: error: N OF CASES: Syntax error at `!minus !one':
2135 Expected positive integer for N OF CASES.
2136 ])
2137 AT_CLEANUP
2138
2139 AT_SETUP([one macro calls another])
2140 AT_DATA([define.sps], [dnl
2141 DEFINE !a(!pos !enclose('(',')')) [[!1]] !ENDDEFINE.
2142 DEFINE !b(!pos !enclose('{','}')) !a(x !1 z) !ENDDEFINE.
2143 DEFINE !c(!pos !enclose('{','}')) !let !tmp=!quote(!concat('<',!1,'>')) !a(!tmp) !ENDDEFINE.
2144 DEBUG EXPAND.
2145 !b{y}.
2146 !c{y}.
2147 ])
2148 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
2149 [[x y z]]
2150
2151 [[ < y > ]]
2152 ])
2153 AT_CLEANUP