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([redefining a macro])
45 AT_DATA([define.sps], [dnl
46 DEFINE !macro() 0 !ENDDEFINE.
47 DEFINE !macro() 1 !ENDDEFINE.
51 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
56 AT_SETUP([macro expansion - one !TOKENS(1) positional argument])
58 AT_DATA([define.sps], [dnl
59 DEFINE !t1(!positional=!tokens(1)) t1 (!1) !ENDDEFINE.
65 AT_CAPTURE_FILE([define.sps])
66 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
73 note: unexpanded token "b"
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.
83 DEFINE !ce(!positional=!charend('/')) ce (!1) !ENDDEFINE.
84 DEFINE !ce2(!positional=!charend('(')
85 /!positional !charend(')'))
89 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
91 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
92 DEFINE !cmd2(!positional !cmdend
93 /!positional !tokens(1))
97 DEFINE !p(!positional !tokens(1)
98 /!positional !tokens(1)
99 /!positional !tokens(1))
104 !title "!TOKENS(1) argument."
109 !title "!TOKENS(2) argument."
113 !title "!CHAREND argument."
119 !title "Two !CHAREND arguments."
123 !title "!ENCLOSE argument."
128 !title "!CMDEND argument."
133 !title "Three !TOKENS(1) arguments."
137 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
138 "!TOKENS(1) argument."
146 note: unexpanded token "b"
148 "!TOKENS(2) argument."
154 note: unexpanded token "d"
166 "Two !CHAREND arguments."
186 note: unexpanded token "7"
188 "Three !TOKENS(1) arguments."
192 p(1, -2, -3) (1 -2 -3)
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))
210 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
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))
230 !p a1 a2 b1 b2 c1 c2.
238 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
239 (a1 a2, b1 b2, c1 c2)
241 define.sps:8.18: error: DEBUG EXPAND: Reached end of command expecting 1 more
242 token in argument !3 to macro !p.
243 8 | !p a1 a2 b1 b2 c1.
250 define.sps:10.12: error: DEBUG EXPAND: Reached end of command expecting 1 more
251 token in argument !2 to macro !p.
259 define.sps:12.6: error: DEBUG EXPAND: Reached end of command expecting 1 more
260 token in argument !1 to macro !p.
270 AT_SETUP([macro call empty positional !CHAREND arguments])
271 AT_KEYWORDS([CHAREND])
272 AT_DATA([define.sps], [dnl
273 DEFINE !p(!positional !charend(',') !default(x)
274 /!positional !charend(';') !default(y)
275 /!positional !charend(':') !default(z))
288 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
307 AT_SETUP([macro call missing positional !CHAREND arguments])
308 AT_DATA([define.sps], [dnl
309 DEFINE !p(!positional !charend(',') !default(x)
310 /!positional !charend(';') !default(y)
311 /!positional !charend(':') !default(z))
326 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
345 AT_SETUP([macro call incomplete positional !CHAREND arguments])
346 AT_KEYWORDS([CHAREND])
347 AT_DATA([define.sps], [dnl
348 DEFINE !p(!positional !charend(',') !default(x)
349 /!positional !charend(';') !default(y)
350 /!positional !charend(':') !default(z))
362 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
365 define.sps:8.9: error: DEBUG EXPAND: Reached end of command expecting ":" in
366 argument !3 to macro !p.
374 define.sps:10.7: error: DEBUG EXPAND: Reached end of command expecting ";" in
375 argument !2 to macro !p.
383 define.sps:12.5: error: DEBUG EXPAND: Reached end of command expecting "," in
384 argument !1 to macro !p.
394 AT_SETUP([macro call missing positional !ENCLOSE arguments])
395 AT_KEYWORDS([ENCLOSE])
396 AT_DATA([define.sps], [dnl
397 DEFINE !p(!positional !enclose('(',')') !default(x)
398 /!positional !enclose('<','>') !default(y)
399 /!positional !enclose('{','}') !default(z))
408 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
419 AT_SETUP([macro call incomplete positional !ENCLOSE arguments])
420 AT_KEYWORDS([ENCLOSE])
421 AT_DATA([define.sps], [dnl
422 DEFINE !p(!positional !enclose('(',')') !default(x)
423 /!positional !enclose('<','>') !default(y)
424 /!positional !enclose('{','}') !default(z))
439 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
442 define.sps:8.12: error: DEBUG EXPAND: Reached end of command expecting "}" in
443 argument !3 to macro !p.
449 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "}" in
450 argument !3 to macro !p.
458 define.sps:11.9: error: DEBUG EXPAND: Reached end of command expecting ">" in
459 argument !2 to macro !p.
465 define.sps:12.8: error: DEBUG EXPAND: Reached end of command expecting ">" in
466 argument !2 to macro !p.
474 define.sps:14.6: error: DEBUG EXPAND: Reached end of command expecting ")" in
475 argument !1 to macro !p.
481 define.sps:15.5: error: DEBUG EXPAND: Reached end of command expecting ")" in
482 argument !1 to macro !p.
492 AT_SETUP([keyword macro argument name with ! prefix])
493 AT_DATA([define.sps], [dnl
494 DEFINE !macro(!x !TOKENS(1).
496 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
497 "define.sps:1.15-1.16: error: DEFINE: Keyword macro parameter must be named in definition without ""!"" prefix.
498 1 | DEFINE !macro@{:@!x !TOKENS(1).
503 AT_SETUP([reserved macro keyword argument name])
504 AT_DATA([define.sps], [dnl
505 DEFINE !macro(if=!TOKENS(1).
507 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
508 "define.sps:1.15-1.16: error: DEFINE: Cannot use macro keyword ""if"" as an argument name.
509 1 | DEFINE !macro@{:@if=!TOKENS(1).
514 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument])
515 AT_KEYWORDS([TOKENS])
516 AT_DATA([define.sps], [dnl
517 DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.
523 AT_CAPTURE_FILE([define.sps])
524 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
529 note: unexpanded token "y"
535 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument - negative])
536 AT_KEYWORDS([TOKENS])
537 AT_DATA([define.sps], [dnl
538 DEFINE !k(arg1 !TOKENS(1)) k(!arg1) !ENDDEFINE.
543 AT_CAPTURE_FILE([define.sps])
544 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
545 define.sps:3.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
546 argument !arg1 to macro !k.
552 define.sps:4.9: error: DEBUG EXPAND: Reached end of command expecting 1 more
553 token in argument !arg1 to macro !k.
561 AT_SETUP([macro expansion - !CHAREND keyword arguments])
562 AT_KEYWORDS([CHAREND])
563 AT_DATA([define.sps], [dnl
564 DEFINE !k(arg1 = !CHAREND('/')
565 /arg2 = !CHAREND('/'))
574 AT_CAPTURE_FILE([define.sps])
575 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
586 AT_SETUP([macro expansion - !CHAREND keyword arguments - negative])
587 AT_KEYWORDS([CHAREND])
588 AT_DATA([define.sps], [dnl
589 DEFINE !k(arg1 = !CHAREND('/')
590 /arg2 = !CHAREND('/'))
599 AT_CAPTURE_FILE([define.sps])
600 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
601 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
602 argument !arg1 to macro !k.
608 define.sps:7.9: error: DEBUG EXPAND: Reached end of command expecting "/" in
609 argument !arg1 to macro !k.
615 define.sps:8.10: error: DEBUG EXPAND: Reached end of command expecting "/" in
616 argument !arg1 to macro !k.
622 define.sps:9.18: error: DEBUG EXPAND: Reached end of command expecting "/" in
623 argument !arg2 to macro !k.
624 9 | !k arg1=x/ arg2=y.
631 AT_SETUP([macro expansion - !ENCLOSE keyword arguments])
632 AT_KEYWORDS([ENCLOSE])
633 AT_DATA([define.sps], [dnl
634 DEFINE !k(arg1 = !ENCLOSE('(',')')
635 /arg2 = !ENCLOSE('{','}'))
639 !k arg1=(x) arg2={y}.
644 AT_CAPTURE_FILE([define.sps])
645 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
656 AT_SETUP([macro expansion - !ENCLOSE keyword arguments - negative])
657 AT_KEYWORDS([ENCLOSE])
658 AT_DATA([define.sps], [dnl
659 DEFINE !k(arg1 = !ENCLOSE('(',')')
660 /arg2 = !ENCLOSE('{','}'))
673 AT_CAPTURE_FILE([define.sps])
674 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
675 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
676 argument !arg1 to macro !k.
682 define.sps:7.9: error: DEBUG EXPAND: Found `.' while expecting `@{:@' reading
683 argument !arg1 to macro !k.
689 define.sps:8.9: error: DEBUG EXPAND: Found `x' while expecting `@{:@' reading
690 argument !arg1 to macro !k.
696 note: unexpanded token "x"
698 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "@:}@" in
699 argument !arg1 to macro !k.
705 define.sps:10.17: error: DEBUG EXPAND: Found `.' while expecting `=' reading
706 argument !arg2 to macro !k.
707 10 | !k arg1=(x) arg2.
712 define.sps:11.18: error: DEBUG EXPAND: Found `.' while expecting `{' reading
713 argument !arg2 to macro !k.
714 11 | !k arg1=(x) arg2=.
719 define.sps:12.18: error: DEBUG EXPAND: Found `y' while expecting `{' reading
720 argument !arg2 to macro !k.
721 12 | !k arg1=(x) arg2=y.
726 note: unexpanded token "y"
728 define.sps:13.18: error: DEBUG EXPAND: Found `@{:@' while expecting `{' reading
729 argument !arg2 to macro !k.
730 13 | !k arg1=(x) arg2=@{:@y.
735 note: unexpanded token "@{:@"
737 note: unexpanded token "y"
741 dnl Keep this test in sync with the examples for !BLANKS in the manual.
742 AT_SETUP([macro expansion - !BLANKS])
743 AT_KEYWORDS([BLANKS])
744 AT_DATA([define.sps], [dnl
758 AT_CAPTURE_FILE([define.sps])
759 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
771 dnl Keep this test in sync with the examples for !CONCAT in the manual.
772 AT_SETUP([macro expansion - !CONCAT])
773 AT_KEYWORDS([CONCAT])
774 AT_DATA([define.sps], [dnl
788 AT_CAPTURE_FILE([define.sps])
789 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
801 dnl Keep this test in sync with the examples for !EVAL in the manual.
802 AT_SETUP([macro expansion - !EVAL])
804 AT_DATA([define.sps], [dnl
805 DEFINE !vars() a b c !ENDDEFINE.
811 !QUOTE(!EVAL(!vars)).
814 DEFINE !e2(!positional !enclose('(',')'))
824 AT_CAPTURE_FILE([define.sps])
825 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
838 dnl Keep this test in sync with the examples for !HEAD in the manual.
839 AT_SETUP([macro expansion - !HEAD])
841 AT_DATA([define.sps], [dnl
851 AT_CAPTURE_FILE([define.sps])
852 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
860 dnl Keep this test in sync with the examples for !TAIL in the manual.
861 AT_SETUP([macro expansion - !TAIL])
863 AT_DATA([define.sps], [dnl
873 AT_CAPTURE_FILE([define.sps])
874 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
882 dnl Keep this test in sync with the examples for !INDEX in the manual.
883 AT_SETUP([macro expansion - !INDEX])
885 AT_DATA([define.sps], [dnl
889 !INDEX(banana, apple).
890 !INDEX("banana", nan).
891 !INDEX("banana", "nan").
892 !INDEX(!UNQUOTE("banana"), !UNQUOTE("nan")).
897 AT_CAPTURE_FILE([define.sps])
898 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
908 dnl Keep this test in sync with the examples for !LENGTH in the manual.
909 AT_SETUP([macro expansion - !LENGTH])
910 AT_KEYWORDS([LENGTH])
911 AT_DATA([define.sps], [dnl
920 !LENGTH(!UNQUOTE("xyzzy")).
921 !LENGTH(!UNQUOTE("xy""zzy")).
924 DEFINE !la(!positional !enclose('(',')'))
932 AT_CAPTURE_FILE([define.sps])
933 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
951 dnl Keep this test in sync with the examples for !NULL in the manual.
952 AT_SETUP([macro expansion - !NULL])
954 AT_DATA([define.sps], [dnl
962 AT_CAPTURE_FILE([define.sps])
963 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
969 dnl Keep this test in sync with the examples for !QUOTE and !UNQUOTE in the manual.
970 AT_SETUP([macro expansion - !QUOTE and !UNQUOTE])
971 AT_KEYWORDS([QUOTE UNQUOTE])
972 AT_DATA([define.sps], [dnl
973 DEFINE !q(!POS !CMDEND)
986 !QUOTE(!UNQUOTE(123.0)).
987 !QUOTE(!UNQUOTE( 123 )).
988 !QUOTE(!UNQUOTE('a b c')).
989 !QUOTE(!UNQUOTE("a b c")).
990 !QUOTE(!UNQUOTE(!1)).
995 AT_CAPTURE_FILE([define.sps])
996 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1017 dnl Keep this test in sync with the examples for !SUBSTR in the manual.
1018 AT_SETUP([macro expansion - !SUBSTR])
1019 AT_KEYWORDS([SUBSTR])
1020 AT_DATA([define.sps], [dnl
1023 !SUBSTR(banana, 3, 3).
1024 !SUBSTR("banana", 1, 3).
1025 !SUBSTR(!UNQUOTE("banana"), 3).
1026 !SUBSTR("banana", 3, 3).
1027 !SUBSTR(banana, 3, 0).
1028 !SUBSTR(banana, 3, 10).
1029 !SUBSTR(banana, 10, 3).
1034 AT_CAPTURE_FILE([define.sps])
1035 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1036 define.sps:1-10: At `"ba' in the expansion of `!s',dnl "
1038 define.sps:12.1-12.2: error: DEBUG EXPAND: Unterminated string constant.
1053 dnl Keep this test in sync with the examples for !UPCASE in the manual.
1054 AT_SETUP([macro expansion - !UPCASE])
1055 AT_KEYWORDS([UPCASE])
1056 AT_DATA([define.sps], [dnl
1066 AT_CAPTURE_FILE([define.sps])
1067 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1075 dnl !* is implemented separately inside and outside function arguments
1076 dnl so this test makes sure to include both.
1077 AT_SETUP([macro expansion - !*])
1078 AT_DATA([define.sps], [dnl
1079 DEFINE !m(!POSITIONAL !TOKENS(1)
1080 /!POSITIONAL !TOKENS(1))
1091 AT_CAPTURE_FILE([define.sps])
1092 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1093 123 b / 5 / 3 b / '123 b'.
1095 2 3 / 3 / 3 / '2 3'.
1097 '' 'b' / 6 / 'b' / ''''' ''b'''.
1101 AT_SETUP([macro maximum nesting level (MNEST)])
1102 AT_KEYWORDS([MNEST])
1103 AT_DATA([define.sps], [dnl
1109 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1110 "define.sps:1-3: In the expansion of `!macro',
1111 define.sps:1-3: inside the expansion of `!macro',
1112 define.sps:1-3: inside the expansion of `!macro',
1113 define.sps:1-3: inside the expansion of `!macro',
1114 define.sps:1-3: inside the expansion of `!macro',
1115 define.sps:1-3: inside the expansion of `!macro',
1116 define.sps:1-3: inside the expansion of `!macro',
1117 define.sps:1-3: inside the expansion of `!macro',
1118 define.sps:1-3: inside the expansion of `!macro',
1119 define.sps:1-3: inside the expansion of `!macro',
1120 define.sps:1-3: inside the expansion of `!macro',
1121 define.sps:1-3: inside the expansion of `!macro',
1122 define.sps:1-3: inside the expansion of `!macro',
1123 define.sps:1-3: inside the expansion of `!macro',
1124 define.sps:1-3: inside the expansion of `!macro',
1125 define.sps:1-3: inside the expansion of `!macro',
1126 define.sps:1-3: inside the expansion of `!macro',
1127 define.sps:1-3: inside the expansion of `!macro',
1128 define.sps:1-3: inside the expansion of `!macro',
1129 define.sps:1-3: inside the expansion of `!macro',
1130 define.sps:1-3: inside the expansion of `!macro',
1131 define.sps:1-3: inside the expansion of `!macro',
1132 define.sps:1-3: inside the expansion of `!macro',
1133 define.sps:1-3: inside the expansion of `!macro',
1134 define.sps:1-3: inside the expansion of `!macro',
1135 define.sps:1-3: inside the expansion of `!macro',
1136 define.sps:1-3: inside the expansion of `!macro',
1137 define.sps:1-3: inside the expansion of `!macro',
1138 define.sps:1-3: inside the expansion of `!macro',
1139 define.sps:1-3: inside the expansion of `!macro',
1140 define.sps:1-3: inside the expansion of `!macro',
1141 define.sps:1-3: inside the expansion of `!macro',
1142 define.sps:1-3: inside the expansion of `!macro',
1143 define.sps:1-3: inside the expansion of `!macro',
1144 define.sps:1-3: inside the expansion of `!macro',
1145 define.sps:1-3: inside the expansion of `!macro',
1146 define.sps:1-3: inside the expansion of `!macro',
1147 define.sps:1-3: inside the expansion of `!macro',
1148 define.sps:1-3: inside the expansion of `!macro',
1149 define.sps:1-3: inside the expansion of `!macro',
1150 define.sps:1-3: inside the expansion of `!macro',
1151 define.sps:1-3: inside the expansion of `!macro',
1152 define.sps:1-3: inside the expansion of `!macro',
1153 define.sps:1-3: inside the expansion of `!macro',
1154 define.sps:1-3: inside the expansion of `!macro',
1155 define.sps:1-3: inside the expansion of `!macro',
1156 define.sps:1-3: inside the expansion of `!macro',
1157 define.sps:1-3: inside the expansion of `!macro',
1158 define.sps:1-3: inside the expansion of `!macro',
1159 define.sps:1-3: inside the expansion of `!macro',
1160 define.sps:1-3: inside the expansion of `!macro',
1161 define.sps:4.1-4.6: error: DEFINE: Maximum nesting level 50 exceeded. (Use SET MNEST to change the limit.)
1165 "define.sps:4.1-4.6: error: In syntax expanded from `!macro': Syntax error expecting command name.
1171 AT_SETUP([macro !IF condition])
1174 '!eq !ne !lt !gt !le !ge' \
1178 AS_BOX([$operators])
1179 cat > define.sps <<EOF
1180 DEFINE !test(!positional !tokens(1))
1181 !if (!1 $1 1) !then true !else false !ifend
1182 !if (!1 $2 1) !then true !else false !ifend
1183 !if (!1 $3 1) !then true !else false !ifend
1184 !if (!1 $4 1) !then true !else false !ifend
1185 !if (!1 $5 1) !then true !else false !ifend
1186 !if (!1 $6 1) !then true !else false !ifend.
1195 AT_CAPTURE_FILE([define.sps])
1196 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1197 false true true false true false.
1199 true false false false true true.
1201 false true false true false true.
1203 true false false false true true.
1205 false true false true false true.
1210 AT_SETUP([macro !IF condition -- case sensitivity])
1213 '!eq !ne !lt !gt !le !ge' \
1217 AS_BOX([$operators])
1218 cat > define.sps <<EOF
1219 DEFINE !test(!positional !tokens(1))
1220 !if (!1 $1 a) !then true !else false !ifend
1221 !if (!1 $1 A) !then true !else false !ifend
1222 !if (!1 $2 a) !then true !else false !ifend
1223 !if (!1 $2 A) !then true !else false !ifend
1224 !if (!1 $3 a) !then true !else false !ifend
1225 !if (!1 $3 A) !then true !else false !ifend
1226 !if (!1 $4 a) !then true !else false !ifend
1227 !if (!1 $4 A) !then true !else false !ifend
1228 !if (!1 $5 a) !then true !else false !ifend
1229 !if (!1 $5 A) !then true !else false !ifend
1230 !if (!1 $6 a) !then true !else false !ifend
1231 !if (!1 $6 A) !then true !else false !ifend
1232 !if (!1 $1 !null) !then true !else false !ifend
1233 !if (!1 $2 !null) !then true !else false !ifend.
1241 AT_CAPTURE_FILE([define.sps])
1242 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1243 true false false true false false false true true false true true false true.
1245 false true true false true false false false true true false true false true.
1247 false false true true false false true true false false true true false true.
1249 false false true true true false false true true false false true false true.
1254 AT_SETUP([macro !IF condition -- logical operators])
1261 AS_BOX([$operators])
1262 cat > define.sps <<EOF
1263 DEFINE !test_binary(!positional !tokens(1)/!positional !tokens(1))
1264 !if !1 $1 !2 !then true !else false !ifend
1265 !if !1 $2 !2 !then true !else false !ifend.
1268 DEFINE !test_unary(!positional !tokens(1))
1269 !if $3 !1 !then true !else false !ifend.
1273 ((not A) and B) or C
1276 DEFINE !test_prec(!pos !tokens(1)/!pos !tokens(1)/!pos !tokens(1))
1277 !if $3 !1 $1 !2 $2 !3 !then true !else false !ifend
1278 !if $3 (!1 $1 !2) $2 !3 !then true !else false !ifend
1279 !if $3 !1 $1 (!2 $2 !3) !then true !else false !ifend
1289 !test_prec 0 0 0 !test_prec 0 0 1 !test_prec 0 1 0 !test_prec 0 1 1.
1290 !test_prec 1 0 0 !test_prec 1 0 1 !test_prec 1 1 0 !test_prec 1 1 1.
1292 AT_CAPTURE_FILE([define.sps])
1293 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1319 AT_SETUP([macro !LET])
1321 AT_DATA([define.sps], [dnl
1322 DEFINE !macro(!POS !CMDEND)
1323 !LET !v1 = !CONCAT('x',!1,'y')
1324 !LET !v2 = !QUOTE(!v1)
1325 !LET !v3 = (!LENGTH(!1) = 1)
1326 !LET !v4 = (!SUBSTR(!1, 3) = !NULL)
1337 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1355 AT_SETUP([macro indexed !DO])
1356 AT_KEYWORDS([index do])
1357 AT_DATA([define.sps], [dnl
1358 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1360 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1361 !DO !var = !1 !TO !2 !var !DOEND.
1364 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1365 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1369 !title "increasing".
1376 !title "decreasing".
1383 !title "non-integer".
1386 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1417 AT_SETUP([macro !DO invalid variable names])
1418 AT_KEYWORDS([index do])
1419 AT_DATA([define.sps], [dnl
1420 DEFINE !for(x=!TOKENS(1) / y=!TOKENS(1))
1421 !DO !x = !x !TO !y !var !DOEND.
1424 DEFINE !for2(x=!TOKENS(1) / y=!TOKENS(1))
1425 !DO !noexpand = !x !TO !y !var !DOEND.
1432 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1433 define.sps:1-3: At `!x' in the expansion of `!for',
1434 define.sps:10.1-10.12: error: DEBUG EXPAND: Cannot use argument name or macro
1435 keyword as !DO variable.
1439 !DO 1 = 1 !TO 5 !var !DOEND.
1441 define.sps:5-7: At `!noexpand' in the expansion of `!for2',
1442 define.sps:11.1-11.13: error: DEBUG EXPAND: Cannot use argument name or macro
1443 keyword as !DO variable.
1447 !DO !noexpand = 1 !TO 5 !var !DOEND.
1451 AT_SETUP([macro indexed !DO reaches MITERATE])
1452 AT_KEYWORDS([index do])
1453 AT_DATA([define.sps], [dnl
1454 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1456 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1457 !DO !var = !1 !TO !2 !var !DOEND.
1460 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1461 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1466 !title "increasing".
1473 !title "decreasing".
1480 !title "non-integer".
1483 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1486 In the expansion of `!DO',
1487 define.sps:3-5: inside the expansion of `!for',
1488 define.sps:14.1-14.8: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1489 number of iterations 3. (Use SET MITERATE to change the limit.)
1495 In the expansion of `!DO',
1496 define.sps:7-9: inside the expansion of `!forby',
1497 define.sps:15.1-15.12: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1498 number of iterations 3. (Use SET MITERATE to change the limit.)
1516 In the expansion of `!DO',
1517 define.sps:7-9: inside the expansion of `!forby',
1518 define.sps:23.1-23.13: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1519 number of iterations 3. (Use SET MITERATE to change the limit.)
1535 AT_SETUP([!BREAK with macro indexed !DO])
1536 AT_KEYWORDS([index do break])
1537 AT_DATA([define.sps], [dnl
1538 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1540 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1541 !DO !var = !1 !TO !2
1557 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1562 AT_SETUP([macro list !DO])
1563 AT_KEYWORDS([index do])
1564 AT_DATA([define.sps], [dnl
1565 DEFINE !for(!POS !CMDEND)
1566 (!DO !i !IN (!1) (!i) !DOEND).
1571 !for 'foo bar baz quux'.
1574 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1577 ( (foo) (bar) (baz) (quux) ).
1583 AT_SETUP([macro list !DO reaches MITERATE])
1584 AT_KEYWORDS([index do])
1585 AT_DATA([define.sps], [dnl
1586 DEFINE !for(!POS !CMDEND)
1587 (!DO !i !IN (!1) (!i) !DOEND).
1593 !for 'foo bar baz quux'.
1596 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1597 In the expansion of `!DO',
1598 define.sps:1-3: inside the expansion of `!for',
1599 define.sps:7.1-7.10: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1600 number of iterations 2. (Use SET MITERATE to change the limit.)
1606 In the expansion of `!DO',
1607 define.sps:1-3: inside the expansion of `!for',
1608 define.sps:8.1-8.23: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1609 number of iterations 2. (Use SET MITERATE to change the limit.)
1610 8 | !for 'foo bar baz quux'.
1611 | ^~~~~~~~~~~~~~~~~~~~~~~
1619 AT_SETUP([!BREAK with macro list !DO])
1620 AT_KEYWORDS([index break do])
1621 AT_DATA([define.sps], [dnl
1622 DEFINE !for(!POS !TOKENS(1) / !POS !CMDEND)
1638 !for baz 'foo bar baz quux'.
1641 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1644 ( (foo), (bar), (baz)x).
1650 AT_SETUP([macro !LET])
1651 AT_DATA([define.sps], [dnl
1652 DEFINE !macro(!pos !enclose('(',')'))
1663 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
1670 AT_SETUP([macro !LET invalid variable names])
1671 AT_DATA([define.sps], [dnl
1672 DEFINE !macro(x=!tokens(1))
1684 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [1], [dnl
1685 "define.sps:1-3: At `!x' in the expansion of `!macro',
1686 define.sps:10.1-10.10: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!x"" as !LET variable.
1692 "define.sps:5-7: At `!do' in the expansion of `!macro2',
1693 define.sps:11.1-11.7: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!do"" as !LET variable.
1697 "define.sps:5-7: At `=' in the expansion of `!macro2',
1698 define.sps:11.1-11.7: error: DEBUG EXPAND: Expected macro variable name following !DO.
1706 AT_SETUP([BEGIN DATA inside a macro])
1707 AT_DATA([define.sps], [dnl
1709 DATA LIST NOTABLE /x 1.
1720 AT_CHECK([pspp define.sps -O format=csv], [0], [dnl
1729 AT_SETUP([TITLE and SUBTITLE with macros])
1730 AT_KEYWORDS([macro])
1731 for command in TITLE SUBTITLE; do
1732 cat >title.sps <<EOF
1733 DEFINE !paste(!POS !TOKENS(1) / !POS !TOKENS(1))
1736 $command prefix !paste foo bar suffix.
1740 title.sps:5: note: SHOW: $command is prefix foobar suffix.
1742 AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
1746 AT_SETUP([error message within macro expansion])
1747 AT_DATA([define.sps], [dnl
1748 DEFINE !vars(!POS !TOKENS(1)) a b C !ENDDEFINE.
1749 DATA LIST NOTABLE /a b 1-2.
1750 COMPUTE x = !vars x.
1752 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1753 "define.sps:3.13-3.19: error: COMPUTE: In syntax expanded from `!vars x': Syntax error expecting end of command.
1754 3 | COMPUTE x = !vars x.
1759 dnl A macro with keyword arguments needs a token of lookahead
1760 dnl to find out whether another keyword is present. Test that
1761 dnl this special case works OK.
1762 AT_SETUP([macro calls in each others' lookahead])
1763 AT_DATA([define.sps], [dnl
1764 DEFINE !k(x=!DEFAULT(0) !TOKENS(1)/y=!DEFAULT(0) !TOKENS(1))
1774 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1786 AT_SETUP([bad token in macro body])
1787 AT_DATA([define.sps], [dnl
1792 AT_CHECK([pspp define.sps], [1], [dnl
1793 define.sps:2.1-2.6: error: DEFINE: String of hex digits has 3 characters, which
1794 is not a multiple of 2.
1800 AT_SETUP([macro name overlaps with macro function name])
1801 dnl !len is short for macro function !LENGTH. PSPP used to
1802 dnl reject the following with "`(' expected following !LENGTH".
1803 dnl Now PSPP only consider macro functions when the name is
1804 dnl followed by '('.
1805 AT_DATA([define.sps], [dnl
1806 DEFINE !len() 5 !ENDDEFINE.
1807 DEFINE !x() !eval(!len) !ENDDEFINE.
1811 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1816 AT_SETUP([generic macro function syntax errors])
1817 AT_DATA([define.sps], [dnl
1820 DEFINE !c() !SUBSTR(1x) !ENDDEFINE.
1821 DEFINE !d() !SUBSTR(1 !ENDDEFINE.
1822 DEFINE !narg_blanks() !BLANKS() !ENDDEFINE.
1823 DEFINE !narg_concat() !CONCAT() !ENDDEFINE.
1824 DEFINE !narg_eval() !EVAL() !ENDDEFINE.
1825 DEFINE !narg_head() !HEAD() !ENDDEFINE.
1826 DEFINE !narg_index() !INDEX() !ENDDEFINE.
1827 DEFINE !narg_length() !LENGTH() !ENDDEFINE.
1828 DEFINE !narg_null() !NULL() !ENDDEFINE.
1829 DEFINE !narg_quote() !QUOTE() !ENDDEFINE.
1830 DEFINE !narg_substr() !SUBSTR() !ENDDEFINE.
1831 DEFINE !narg_tail() !TAIL() !ENDDEFINE.
1832 DEFINE !narg_unquote() !UNQUOTE() !ENDDEFINE.
1833 DEFINE !narg_upcase() !UPCASE() !ENDDEFINE.
1853 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1854 define.sps:3: At `x' in the expansion of `!c',
1855 define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro
1862 define.sps:4: In the expansion of `!d',
1863 define.sps:21.1-21.2: error: DEBUG EXPAND: Missing `@:}@' in call to macro
1870 define.sps:5: In the expansion of `!narg_blanks',
1871 define.sps:22.1-22.12: error: DEBUG EXPAND: Macro function !BLANKS takes one
1878 define.sps:6: In the expansion of `!narg_concat',
1879 define.sps:23.1-23.12: error: DEBUG EXPAND: Macro function !CONCAT needs at
1886 define.sps:7: In the expansion of `!narg_eval',
1887 define.sps:24.1-24.10: error: DEBUG EXPAND: Macro function !EVAL takes one
1894 define.sps:8: In the expansion of `!narg_head',
1895 define.sps:25.1-25.10: error: DEBUG EXPAND: Macro function !HEAD takes one
1902 define.sps:9: In the expansion of `!narg_index',
1903 define.sps:26.1-26.11: error: DEBUG EXPAND: Macro function !INDEX takes two
1910 define.sps:10: In the expansion of `!narg_length',
1911 define.sps:27.1-27.12: error: DEBUG EXPAND: Macro function !LENGTH takes one
1920 define.sps:12: In the expansion of `!narg_quote',
1921 define.sps:29.1-29.11: error: DEBUG EXPAND: Macro function !QUOTE takes one
1928 define.sps:13: In the expansion of `!narg_substr',
1929 define.sps:30.1-30.12: error: DEBUG EXPAND: Macro function !SUBSTR takes two or
1930 three arguments (not 0).
1936 define.sps:14: In the expansion of `!narg_tail',
1937 define.sps:31.1-31.10: error: DEBUG EXPAND: Macro function !TAIL takes one
1944 define.sps:15: In the expansion of `!narg_unquote',
1945 define.sps:32.1-32.13: error: DEBUG EXPAND: Macro function !UNQUOTE takes one
1952 define.sps:16: In the expansion of `!narg_upcase',
1953 define.sps:33.1-33.12: error: DEBUG EXPAND: Macro function !UPCASE takes one
1962 AT_SETUP([specific macro function syntax errors])
1963 AT_DATA([define.sps], [dnl
1964 DEFINE !a() !BLANKS(x). !ENDDEFINE.
1965 DEFINE !b() !SUBSTR(x, y). !ENDDEFINE.
1966 DEFINE !c() !SUBSTR(x, 1, z). !ENDDEFINE.
1972 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1973 define.sps:1: In the expansion of `!a',
1974 define.sps:5.1-5.2: error: DEBUG EXPAND: Argument to !BLANKS must be non-
1975 negative integer (not "x").
1981 define.sps:2: In the expansion of `!b',
1982 define.sps:6.1-6.2: error: DEBUG EXPAND: Second argument of !SUBSTR must be
1983 positive integer (not "y").
1989 define.sps:3: In the expansion of `!c',
1990 define.sps:7.1-7.2: error: DEBUG EXPAND: Third argument of !SUBSTR must be non-
1991 negative integer (not "z").
1999 AT_SETUP([macro expression errors])
2000 AT_DATA([define.sps], [dnl
2001 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
2003 DEFINE !b() !DO !x = x. !ENDDEFINE.
2004 DEFINE !c() !LET !x = (). !ENDDEFINE.
2010 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2011 define.sps:1-2: At `.' in the expansion of `!a',
2012 define.sps:5.1-5.2: error: DEBUG EXPAND: Expecting ')' in macro expression.
2018 At `x' in the expansion of `!DO',
2019 define.sps:2: inside the expansion of `!b',
2020 define.sps:6.1-6.2: error: DEBUG EXPAND: Macro expression must evaluate to a
2027 define.sps:3: At `)' in the expansion of `!c',
2028 define.sps:7.1-7.2: error: DEBUG EXPAND: Expecting literal or function
2029 invocation in macro expression.
2037 AT_SETUP([macro !IF errors])
2039 AT_DATA([define.sps], [dnl
2040 DEFINE !a() !IF 1 !ENDDEFINE.
2041 DEFINE !b() !IF 1 !THEN !ENDDEFINE.
2042 DEFINE !c() !IF 1 !THEN !ELSE !ENDDEFINE.
2048 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2049 define.sps:1: In the expansion of `!a',
2050 define.sps:5.1-5.2: error: DEBUG EXPAND: !THEN expected in macro !IF construct.
2056 define.sps:2: In the expansion of `!b',
2057 define.sps:6.1-6.2: error: DEBUG EXPAND: !ELSE or !IFEND expected in macro !IF
2064 define.sps:3: In the expansion of `!c',
2065 define.sps:7.1-7.2: error: DEBUG EXPAND: !IFEND expected in macro !IF
2074 AT_SETUP([macro !LET errors])
2076 AT_DATA([define.sps], [dnl
2077 DEFINE !a() !LET !ENDDEFINE.
2078 DEFINE !b() !LET 0 !ENDDEFINE.
2079 DEFINE !c() !LET !x !ENDDEFINE.
2080 DEFINE !d() !LET !x y !ENDDEFINE.
2087 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2088 define.sps:1: In the expansion of `!a',
2089 define.sps:6.1-6.2: error: DEBUG EXPAND: Expected macro variable name following
2096 define.sps:2: At `0' in the expansion of `!b',
2097 define.sps:7.1-7.2: error: DEBUG EXPAND: Expected macro variable name following
2104 define.sps:3: In the expansion of `!c',
2105 define.sps:8.1-8.2: error: DEBUG EXPAND: Expected `=' following !LET.
2111 define.sps:4: At `y' in the expansion of `!d',
2112 define.sps:9.1-9.2: error: DEBUG EXPAND: Expected `=' following !LET.
2120 AT_SETUP([macro !DO errors])
2122 AT_DATA([define.sps], [dnl
2123 DEFINE !a() !DO !ENDDEFINE.
2124 DEFINE !b() !DO 0 !ENDDEFINE.
2125 DEFINE !c() !DO !x !ENDDEFINE.
2126 DEFINE !d() !DO !x !in (x) !ENDDEFINE.
2127 DEFINE !e() !DO !x = x. !ENDDEFINE.
2128 DEFINE !f() !DO !x = 5 x !ENDDEFINE.
2129 DEFINE !g() !DO !x = 5 !TO 6 !BY 0 !ENDDEFINE.
2130 DEFINE !h() !DO !x !ENDDEFINE.
2131 DEFINE !i() !DO !x 0 !ENDDEFINE.
2132 DEFINE !j() !BREAK !ENDDEFINE.
2145 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2146 define.sps:1: In the expansion of `!a',
2147 define.sps:12.1-12.2: error: DEBUG EXPAND: Expected macro variable name
2154 define.sps:2: At `0' in the expansion of `!b',
2155 define.sps:13.1-13.2: error: DEBUG EXPAND: Expected macro variable name
2162 define.sps:3: In the expansion of `!c',
2163 define.sps:14.1-14.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2169 In the expansion of `!DO',
2170 define.sps:4: inside the expansion of `!d',
2171 define.sps:15.1-15.2: error: DEBUG EXPAND: Missing !DOEND.
2177 At `x' in the expansion of `!DO',
2178 define.sps:5: inside the expansion of `!e',
2179 define.sps:16.1-16.2: error: DEBUG EXPAND: Macro expression must evaluate to a
2186 At `x' in the expansion of `!DO',
2187 define.sps:6: inside the expansion of `!f',
2188 define.sps:17.1-17.2: error: DEBUG EXPAND: Expected !TO in numerical !DO loop.
2194 In the expansion of `!DO',
2195 define.sps:7: inside the expansion of `!g',
2196 define.sps:18.1-18.2: error: DEBUG EXPAND: !BY value cannot be zero.
2200 !DO !x = 5 !TO 6 !BY 0
2202 define.sps:8: In the expansion of `!h',
2203 define.sps:19.1-19.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2209 define.sps:9: At `0' in the expansion of `!i',
2210 define.sps:20.1-20.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2216 define.sps:10: At `!BREAK' in the expansion of `!j',
2217 define.sps:21.1-21.2: error: DEBUG EXPAND: !BREAK outside !DO.
2224 AT_SETUP([macros in comments])
2225 AT_KEYWORDS([macro])
2226 AT_DATA([define.sps], [dnl
2227 DEFINE !macro() x y z !ENDDEFINE.
2233 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
2238 AT_SETUP([DEFINE syntax errors])
2239 AT_KEYWORDS([macro])
2240 AT_DATA([define.sps], [dnl
2241 DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2242 DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2243 DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2244 DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2245 DEFINE 0() !ENDDEFINE.
2246 DEFINE x y () !ENDDEFINE.
2247 DEFINE !macro(1) !ENDDEFINE.
2248 DEFINE !macro(x 2) !ENDDEFINE.
2249 DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2250 DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2251 DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2252 DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2253 DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2254 DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2255 DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2256 DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2257 DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2258 DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2259 DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2260 DEFINE !macro(x=!WTF) !ENDDEFINE.
2261 DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2262 DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2263 DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2266 AT_CHECK([pspp define.sps], [1], [dnl
2267 define.sps:1.36-1.40: error: DEFINE: String must contain exactly one token.
2268 1 | DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2271 define.sps:2.28-2.38: error: DEFINE: Positional parameters must precede keyword
2273 2 | DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2276 define.sps:2.15: note: DEFINE: Here is a previous keyword parameter.
2277 2 | DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2280 define.sps:3.15-3.16: error: DEFINE: Keyword macro parameter must be named in
2281 definition without "!" prefix.
2282 3 | DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2285 define.sps:4.15-4.16: error: DEFINE: Cannot use macro keyword "do" as an
2287 4 | DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2290 define.sps:5.8: error: DEFINE: Syntax error expecting identifier.
2291 5 | DEFINE 0() !ENDDEFINE.
2294 define.sps:6.10: error: DEFINE: Syntax error expecting `@{:@'.
2295 6 | DEFINE x y () !ENDDEFINE.
2298 define.sps:7.15: error: DEFINE: Syntax error expecting identifier.
2299 7 | DEFINE !macro(1) !ENDDEFINE.
2302 define.sps:8.17: error: DEFINE: Syntax error expecting !TOKENS, !CHAREND, !
2303 ENCLOSE, or !CMDEND.
2304 8 | DEFINE !macro(x 2) !ENDDEFINE.
2307 define.sps:9.26: error: DEFINE: Syntax error expecting `@{:@'.
2308 9 | DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2311 define.sps:10.25: error: DEFINE: Syntax error expecting `@{:@'.
2312 10 | DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2315 define.sps:11.25: error: DEFINE: Syntax error expecting positive integer for !
2317 11 | DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2320 define.sps:12.27: error: DEFINE: Syntax error expecting `@:}@'.
2321 12 | DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2324 define.sps:13.26: error: DEFINE: Syntax error expecting `@{:@'.
2325 13 | DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2328 define.sps:14.30: error: DEFINE: Syntax error expecting `,'.
2329 14 | DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2332 define.sps:15.30: error: DEFINE: Syntax error expecting string.
2333 15 | DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2336 define.sps:16.34: error: DEFINE: Syntax error expecting `@:}@'.
2337 16 | DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2340 define.sps:17.26: error: DEFINE: Syntax error expecting `@{:@'.
2341 17 | DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2344 define.sps:18.26: error: DEFINE: Syntax error expecting string.
2345 18 | DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2348 define.sps:19.30: error: DEFINE: Syntax error expecting `@:}@'.
2349 19 | DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2352 define.sps:20.17-20.20: error: DEFINE: Syntax error expecting !TOKENS, !
2353 CHAREND, !ENCLOSE, or !CMDEND.
2354 20 | DEFINE !macro(x=!WTF) !ENDDEFINE.
2357 define.sps:21.28: error: DEFINE: Syntax error expecting `/'.
2358 21 | DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2361 define.sps:22.28-22.35: error: DEFINE: !DEFAULT is allowed only once per
2363 22 | DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2366 define.sps:23.28-23.34: error: DEFINE: Only one of !TOKENS, !CHAREND, !ENCLOSE,
2367 or !CMDEND is allowed.
2368 23 | DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2371 define.sps:25.1: error: DEFINE: Syntax error expecting macro body or !
2378 AT_SETUP([macro expansion with token merging])
2379 AT_DATA([define.sps], [dnl
2380 DEFINE !foo() "foo" !ENDDEFINE.
2381 DEFINE !bar() "bar" !ENDDEFINE.
2382 DEFINE !plus() + !ENDDEFINE.
2383 DEFINE !minus() - !ENDDEFINE.
2384 DEFINE !one() 1 !ENDDEFINE.
2391 ECHO !foo !plus !bar.
2392 ECHO "two" "strings".
2394 N OF CASES !minus 1.
2396 N OF CASES !minus !one.
2398 AT_CHECK([pspp define.sps], [1], [dnl
2415 define.sps:13.12-13.20: error: ECHO: Syntax error expecting end of command.
2416 13 | ECHO "two" "strings".
2419 define.sps:14.12-14.17: error: N OF CASES: Syntax error expecting positive
2420 integer for N OF CASES.
2421 14 | N OF CASES -/**/1.
2424 define.sps:15.12-15.19: error: N OF CASES: Syntax error expecting positive
2425 integer for N OF CASES.
2426 15 | N OF CASES !minus 1.
2429 define.sps:16.12-16.17: error: N OF CASES: Syntax error expecting positive
2430 integer for N OF CASES.
2431 16 | N OF CASES - !one.
2434 define.sps:17.12-17.22: error: N OF CASES: Syntax error expecting positive
2435 integer for N OF CASES.
2436 17 | N OF CASES !minus !one.
2441 AT_SETUP([one macro calls another])
2442 AT_DATA([define.sps], [dnl
2443 DEFINE !a(!pos !enclose('(',')')) [[!1]] !ENDDEFINE.
2444 DEFINE !b(!pos !enclose('{','}')) !a(x !1 z) !ENDDEFINE.
2445 DEFINE !c(!pos !enclose('{','}')) !let !tmp=!quote(!concat('<',!1,'>')) !a(!tmp) !ENDDEFINE.
2450 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl