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