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.
1741 $command,prefix foobar suffix
1743 AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
1747 AT_SETUP([error message within macro expansion])
1748 AT_DATA([define.sps], [dnl
1749 DEFINE !vars(!POS !TOKENS(1)) a b C !ENDDEFINE.
1750 DATA LIST NOTABLE /a b 1-2.
1751 COMPUTE x = !vars x.
1753 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1754 "define.sps:3.13-3.19: error: COMPUTE: In syntax expanded from `!vars x': Syntax error expecting end of command.
1755 3 | COMPUTE x = !vars x.
1760 dnl A macro with keyword arguments needs a token of lookahead
1761 dnl to find out whether another keyword is present. Test that
1762 dnl this special case works OK.
1763 AT_SETUP([macro calls in each others' lookahead])
1764 AT_DATA([define.sps], [dnl
1765 DEFINE !k(x=!DEFAULT(0) !TOKENS(1)/y=!DEFAULT(0) !TOKENS(1))
1775 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1787 AT_SETUP([bad token in macro body])
1788 AT_DATA([define.sps], [dnl
1793 AT_CHECK([pspp define.sps], [1], [dnl
1794 define.sps:2.1-2.6: error: DEFINE: String of hex digits has 3 characters, which
1795 is not a multiple of 2.
1801 AT_SETUP([macro name overlaps with macro function name])
1802 dnl !len is short for macro function !LENGTH. PSPP used to
1803 dnl reject the following with "`(' expected following !LENGTH".
1804 dnl Now PSPP only consider macro functions when the name is
1805 dnl followed by '('.
1806 AT_DATA([define.sps], [dnl
1807 DEFINE !len() 5 !ENDDEFINE.
1808 DEFINE !x() !eval(!len) !ENDDEFINE.
1812 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1817 AT_SETUP([generic macro function syntax errors])
1818 AT_DATA([define.sps], [dnl
1821 DEFINE !c() !SUBSTR(1x) !ENDDEFINE.
1822 DEFINE !d() !SUBSTR(1 !ENDDEFINE.
1823 DEFINE !narg_blanks() !BLANKS() !ENDDEFINE.
1824 DEFINE !narg_concat() !CONCAT() !ENDDEFINE.
1825 DEFINE !narg_eval() !EVAL() !ENDDEFINE.
1826 DEFINE !narg_head() !HEAD() !ENDDEFINE.
1827 DEFINE !narg_index() !INDEX() !ENDDEFINE.
1828 DEFINE !narg_length() !LENGTH() !ENDDEFINE.
1829 DEFINE !narg_null() !NULL() !ENDDEFINE.
1830 DEFINE !narg_quote() !QUOTE() !ENDDEFINE.
1831 DEFINE !narg_substr() !SUBSTR() !ENDDEFINE.
1832 DEFINE !narg_tail() !TAIL() !ENDDEFINE.
1833 DEFINE !narg_unquote() !UNQUOTE() !ENDDEFINE.
1834 DEFINE !narg_upcase() !UPCASE() !ENDDEFINE.
1854 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1855 define.sps:3: At `x' in the expansion of `!c',
1856 define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro
1863 define.sps:4: In the expansion of `!d',
1864 define.sps:21.1-21.2: error: DEBUG EXPAND: Missing `@:}@' in call to macro
1871 define.sps:5: In the expansion of `!narg_blanks',
1872 define.sps:22.1-22.12: error: DEBUG EXPAND: Macro function !BLANKS takes one
1879 define.sps:6: In the expansion of `!narg_concat',
1880 define.sps:23.1-23.12: error: DEBUG EXPAND: Macro function !CONCAT needs at
1887 define.sps:7: In the expansion of `!narg_eval',
1888 define.sps:24.1-24.10: error: DEBUG EXPAND: Macro function !EVAL takes one
1895 define.sps:8: In the expansion of `!narg_head',
1896 define.sps:25.1-25.10: error: DEBUG EXPAND: Macro function !HEAD takes one
1903 define.sps:9: In the expansion of `!narg_index',
1904 define.sps:26.1-26.11: error: DEBUG EXPAND: Macro function !INDEX takes two
1911 define.sps:10: In the expansion of `!narg_length',
1912 define.sps:27.1-27.12: error: DEBUG EXPAND: Macro function !LENGTH takes one
1921 define.sps:12: In the expansion of `!narg_quote',
1922 define.sps:29.1-29.11: error: DEBUG EXPAND: Macro function !QUOTE takes one
1929 define.sps:13: In the expansion of `!narg_substr',
1930 define.sps:30.1-30.12: error: DEBUG EXPAND: Macro function !SUBSTR takes two or
1931 three arguments (not 0).
1937 define.sps:14: In the expansion of `!narg_tail',
1938 define.sps:31.1-31.10: error: DEBUG EXPAND: Macro function !TAIL takes one
1945 define.sps:15: In the expansion of `!narg_unquote',
1946 define.sps:32.1-32.13: error: DEBUG EXPAND: Macro function !UNQUOTE takes one
1953 define.sps:16: In the expansion of `!narg_upcase',
1954 define.sps:33.1-33.12: error: DEBUG EXPAND: Macro function !UPCASE takes one
1963 AT_SETUP([specific macro function syntax errors])
1964 AT_DATA([define.sps], [dnl
1965 DEFINE !a() !BLANKS(x). !ENDDEFINE.
1966 DEFINE !b() !SUBSTR(x, y). !ENDDEFINE.
1967 DEFINE !c() !SUBSTR(x, 1, z). !ENDDEFINE.
1973 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1974 define.sps:1: In the expansion of `!a',
1975 define.sps:5.1-5.2: error: DEBUG EXPAND: Argument to !BLANKS must be non-
1976 negative integer (not "x").
1982 define.sps:2: In the expansion of `!b',
1983 define.sps:6.1-6.2: error: DEBUG EXPAND: Second argument of !SUBSTR must be
1984 positive integer (not "y").
1990 define.sps:3: In the expansion of `!c',
1991 define.sps:7.1-7.2: error: DEBUG EXPAND: Third argument of !SUBSTR must be non-
1992 negative integer (not "z").
2000 AT_SETUP([macro expression errors])
2001 AT_DATA([define.sps], [dnl
2002 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
2004 DEFINE !b() !DO !x = x. !ENDDEFINE.
2005 DEFINE !c() !LET !x = (). !ENDDEFINE.
2011 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2012 define.sps:1-2: At `.' in the expansion of `!a',
2013 define.sps:5.1-5.2: error: DEBUG EXPAND: Expecting ')' in macro expression.
2019 At `x' in the expansion of `!DO',
2020 define.sps:2: inside the expansion of `!b',
2021 define.sps:6.1-6.2: error: DEBUG EXPAND: Macro expression must evaluate to a
2028 define.sps:3: At `)' in the expansion of `!c',
2029 define.sps:7.1-7.2: error: DEBUG EXPAND: Expecting literal or function
2030 invocation in macro expression.
2038 AT_SETUP([macro !IF errors])
2040 AT_DATA([define.sps], [dnl
2041 DEFINE !a() !IF 1 !ENDDEFINE.
2042 DEFINE !b() !IF 1 !THEN !ENDDEFINE.
2043 DEFINE !c() !IF 1 !THEN !ELSE !ENDDEFINE.
2049 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2050 define.sps:1: In the expansion of `!a',
2051 define.sps:5.1-5.2: error: DEBUG EXPAND: !THEN expected in macro !IF construct.
2057 define.sps:2: In the expansion of `!b',
2058 define.sps:6.1-6.2: error: DEBUG EXPAND: !ELSE or !IFEND expected in macro !IF
2065 define.sps:3: In the expansion of `!c',
2066 define.sps:7.1-7.2: error: DEBUG EXPAND: !IFEND expected in macro !IF
2075 AT_SETUP([macro !LET errors])
2077 AT_DATA([define.sps], [dnl
2078 DEFINE !a() !LET !ENDDEFINE.
2079 DEFINE !b() !LET 0 !ENDDEFINE.
2080 DEFINE !c() !LET !x !ENDDEFINE.
2081 DEFINE !d() !LET !x y !ENDDEFINE.
2088 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2089 define.sps:1: In the expansion of `!a',
2090 define.sps:6.1-6.2: error: DEBUG EXPAND: Expected macro variable name following
2097 define.sps:2: At `0' in the expansion of `!b',
2098 define.sps:7.1-7.2: error: DEBUG EXPAND: Expected macro variable name following
2105 define.sps:3: In the expansion of `!c',
2106 define.sps:8.1-8.2: error: DEBUG EXPAND: Expected `=' following !LET.
2112 define.sps:4: At `y' in the expansion of `!d',
2113 define.sps:9.1-9.2: error: DEBUG EXPAND: Expected `=' following !LET.
2121 AT_SETUP([macro !DO errors])
2123 AT_DATA([define.sps], [dnl
2124 DEFINE !a() !DO !ENDDEFINE.
2125 DEFINE !b() !DO 0 !ENDDEFINE.
2126 DEFINE !c() !DO !x !ENDDEFINE.
2127 DEFINE !d() !DO !x !in (x) !ENDDEFINE.
2128 DEFINE !e() !DO !x = x. !ENDDEFINE.
2129 DEFINE !f() !DO !x = 5 x !ENDDEFINE.
2130 DEFINE !g() !DO !x = 5 !TO 6 !BY 0 !ENDDEFINE.
2131 DEFINE !h() !DO !x !ENDDEFINE.
2132 DEFINE !i() !DO !x 0 !ENDDEFINE.
2133 DEFINE !j() !BREAK !ENDDEFINE.
2146 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
2147 define.sps:1: In the expansion of `!a',
2148 define.sps:12.1-12.2: error: DEBUG EXPAND: Expected macro variable name
2155 define.sps:2: At `0' in the expansion of `!b',
2156 define.sps:13.1-13.2: error: DEBUG EXPAND: Expected macro variable name
2163 define.sps:3: In the expansion of `!c',
2164 define.sps:14.1-14.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2170 In the expansion of `!DO',
2171 define.sps:4: inside the expansion of `!d',
2172 define.sps:15.1-15.2: error: DEBUG EXPAND: Missing !DOEND.
2178 At `x' in the expansion of `!DO',
2179 define.sps:5: inside the expansion of `!e',
2180 define.sps:16.1-16.2: error: DEBUG EXPAND: Macro expression must evaluate to a
2187 At `x' in the expansion of `!DO',
2188 define.sps:6: inside the expansion of `!f',
2189 define.sps:17.1-17.2: error: DEBUG EXPAND: Expected !TO in numerical !DO loop.
2195 In the expansion of `!DO',
2196 define.sps:7: inside the expansion of `!g',
2197 define.sps:18.1-18.2: error: DEBUG EXPAND: !BY value cannot be zero.
2201 !DO !x = 5 !TO 6 !BY 0
2203 define.sps:8: In the expansion of `!h',
2204 define.sps:19.1-19.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2210 define.sps:9: At `0' in the expansion of `!i',
2211 define.sps:20.1-20.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2217 define.sps:10: At `!BREAK' in the expansion of `!j',
2218 define.sps:21.1-21.2: error: DEBUG EXPAND: !BREAK outside !DO.
2225 AT_SETUP([macros in comments])
2226 AT_KEYWORDS([macro])
2227 AT_DATA([define.sps], [dnl
2228 DEFINE !macro() x y z !ENDDEFINE.
2234 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
2239 AT_SETUP([DEFINE syntax errors])
2240 AT_KEYWORDS([macro])
2241 AT_DATA([define.sps], [dnl
2242 DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2243 DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2244 DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2245 DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2246 DEFINE 0() !ENDDEFINE.
2247 DEFINE x y () !ENDDEFINE.
2248 DEFINE !macro(1) !ENDDEFINE.
2249 DEFINE !macro(x 2) !ENDDEFINE.
2250 DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2251 DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2252 DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2253 DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2254 DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2255 DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2256 DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2257 DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2258 DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2259 DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2260 DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2261 DEFINE !macro(x=!WTF) !ENDDEFINE.
2262 DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2263 DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2264 DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2267 AT_CHECK([pspp define.sps], [1], [dnl
2268 define.sps:1.36-1.40: error: DEFINE: String must contain exactly one token.
2269 1 | DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2272 define.sps:2.28-2.38: error: DEFINE: Positional parameters must precede keyword
2274 2 | DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2277 define.sps:2.15: note: DEFINE: Here is a previous keyword parameter.
2278 2 | DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2281 define.sps:3.15-3.16: error: DEFINE: Keyword macro parameter must be named in
2282 definition without "!" prefix.
2283 3 | DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2286 define.sps:4.15-4.16: error: DEFINE: Cannot use macro keyword "do" as an
2288 4 | DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2291 define.sps:5.8: error: DEFINE: Syntax error expecting identifier.
2292 5 | DEFINE 0() !ENDDEFINE.
2295 define.sps:6.10: error: DEFINE: Syntax error expecting `@{:@'.
2296 6 | DEFINE x y () !ENDDEFINE.
2299 define.sps:7.15: error: DEFINE: Syntax error expecting identifier.
2300 7 | DEFINE !macro(1) !ENDDEFINE.
2303 define.sps:8.17: error: DEFINE: Syntax error expecting !TOKENS, !CHAREND, !
2304 ENCLOSE, or !CMDEND.
2305 8 | DEFINE !macro(x 2) !ENDDEFINE.
2308 define.sps:9.26: error: DEFINE: Syntax error expecting `@{:@'.
2309 9 | DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2312 define.sps:10.25: error: DEFINE: Syntax error expecting `@{:@'.
2313 10 | DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2316 define.sps:11.25: error: DEFINE: Syntax error expecting positive integer for !
2318 11 | DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2321 define.sps:12.27: error: DEFINE: Syntax error expecting `@:}@'.
2322 12 | DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2325 define.sps:13.26: error: DEFINE: Syntax error expecting `@{:@'.
2326 13 | DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2329 define.sps:14.30: error: DEFINE: Syntax error expecting `,'.
2330 14 | DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2333 define.sps:15.30: error: DEFINE: Syntax error expecting string.
2334 15 | DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2337 define.sps:16.34: error: DEFINE: Syntax error expecting `@:}@'.
2338 16 | DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2341 define.sps:17.26: error: DEFINE: Syntax error expecting `@{:@'.
2342 17 | DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2345 define.sps:18.26: error: DEFINE: Syntax error expecting string.
2346 18 | DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2349 define.sps:19.30: error: DEFINE: Syntax error expecting `@:}@'.
2350 19 | DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2353 define.sps:20.17-20.20: error: DEFINE: Syntax error expecting !TOKENS, !
2354 CHAREND, !ENCLOSE, or !CMDEND.
2355 20 | DEFINE !macro(x=!WTF) !ENDDEFINE.
2358 define.sps:21.28: error: DEFINE: Syntax error expecting `/'.
2359 21 | DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2362 define.sps:22.28-22.35: error: DEFINE: !DEFAULT is allowed only once per
2364 22 | DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2367 define.sps:23.28-23.34: error: DEFINE: Only one of !TOKENS, !CHAREND, !ENCLOSE,
2368 or !CMDEND is allowed.
2369 23 | DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2372 define.sps:25.1: error: DEFINE: Syntax error expecting macro body or !
2379 AT_SETUP([macro expansion with token merging])
2380 AT_DATA([define.sps], [dnl
2381 DEFINE !foo() "foo" !ENDDEFINE.
2382 DEFINE !bar() "bar" !ENDDEFINE.
2383 DEFINE !plus() + !ENDDEFINE.
2384 DEFINE !minus() - !ENDDEFINE.
2385 DEFINE !one() 1 !ENDDEFINE.
2392 ECHO !foo !plus !bar.
2393 ECHO "two" "strings".
2395 N OF CASES !minus 1.
2397 N OF CASES !minus !one.
2399 AT_CHECK([pspp define.sps], [1], [dnl
2416 define.sps:13.12-13.20: error: ECHO: Syntax error expecting end of command.
2417 13 | ECHO "two" "strings".
2420 define.sps:14.12-14.17: error: N OF CASES: Syntax error expecting positive
2421 integer for N OF CASES.
2422 14 | N OF CASES -/**/1.
2425 define.sps:15.12-15.19: error: N OF CASES: Syntax error expecting positive
2426 integer for N OF CASES.
2427 15 | N OF CASES !minus 1.
2430 define.sps:16.12-16.17: error: N OF CASES: Syntax error expecting positive
2431 integer for N OF CASES.
2432 16 | N OF CASES - !one.
2435 define.sps:17.12-17.22: error: N OF CASES: Syntax error expecting positive
2436 integer for N OF CASES.
2437 17 | N OF CASES !minus !one.
2442 AT_SETUP([one macro calls another])
2443 AT_DATA([define.sps], [dnl
2444 DEFINE !a(!pos !enclose('(',')')) [[!1]] !ENDDEFINE.
2445 DEFINE !b(!pos !enclose('{','}')) !a(x !1 z) !ENDDEFINE.
2446 DEFINE !c(!pos !enclose('{','}')) !let !tmp=!quote(!concat('<',!1,'>')) !a(!tmp) !ENDDEFINE.
2451 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl