1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
19 AT_SETUP([simple macro expansion])
20 AT_DATA([define.sps], [dnl
28 "a" "b" "c" 'a' 'b' 'c'.
34 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
39 "a" "b" "c" 'a' 'b' 'c'.
44 AT_SETUP([macro expansion - one !TOKENS(1) positional argument])
46 AT_DATA([define.sps], [dnl
47 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
53 AT_CAPTURE_FILE([define.sps])
54 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
61 note: unexpanded token "b"
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.
71 DEFINE !ce(!positional !charend('/')) ce (!1) !ENDDEFINE.
72 DEFINE !ce2(!positional !charend('(')
73 /!positional !charend(')'))
77 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
79 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
80 DEFINE !cmd2(!positional !cmdend
81 /!positional !tokens(1))
85 DEFINE !p(!positional !tokens(1)
86 /!positional !tokens(1)
87 /!positional !tokens(1))
92 !title "!TOKENS(1) argument."
97 !title "!TOKENS(2) argument."
101 !title "!CHAREND argument."
107 !title "Two !CHAREND arguments."
111 !title "!ENCLOSE argument."
116 !title "!CMDEND argument."
121 !title "Three !TOKENS(1) arguments."
125 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
126 "!TOKENS(1) argument."
134 note: unexpanded token "b"
136 "!TOKENS(2) argument."
142 note: unexpanded token "d"
154 "Two !CHAREND arguments."
174 "Three !TOKENS(1) arguments."
178 p(1, -2, -3) (1 -2 -3)
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))
191 DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE.
193 DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE.
195 !title "Too few tokens for !TOKENS."
200 !title "Missing charend delimiter."
203 !title "Missing start delimiter."
206 !title "Missing end delimiter."
209 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
210 "Too few tokens for !TOKENS."
212 define.sps:13.7: error: DEBUG EXPAND: Unexpected end of command reading
213 argument !3 to macro !p.
215 note: unexpanded token "!p"
217 note: unexpanded token "a"
219 note: unexpanded token "b"
221 define.sps:14.5: error: DEBUG EXPAND: Unexpected end of command reading
222 argument !2 to macro !p.
224 note: unexpanded token "!p"
226 note: unexpanded token "a"
228 define.sps:15.3: error: DEBUG EXPAND: Unexpected end of command reading
229 argument !1 to macro !p.
231 note: unexpanded token "!p"
233 "Missing charend delimiter."
235 define.sps:18.10: error: DEBUG EXPAND: Unexpected end of command reading
236 argument !1 to macro !ce.
238 note: unexpanded token "!ce"
240 note: unexpanded token "a"
242 note: unexpanded token "b"
244 note: unexpanded token "c"
246 "Missing start delimiter."
248 define.sps:21.7: error: DEBUG EXPAND: Found `a' while expecting `{' reading
249 argument !1 to macro !enc1.
251 note: unexpanded token "!enc1"
253 note: unexpanded token "a"
255 note: unexpanded token "b"
257 note: unexpanded token "c"
259 "Missing end delimiter."
261 define.sps:24.12: error: DEBUG EXPAND: Unexpected end of command reading
262 argument !1 to macro !enc1.
264 note: unexpanded token "!enc1"
266 note: unexpanded token "{"
268 note: unexpanded token "a"
270 note: unexpanded token "b"
272 note: unexpanded token "c"
276 AT_SETUP([keyword macro argument name with ! prefix])
277 AT_DATA([define.sps], [dnl
278 DEFINE !macro(!x=!TOKENS(1).
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."
285 AT_SETUP([reserved macro keyword argument name])
286 AT_DATA([define.sps], [dnl
287 DEFINE !macro(if=!TOKENS(1).
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."
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.
303 AT_CAPTURE_FILE([define.sps])
304 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
309 note: unexpanded token "y"
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.
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.
328 note: unexpanded token "!k"
330 note: unexpanded token "arg1"
332 define.sps:4.9: error: DEBUG EXPAND: Unexpected end of command reading argument
335 note: unexpanded token "!k"
337 note: unexpanded token "arg1"
339 note: unexpanded token "="
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('/'))
356 AT_CAPTURE_FILE([define.sps])
357 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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('/'))
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.
386 note: unexpanded token "!k"
388 note: unexpanded token "arg1"
390 define.sps:7.9: error: DEBUG EXPAND: Unexpected end of command reading argument
393 note: unexpanded token "!k"
395 note: unexpanded token "arg1"
397 note: unexpanded token "="
399 define.sps:8.10: error: DEBUG EXPAND: Unexpected end of command reading
400 argument !arg1 to macro !k.
402 note: unexpanded token "!k"
404 note: unexpanded token "arg1"
406 note: unexpanded token "="
408 note: unexpanded token "x"
410 define.sps:9.18: error: DEBUG EXPAND: Unexpected end of command reading
411 argument !arg2 to macro !k.
413 note: unexpanded token "!k"
415 note: unexpanded token "arg1"
417 note: unexpanded token "="
419 note: unexpanded token "x"
421 note: unexpanded token "/"
423 note: unexpanded token "arg2"
425 note: unexpanded token "="
427 note: unexpanded token "y"
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
448 AT_CAPTURE_FILE([define.sps])
449 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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
478 AT_CAPTURE_FILE([define.sps])
479 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
491 dnl Keep this test in sync with the examples for !EVAL in the manual.
492 AT_SETUP([macro expansion - !EVAL])
494 AT_DATA([define.sps], [dnl
495 DEFINE !vars() a b c !ENDDEFINE.
501 !QUOTE(!EVAL(!vars)).
504 DEFINE !e2(!positional !enclose('(',')'))
514 AT_CAPTURE_FILE([define.sps])
515 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
528 dnl Keep this test in sync with the examples for !HEAD in the manual.
529 AT_SETUP([macro expansion - !HEAD])
531 AT_DATA([define.sps], [dnl
541 AT_CAPTURE_FILE([define.sps])
542 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
550 dnl Keep this test in sync with the examples for !TAIL in the manual.
551 AT_SETUP([macro expansion - !TAIL])
553 AT_DATA([define.sps], [dnl
563 AT_CAPTURE_FILE([define.sps])
564 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
572 dnl Keep this test in sync with the examples for !INDEX in the manual.
573 AT_SETUP([macro expansion - !INDEX])
575 AT_DATA([define.sps], [dnl
579 !INDEX(banana, apple).
580 !INDEX("banana", nan).
581 !INDEX("banana", "nan").
582 !INDEX(!UNQUOTE("banana"), !UNQUOTE("nan")).
587 AT_CAPTURE_FILE([define.sps])
588 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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
610 !LENGTH(!UNQUOTE("xyzzy")).
611 !LENGTH(!UNQUOTE("xy""zzy")).
614 DEFINE !la(!positional !enclose('(',')'))
622 AT_CAPTURE_FILE([define.sps])
623 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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
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).
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 "
662 define.sps:12.1-12.2: error: DEBUG EXPAND: Unterminated string constant.
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
688 AT_CAPTURE_FILE([define.sps])
689 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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))
713 AT_CAPTURE_FILE([define.sps])
714 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
715 123 b / 5 / 3 b / '123 b'.
719 '' 'b' / 6 / 'b' / ''''' ''b'''.
723 AT_SETUP([macro maximum nesting level (MNEST)])
725 AT_DATA([define.sps], [dnl
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.)"
785 define.sps:4.1-4.6: error: Syntax error at `!macro' (in expansion of `!macro'): expecting command name.
789 AT_SETUP([macro !IF condition])
792 '!eq !ne !lt !gt !le !ge' \
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.
813 AT_CAPTURE_FILE([define.sps])
814 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
815 false true true false true false.
817 true false false false true true.
819 false true false true false true.
821 true false false false true true.
823 false true false true false true.
828 AT_SETUP([macro !IF condition -- case sensitivity])
831 '!eq !ne !lt !gt !le !ge' \
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.
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.
863 false true true false true false false false true true false true false true.
865 false false true true false false true true false false true true false true.
867 false false true true true false false true true false false true false true.
872 AT_SETUP([macro !IF condition -- logical 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.
886 DEFINE !test_unary(!positional !tokens(1))
887 !if $3 !1 !then true !else false !ifend.
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
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.
910 AT_CAPTURE_FILE([define.sps])
911 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
937 AT_SETUP([macro !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)
955 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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.
978 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
979 !DO !var = !1 !TO !2 !var !DOEND.
982 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
983 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1001 !title "non-integer".
1004 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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.
1042 DEFINE !for2(x=!TOKENS(1) / y=!TOKENS(1))
1043 !DO !noexpand = !x !TO !y !var !DOEND.
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.
1055 !DO 1 = 1 !TO 5 !var !DOEND.
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.
1061 !DO !noexpand = 1 !TO 5 !var !DOEND.
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.
1070 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1071 !DO !var = !1 !TO !2 !var !DOEND.
1074 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1075 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1080 !title "increasing".
1087 !title "decreasing".
1094 !title "non-integer".
1097 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
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.)
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.)
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.)
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.
1148 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1149 !DO !var = !1 !TO !2
1165 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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).
1179 !for 'foo bar baz quux'.
1182 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1185 ( (foo) (bar) (baz) (quux) ).
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).
1201 !for 'foo bar baz quux'.
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.)
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.)
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)
1242 !for baz 'foo bar baz quux'.
1245 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1248 ( (foo), (bar), (baz)x).
1254 AT_SETUP([macro !LET])
1255 AT_DATA([define.sps], [dnl
1256 DEFINE !macro(!pos !enclose('(',')'))
1267 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
1274 AT_SETUP([macro !LET invalid variable names])
1275 AT_DATA([define.sps], [dnl
1276 DEFINE !macro(x=!tokens(1))
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."
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."
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."
1304 AT_SETUP([BEGIN DATA inside a macro])
1305 AT_DATA([define.sps], [dnl
1307 DATA LIST NOTABLE /x 1.
1318 AT_CHECK([pspp define.sps -O format=csv], [0], [dnl
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))
1334 $command prefix !paste foo bar suffix.
1338 title.sps:5: note: SHOW: $command is prefix foobar suffix.
1340 AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
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.
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.
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))
1370 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1382 AT_SETUP([bad token in macro body])
1383 AT_DATA([define.sps], [dnl
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.
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.
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.
1437 define.sps:2: At `x' in the expansion of `!b',
1438 define.sps:19.1-19.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR.
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
1448 define.sps:4: In the expansion of `!d',
1449 define.sps:21.1-21.2: error: DEBUG EXPAND: Missing `@:}@' in call to macro
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
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
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
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
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
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
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
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).
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
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
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
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.
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").
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").
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").
1555 AT_SETUP([macro expression errors])
1556 AT_DATA([define.sps], [dnl
1557 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
1559 DEFINE !b() !DO !x = x. !ENDDEFINE.
1560 DEFINE !c() !LET !x = (). !ENDDEFINE.
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.
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
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.
1587 AT_SETUP([macro !IF errors])
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.
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.
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
1610 define.sps:3: In the expansion of `!c',
1611 define.sps:7.1-7.2: error: DEBUG EXPAND: !IFEND expected in macro !IF
1618 AT_SETUP([macro !LET errors])
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.
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
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
1644 define.sps:3: In the expansion of `!c',
1645 define.sps:8.1-8.2: error: DEBUG EXPAND: Expected `=' following !LET.
1649 define.sps:4: At `y' in the expansion of `!d',
1650 define.sps:9.1-9.2: error: DEBUG EXPAND: Expected `=' following !LET.
1656 AT_SETUP([macro !DO errors])
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.
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
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
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.
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.
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
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.
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.
1722 !DO !x = 5 !TO 6 !BY 0
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.
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.
1734 define.sps:10: At `!BREAK' in the expansion of `!j',
1735 define.sps:21.1-21.2: error: DEBUG EXPAND: !BREAK outside !DO.
1740 AT_SETUP([macros in comments])
1741 AT_KEYWORDS([macro])
1742 AT_DATA([define.sps], [dnl
1743 DEFINE !macro() x y z !ENDDEFINE.
1749 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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.
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.
1786 define.sps:2.40-2.46: error: DEFINE: Syntax error at `!TOKENS': Positional
1787 parameters must precede keyword parameters.
1789 define.sps:3.15-3.16: error: DEFINE: Syntax error at `!a': Keyword macro
1790 parameter must be named in definition without "!" prefix.
1792 define.sps:4.15-4.16: error: DEFINE: Syntax error at `do': Cannot use macro
1793 keyword "do" as an argument name.
1795 define.sps:5.8: error: DEFINE: Syntax error at `0': expecting identifier.
1797 define.sps:6.10: error: DEFINE: Syntax error at `y': expecting `@{:@'.
1799 define.sps:7.15: error: DEFINE: Syntax error at `1': expecting identifier.
1801 define.sps:8.17: error: DEFINE: Syntax error at `2': expecting `='.
1803 define.sps:9.26: error: DEFINE: Syntax error at `3': expecting `@{:@'.
1805 define.sps:10.25: error: DEFINE: Syntax error at `4': expecting `('.
1807 define.sps:11.25: error: DEFINE: Syntax error at `x': Expected positive integer
1810 define.sps:12.27: error: DEFINE: Syntax error at `5': expecting `)'.
1812 define.sps:13.26: error: DEFINE: Syntax error at `6': expecting `('.
1814 define.sps:14.30: error: DEFINE: Syntax error at `y': expecting `,'.
1816 define.sps:15.30: error: DEFINE: Syntax error at `y': expecting string.
1818 define.sps:16.34: error: DEFINE: Syntax error at `z': expecting `)'.
1820 define.sps:17.26: error: DEFINE: Syntax error at `7': expecting `('.
1822 define.sps:18.26: error: DEFINE: Syntax error at `8': expecting string.
1824 define.sps:19.30: error: DEFINE: Syntax error at `9': expecting `)'.
1826 define.sps:20.17-20.20: error: DEFINE: Syntax error at `!WTF': expecting !
1827 TOKENS, !CHAREND, !ENCLOSE, or !CMDEND.
1829 define.sps:21.28: error: DEFINE: Syntax error at `x': expecting `/'.
1831 define.sps:22.36: error: DEFINE: Syntax error at `(': !DEFAULT is allowed only
1834 define.sps:23.35: error: DEFINE: Syntax error at `)': Only one of !TOKENS, !
1835 CHAREND, !ENCLOSE, or !CMDEND is allowed.
1837 define.sps:25.1: error: DEFINE: Syntax error at end of command: Expecting macro
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.
1855 ECHO !foo !plus !bar.
1856 ECHO "two" "strings".
1858 N OF CASES !minus 1.
1860 N OF CASES !minus !one.
1862 AT_CHECK([pspp define.sps], [1], [dnl
1879 define.sps:13.12-13.20: error: ECHO: Syntax error at `"strings"': expecting end
1882 define.sps:14.12-14.17: error: N OF CASES: Syntax error at `-/**/1': Expected
1883 positive integer for N OF CASES.
1885 define.sps:15.12-15.19: error: N OF CASES: Syntax error at `!minus 1': Expected
1886 positive integer for N OF CASES.
1888 define.sps:16.12-16.17: error: N OF CASES: Syntax error at `- !one': Expected
1889 positive integer for N OF CASES.
1891 define.sps:17.12-17.22: error: N OF CASES: Syntax error at `!minus !one':
1892 Expected positive integer for N OF CASES.