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