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 m4_define([PSPP_CHECK_MACRO_EXPANSION],
20 [AT_SETUP([macro expansion - $1])
21 AT_KEYWORDS([m4_bpatsubst([$1], [!], [])])
22 AT_DATA([define.sps], [$2
26 AT_CAPTURE_FILE([define.sps])
29 AT_CHECK([pspp --testing-mode define.sps | sed '/^$/d'], [$6], [expout])
32 AT_SETUP([simple macro expansion])
33 AT_DATA([define.sps], [dnl
41 "a" "b" "c" 'a' 'b' 'c'.
47 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
52 "a" "b" "c" 'a' 'b' 'c'.
57 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) positional argument],
58 [DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.],
65 note: unexpanded token "b"])
67 AT_SETUP([macro expansion with positional arguments])
68 AT_DATA([define.sps], [dnl
69 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
70 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
71 DEFINE !t2(!positional !tokens(2)) t2 (!1) !ENDDEFINE.
73 DEFINE !ce(!positional !charend('/')) ce (!1) !ENDDEFINE.
74 DEFINE !ce2(!positional !charend('(')
75 /!positional !charend(')'))
79 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
81 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
82 DEFINE !cmd2(!positional !cmdend
83 /!positional !tokens(1))
87 DEFINE !p(!positional !tokens(1)
88 /!positional !tokens(1)
89 /!positional !tokens(1))
94 !title "!TOKENS(1) argument."
99 !title "!TOKENS(2) argument."
103 !title "!CHAREND argument."
109 !title "Two !CHAREND arguments."
113 !title "!ENCLOSE argument."
118 !title "!CMDEND argument."
123 !title "Three !TOKENS(1) arguments."
127 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
128 "!TOKENS(1) argument."
136 note: unexpanded token "b"
138 "!TOKENS(2) argument."
144 note: unexpanded token "d"
156 "Two !CHAREND arguments."
176 "Three !TOKENS(1) arguments."
180 p(1, -2, -3) (1 -2 -3)
184 AT_SETUP([macro expansion with positional arguments - negative])
185 AT_DATA([define.sps], [dnl
186 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
187 DEFINE !p(!positional !tokens(1)
188 /!positional !tokens(1)
189 /!positional !tokens(1))
193 DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE.
195 DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE.
197 !title "Too few tokens for !TOKENS."
202 !title "Missing charend delimiter."
205 !title "Missing start delimiter."
208 !title "Missing end delimiter."
211 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
212 "Too few tokens for !TOKENS."
214 define.sps:13: error: DEBUG EXPAND: Unexpected end of command reading
215 argument !3 to macro !p.
217 note: unexpanded token "!p"
219 note: unexpanded token "a"
221 note: unexpanded token "b"
223 define.sps:14: error: DEBUG EXPAND: Unexpected end of command reading
224 argument !2 to macro !p.
226 note: unexpanded token "!p"
228 note: unexpanded token "a"
230 define.sps:15: error: DEBUG EXPAND: Unexpected end of command reading
231 argument !1 to macro !p.
233 note: unexpanded token "!p"
235 "Missing charend delimiter."
237 define.sps:18: error: DEBUG EXPAND: Unexpected end of command reading
238 argument !1 to macro !ce.
240 note: unexpanded token "!ce"
242 note: unexpanded token "a"
244 note: unexpanded token "b"
246 note: unexpanded token "c"
248 "Missing start delimiter."
250 define.sps:21: error: DEBUG EXPAND: Found `a' while expecting `{' reading
251 argument !1 to macro !enc1.
253 note: unexpanded token "!enc1"
255 note: unexpanded token "a"
257 note: unexpanded token "b"
259 note: unexpanded token "c"
261 "Missing end delimiter."
263 define.sps:24: error: DEBUG EXPAND: Unexpected end of command reading
264 argument !1 to macro !enc1.
266 note: unexpanded token "!enc1"
268 note: unexpanded token "{"
270 note: unexpanded token "a"
272 note: unexpanded token "b"
274 note: unexpanded token "c"
278 AT_SETUP([keyword macro argument name with ! prefix])
279 AT_DATA([define.sps], [dnl
280 DEFINE !macro(!x=!TOKENS(1).
282 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
283 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `!x': Keyword macro parameter must be named in definition without ""!"" prefix."
287 AT_SETUP([reserved macro keyword argument name])
288 AT_DATA([define.sps], [dnl
289 DEFINE !macro(if=!TOKENS(1).
291 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
292 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `if': Cannot use macro keyword ""if"" as an argument name."
296 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument],
297 [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
303 note: unexpanded token "y"
306 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument - negative],
307 [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
310 define.sps:3: error: DEBUG EXPAND: Found `.' while expecting `=' reading
311 argument !arg1 to macro !k.
312 note: unexpanded token "!k"
313 note: unexpanded token "arg1"
314 define.sps:4: error: DEBUG EXPAND: Unexpected end of command reading argument !
316 note: unexpanded token "!k"
317 note: unexpanded token "arg1"
318 note: unexpanded token "="], [1])
320 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments], [dnl
321 DEFINE !k(arg1 = !CHAREND('/')
322 /arg2 = !CHAREND('/'))
334 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments - negative], [dnl
335 DEFINE !k(arg1 = !CHAREND('/')
336 /arg2 = !CHAREND('/'))
343 [define.sps:6: error: DEBUG EXPAND: Found `.' while expecting `=' reading
344 argument !arg1 to macro !k.
345 note: unexpanded token "!k"
346 note: unexpanded token "arg1"
347 define.sps:7: error: DEBUG EXPAND: Unexpected end of command reading argument !
349 note: unexpanded token "!k"
350 note: unexpanded token "arg1"
351 note: unexpanded token "="
352 define.sps:8: error: DEBUG EXPAND: Unexpected end of command reading argument !
354 note: unexpanded token "!k"
355 note: unexpanded token "arg1"
356 note: unexpanded token "="
357 note: unexpanded token "x"
358 define.sps:9: error: DEBUG EXPAND: Unexpected end of command reading argument !
360 note: unexpanded token "!k"
361 note: unexpanded token "arg1"
362 note: unexpanded token "="
363 note: unexpanded token "x"
364 note: unexpanded token "/"
365 note: unexpanded token "arg2"
366 note: unexpanded token "="
367 note: unexpanded token "y"])
369 PSPP_CHECK_MACRO_EXPANSION([default keyword arguments],
370 [DEFINE !k(arg1 = !DEFAULT(a b c) !CMDEND) k(!arg1) !ENDDEFINE],
376 dnl Keep this test in sync with the examples for !BLANKS in the manual.
377 PSPP_CHECK_MACRO_EXPANSION([!BLANKS],
398 dnl Keep this test in sync with the examples for !CONCAT in the manual.
399 PSPP_CHECK_MACRO_EXPANSION([!CONCAT],
420 dnl Keep this test in sync with the examples for !EVAL in the manual.
421 PSPP_CHECK_MACRO_EXPANSION([!EVAL],
422 [DEFINE !vars() a b c !ENDDEFINE.
427 !QUOTE(!EVAL(!vars)).
429 DEFINE !e2(!positional !enclose('(',')'))
446 dnl Keep this test in sync with the examples for !HEAD in the manual.
447 PSPP_CHECK_MACRO_EXPANSION([!HEAD],
460 dnl Keep this test in sync with the examples for !TAIL in the manual.
461 PSPP_CHECK_MACRO_EXPANSION([!TAIL],
474 dnl Keep this test in sync with the examples for !INDEX in the manual.
475 PSPP_CHECK_MACRO_EXPANSION([!INDEX],
479 !INDEX(banana, apple).
480 !INDEX("banana", nan).
481 !INDEX("banana", "nan").
482 !INDEX(!UNQUOTE("banana"), !UNQUOTE("nan")).
492 dnl Keep this test in sync with the examples for !LENGTH in the manual.
493 PSPP_CHECK_MACRO_EXPANSION([!LENGTH],
502 !LENGTH(!UNQUOTE("xyzzy")).
503 !LENGTH(!UNQUOTE("xy""zzy")).
506 DEFINE !la(!positional !enclose('(',')'))
525 dnl Keep this test in sync with the examples for !SUBSTR in the manual.
526 PSPP_CHECK_MACRO_EXPANSION([!SUBSTR],
529 !SUBSTR(banana, 3, 3).
530 !SUBSTR("banana", 1, 3).
531 !SUBSTR(!UNQUOTE("banana"), 3).
532 !SUBSTR("banana", 3, 3).
533 !SUBSTR(banana, 3, 0).
534 !SUBSTR(banana, 3, 10).
535 !SUBSTR(banana, 10, 3).
538 [define.sps:1-10: At `"ba' in the expansion of `!s',dnl "
540 define.sps:12: error: DEBUG EXPAND: Unterminated string constant.
550 dnl Keep this test in sync with the examples for !UPCASE in the manual.
551 PSPP_CHECK_MACRO_EXPANSION([!UPCASE],
565 dnl !* is implemented separately inside and outside function arguments
566 dnl so this test makes sure to include both.
567 PSPP_CHECK_MACRO_EXPANSION([!*], [dnl
568 DEFINE !m(!POSITIONAL !TOKENS(1)
569 /!POSITIONAL !TOKENS(1))
578 ], [123 b / 5 / 3 b / '123 b'.
580 '' 'b' / 6 / 'b' / ''''' ''b'''.])
582 AT_SETUP([macro maximum nesting level (MNEST)])
584 AT_DATA([define.sps], [dnl
590 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
591 "define.sps:1-3: In the expansion of `!macro',
592 define.sps:1-3: inside the expansion of `!macro',
593 define.sps:1-3: inside the expansion of `!macro',
594 define.sps:1-3: inside the expansion of `!macro',
595 define.sps:1-3: inside the expansion of `!macro',
596 define.sps:1-3: inside the expansion of `!macro',
597 define.sps:1-3: inside the expansion of `!macro',
598 define.sps:1-3: inside the expansion of `!macro',
599 define.sps:1-3: inside the expansion of `!macro',
600 define.sps:1-3: inside the expansion of `!macro',
601 define.sps:1-3: inside the expansion of `!macro',
602 define.sps:1-3: inside the expansion of `!macro',
603 define.sps:1-3: inside the expansion of `!macro',
604 define.sps:1-3: inside the expansion of `!macro',
605 define.sps:1-3: inside the expansion of `!macro',
606 define.sps:1-3: inside the expansion of `!macro',
607 define.sps:1-3: inside the expansion of `!macro',
608 define.sps:1-3: inside the expansion of `!macro',
609 define.sps:1-3: inside the expansion of `!macro',
610 define.sps:1-3: inside the expansion of `!macro',
611 define.sps:1-3: inside the expansion of `!macro',
612 define.sps:1-3: inside the expansion of `!macro',
613 define.sps:1-3: inside the expansion of `!macro',
614 define.sps:1-3: inside the expansion of `!macro',
615 define.sps:1-3: inside the expansion of `!macro',
616 define.sps:1-3: inside the expansion of `!macro',
617 define.sps:1-3: inside the expansion of `!macro',
618 define.sps:1-3: inside the expansion of `!macro',
619 define.sps:1-3: inside the expansion of `!macro',
620 define.sps:1-3: inside the expansion of `!macro',
621 define.sps:1-3: inside the expansion of `!macro',
622 define.sps:1-3: inside the expansion of `!macro',
623 define.sps:1-3: inside the expansion of `!macro',
624 define.sps:1-3: inside the expansion of `!macro',
625 define.sps:1-3: inside the expansion of `!macro',
626 define.sps:1-3: inside the expansion of `!macro',
627 define.sps:1-3: inside the expansion of `!macro',
628 define.sps:1-3: inside the expansion of `!macro',
629 define.sps:1-3: inside the expansion of `!macro',
630 define.sps:1-3: inside the expansion of `!macro',
631 define.sps:1-3: inside the expansion of `!macro',
632 define.sps:1-3: inside the expansion of `!macro',
633 define.sps:1-3: inside the expansion of `!macro',
634 define.sps:1-3: inside the expansion of `!macro',
635 define.sps:1-3: inside the expansion of `!macro',
636 define.sps:1-3: inside the expansion of `!macro',
637 define.sps:1-3: inside the expansion of `!macro',
638 define.sps:1-3: inside the expansion of `!macro',
639 define.sps:1-3: inside the expansion of `!macro',
640 define.sps:1-3: inside the expansion of `!macro',
641 define.sps:1-3: inside the expansion of `!macro',
642 define.sps:4: error: DEFINE: Maximum nesting level 50 exceeded. (Use SET MNEST to change the limit.)"
644 define.sps:4.1-4.6: error: Syntax error at `!macro' (in expansion of `!macro'): expecting command name.
648 AT_SETUP([macro !IF condition])
651 '!eq !ne !lt !gt !le !ge' \
656 cat > define.sps <<EOF
657 DEFINE !test(!positional !tokens(1))
658 !if (!1 $1 1) !then true !else false !ifend
659 !if (!1 $2 1) !then true !else false !ifend
660 !if (!1 $3 1) !then true !else false !ifend
661 !if (!1 $4 1) !then true !else false !ifend
662 !if (!1 $5 1) !then true !else false !ifend
663 !if (!1 $6 1) !then true !else false !ifend.
672 AT_CAPTURE_FILE([define.sps])
673 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
674 false true true false true false.
676 true false false false true true.
678 false true false true false true.
680 true false false false true true.
682 false true false true false true.
687 AT_SETUP([macro !IF condition -- case sensitivity])
690 '!eq !ne !lt !gt !le !ge' \
695 cat > define.sps <<EOF
696 DEFINE !test(!positional !tokens(1))
697 !if (!1 $1 a) !then true !else false !ifend
698 !if (!1 $1 A) !then true !else false !ifend
699 !if (!1 $2 a) !then true !else false !ifend
700 !if (!1 $2 A) !then true !else false !ifend
701 !if (!1 $3 a) !then true !else false !ifend
702 !if (!1 $3 A) !then true !else false !ifend
703 !if (!1 $4 a) !then true !else false !ifend
704 !if (!1 $4 A) !then true !else false !ifend
705 !if (!1 $5 a) !then true !else false !ifend
706 !if (!1 $5 A) !then true !else false !ifend
707 !if (!1 $6 a) !then true !else false !ifend
708 !if (!1 $6 A) !then true !else false !ifend
709 !if (!1 $1 !null) !then true !else false !ifend
710 !if (!1 $2 !null) !then true !else false !ifend.
718 AT_CAPTURE_FILE([define.sps])
719 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
720 true false false true false false false true true false true true false true.
722 false true true false true false false false true true false true false true.
724 false false true true false false true true false false true true false true.
726 false false true true true false false true true false false true false true.
731 AT_SETUP([macro !IF condition -- logical operators])
739 cat > define.sps <<EOF
740 DEFINE !test_binary(!positional !tokens(1)/!positional !tokens(1))
741 !if !1 $1 !2 !then true !else false !ifend
742 !if !1 $2 !2 !then true !else false !ifend.
745 DEFINE !test_unary(!positional !tokens(1))
746 !if $3 !1 !then true !else false !ifend.
753 DEFINE !test_prec(!pos !tokens(1)/!pos !tokens(1)/!pos !tokens(1))
754 !if $3 !1 $1 !2 $2 !3 !then true !else false !ifend
755 !if $3 (!1 $1 !2) $2 !3 !then true !else false !ifend
756 !if $3 !1 $1 (!2 $2 !3) !then true !else false !ifend
766 !test_prec 0 0 0 !test_prec 0 0 1 !test_prec 0 1 0 !test_prec 0 1 1.
767 !test_prec 1 0 0 !test_prec 1 0 1 !test_prec 1 1 0 !test_prec 1 1 1.
769 AT_CAPTURE_FILE([define.sps])
770 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
796 AT_SETUP([macro !LET])
798 AT_DATA([define.sps], [dnl
799 DEFINE !macro(!POS !CMDEND)
800 !LET !v1 = !CONCAT('x',!1,'y')
801 !LET !v2 = !QUOTE(!v1)
802 !LET !v3 = (!LENGTH(!1) = 1)
803 !LET !v4 = (!SUBSTR(!1, 3) = !NULL)
814 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
832 AT_SETUP([macro indexed !DO])
833 AT_KEYWORDS([index do])
834 AT_DATA([define.sps], [dnl
835 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
837 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
838 !DO !var = !1 !TO !2 !var !DOEND.
841 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
842 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
860 !title "non-integer".
863 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
894 AT_SETUP([macro !DO invalid variable names])
895 AT_KEYWORDS([index do])
896 AT_DATA([define.sps], [dnl
897 DEFINE !for(x=!TOKENS(1) / y=!TOKENS(1))
898 !DO !x = !x !TO !y !var !DOEND.
901 DEFINE !for2(x=!TOKENS(1) / y=!TOKENS(1))
902 !DO !noexpand = !x !TO !y !var !DOEND.
909 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
910 define.sps:1-3: At `!x' in the expansion of `!for',
911 define.sps:10: error: DEBUG EXPAND: Cannot use argument name or macro keyword
914 !DO 1 = 1 !TO 5 !var !DOEND.
916 define.sps:5-7: At `!noexpand' in the expansion of `!for2',
917 define.sps:11: error: DEBUG EXPAND: Cannot use argument name or macro keyword
920 !DO !noexpand = 1 !TO 5 !var !DOEND.
924 AT_SETUP([macro indexed !DO reaches MITERATE])
925 AT_KEYWORDS([index do])
926 AT_DATA([define.sps], [dnl
927 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
929 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
930 !DO !var = !1 !TO !2 !var !DOEND.
933 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
934 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
953 !title "non-integer".
956 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
959 In the expansion of `!DO',
960 define.sps:3-5: inside the expansion of `!for',
961 define.sps:14: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum number
962 of iterations 3. (Use SET MITERATE to change the limit.)
966 In the expansion of `!DO',
967 define.sps:7-9: inside the expansion of `!forby',
968 define.sps:15: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum number
969 of iterations 3. (Use SET MITERATE to change the limit.)
985 In the expansion of `!DO',
986 define.sps:7-9: inside the expansion of `!forby',
987 define.sps:23: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum number
988 of iterations 3. (Use SET MITERATE to change the limit.)
1002 AT_SETUP([!BREAK with macro indexed !DO])
1003 AT_KEYWORDS([index do break])
1004 AT_DATA([define.sps], [dnl
1005 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1007 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1008 !DO !var = !1 !TO !2
1024 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1029 AT_SETUP([macro list !DO])
1030 AT_KEYWORDS([index do])
1031 AT_DATA([define.sps], [dnl
1032 DEFINE !for(!POS !CMDEND)
1033 (!DO !i !IN (!1) (!i) !DOEND).
1038 !for 'foo bar baz quux'.
1041 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1044 ( (foo) (bar) (baz) (quux) ).
1050 AT_SETUP([macro list !DO reaches MITERATE])
1051 AT_KEYWORDS([index do])
1052 AT_DATA([define.sps], [dnl
1053 DEFINE !for(!POS !CMDEND)
1054 (!DO !i !IN (!1) (!i) !DOEND).
1060 !for 'foo bar baz quux'.
1063 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1064 In the expansion of `!DO',
1065 define.sps:1-3: inside the expansion of `!for',
1066 define.sps:7: error: DEBUG EXPAND: !DO loop over list exceeded maximum number
1067 of iterations 2. (Use SET MITERATE to change the limit.)
1071 In the expansion of `!DO',
1072 define.sps:1-3: inside the expansion of `!for',
1073 define.sps:8: error: DEBUG EXPAND: !DO loop over list exceeded maximum number
1074 of iterations 2. (Use SET MITERATE to change the limit.)
1082 AT_SETUP([!BREAK with macro list !DO])
1083 AT_KEYWORDS([index break do])
1084 AT_DATA([define.sps], [dnl
1085 DEFINE !for(!POS !TOKENS(1) / !POS !CMDEND)
1101 !for baz 'foo bar baz quux'.
1104 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1107 ( (foo), (bar), (baz)x).
1113 AT_SETUP([macro !LET])
1114 AT_DATA([define.sps], [dnl
1115 DEFINE !macro(!pos !enclose('(',')'))
1126 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
1133 AT_SETUP([macro !LET invalid variable names])
1134 AT_DATA([define.sps], [dnl
1135 DEFINE !macro(x=!tokens(1))
1147 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [1], [dnl
1148 "define.sps:1-3: At `!x' in the expansion of `!macro',
1149 define.sps:10: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!x"" as !LET variable."
1153 "define.sps:5-7: At `!do' in the expansion of `!macro2',
1154 define.sps:11: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!do"" as !LET variable."
1156 "define.sps:5-7: At `=' in the expansion of `!macro2',
1157 define.sps:11: error: DEBUG EXPAND: Expected macro variable name following !DO."
1163 AT_SETUP([BEGIN DATA inside a macro])
1164 AT_DATA([define.sps], [dnl
1166 DATA LIST NOTABLE /x 1.
1177 AT_CHECK([pspp define.sps -O format=csv], [0], [dnl
1186 AT_SETUP([TITLE and SUBTITLE with macros])
1187 AT_KEYWORDS([macro])
1188 for command in TITLE SUBTITLE; do
1189 cat >title.sps <<EOF
1190 DEFINE !paste(!POS !TOKENS(1) / !POS !TOKENS(1))
1193 $command prefix !paste foo bar suffix.
1197 title.sps:5: note: SHOW: $command is prefix foobar suffix.
1199 AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
1203 AT_SETUP([error message within macro expansion])
1204 AT_DATA([define.sps], [dnl
1205 DEFINE !vars(!POS !TOKENS(1)) a b C !ENDDEFINE.
1206 DATA LIST NOTABLE /a b 1-2.
1207 COMPUTE x = !vars x.
1209 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1210 define.sps:3.13-3.19: error: COMPUTE: Syntax error at `b' (in expansion of `!vars x'): expecting end of command.
1214 dnl A macro with keyword arguments needs a token of lookahead
1215 dnl to find out whether another keyword is present. Test that
1216 dnl this special case works OK.
1217 AT_SETUP([macro calls in each others' lookahead])
1218 AT_DATA([define.sps], [dnl
1219 DEFINE !k(x=!DEFAULT(0) !TOKENS(1)/y=!DEFAULT(0) !TOKENS(1))
1229 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1241 AT_SETUP([bad token in macro body])
1242 AT_DATA([define.sps], [dnl
1247 AT_CHECK([pspp define.sps], [1], [dnl
1248 define.sps:3: error: DEFINE: String of hex digits has 3 characters, which is
1249 not a multiple of 2.
1253 AT_SETUP([generic macro function syntax errors])
1254 AT_DATA([define.sps], [dnl
1255 DEFINE !a() !SUBSTR !ENDDEFINE.
1256 DEFINE !b() !SUBSTR x !ENDDEFINE.
1257 DEFINE !c() !SUBSTR(1,2,3,4) !ENDDEFINE.
1258 DEFINE !d() !SUBSTR(1x) !ENDDEFINE.
1259 DEFINE !e() !SUBSTR(1 !ENDDEFINE.
1268 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1269 define.sps:1: In the expansion of `!a',
1270 define.sps:7: error: DEBUG EXPAND: `(' expected following !SUBSTR.
1274 define.sps:2: At `x' in the expansion of `!b',
1275 define.sps:8: error: DEBUG EXPAND: `(' expected following !SUBSTR.
1279 define.sps:3: At `)' in the expansion of `!c',
1280 define.sps:9: error: DEBUG EXPAND: Wrong number of arguments to macro
1285 define.sps:4: At `x' in the expansion of `!d',
1286 define.sps:10: error: DEBUG EXPAND: `,' or `)' expected in call to macro
1291 define.sps:5: In the expansion of `!e',
1292 define.sps:11: error: DEBUG EXPAND: Missing `)' in call to macro function !
1299 AT_SETUP([specific macro function syntax errors])
1300 AT_DATA([define.sps], [dnl
1301 DEFINE !a() !BLANKS(x). !ENDDEFINE.
1302 DEFINE !b() !SUBSTR(x, y). !ENDDEFINE.
1303 DEFINE !c() !SUBSTR(x, 1, z). !ENDDEFINE.
1309 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1310 define.sps:1: In the expansion of `!a',
1311 define.sps:5: error: DEBUG EXPAND: Argument to !BLANKS must be non-negative
1316 define.sps:2: In the expansion of `!b',
1317 define.sps:6: error: DEBUG EXPAND: Second argument of !SUBSTR must be positive
1322 define.sps:3: In the expansion of `!c',
1323 define.sps:7: error: DEBUG EXPAND: Third argument of !SUBSTR must be non-
1324 negative integer (not "z").
1330 AT_SETUP([macro expression errors])
1331 AT_DATA([define.sps], [dnl
1332 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
1334 DEFINE !b() !DO !x = x. !ENDDEFINE.
1335 DEFINE !c() !LET !x = (). !ENDDEFINE.
1341 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1342 define.sps:1-2: At `.' in the expansion of `!a',
1343 define.sps:5: error: DEBUG EXPAND: Expecting ')' in macro expression.
1347 At `x' in the expansion of `!DO',
1348 define.sps:2: inside the expansion of `!b',
1349 define.sps:6: error: DEBUG EXPAND: Macro expression must evaluate to a number
1354 define.sps:3: At `)' in the expansion of `!c',
1355 define.sps:7: error: DEBUG EXPAND: Expecting literal or function invocation in
1362 AT_SETUP([macro !IF errors])
1364 AT_DATA([define.sps], [dnl
1365 DEFINE !a() !IF 1 !ENDDEFINE.
1366 DEFINE !b() !IF 1 !THEN !ENDDEFINE.
1367 DEFINE !c() !IF 1 !THEN !ELSE !ENDDEFINE.
1373 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1374 define.sps:1: In the expansion of `!a',
1375 define.sps:5: error: DEBUG EXPAND: !THEN expected in macro !IF construct.
1379 define.sps:2: In the expansion of `!b',
1380 define.sps:6: error: DEBUG EXPAND: !ELSE or !IFEND expected in macro !IF
1385 define.sps:3: In the expansion of `!c',
1386 define.sps:7: error: DEBUG EXPAND: !IFEND expected in macro !IF construct.
1392 AT_SETUP([macro !LET errors])
1394 AT_DATA([define.sps], [dnl
1395 DEFINE !a() !LET !ENDDEFINE.
1396 DEFINE !b() !LET 0 !ENDDEFINE.
1397 DEFINE !c() !LET !x !ENDDEFINE.
1398 DEFINE !d() !LET !x y !ENDDEFINE.
1405 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1406 define.sps:1: In the expansion of `!a',
1407 define.sps:6: error: DEBUG EXPAND: Expected macro variable name following !LET.
1411 define.sps:2: At `0' in the expansion of `!b',
1412 define.sps:7: error: DEBUG EXPAND: Expected macro variable name following !LET.
1416 define.sps:3: In the expansion of `!c',
1417 define.sps:8: error: DEBUG EXPAND: Expected `=' following !LET.
1421 define.sps:4: At `y' in the expansion of `!d',
1422 define.sps:9: error: DEBUG EXPAND: Expected `=' following !LET.
1428 AT_SETUP([macro !DO errors])
1430 AT_DATA([define.sps], [dnl
1431 DEFINE !a() !DO !ENDDEFINE.
1432 DEFINE !b() !DO 0 !ENDDEFINE.
1433 DEFINE !c() !DO !x !ENDDEFINE.
1434 DEFINE !d() !DO !x !in (x) !ENDDEFINE.
1435 DEFINE !e() !DO !x = x. !ENDDEFINE.
1436 DEFINE !f() !DO !x = 5 x !ENDDEFINE.
1437 DEFINE !g() !DO !x = 5 !TO 6 !BY 0 !ENDDEFINE.
1438 DEFINE !h() !DO !x !ENDDEFINE.
1439 DEFINE !i() !DO !x 0 !ENDDEFINE.
1440 DEFINE !j() !BREAK !ENDDEFINE.
1453 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1454 define.sps:1: In the expansion of `!a',
1455 define.sps:12: error: DEBUG EXPAND: Expected macro variable name following !DO.
1459 define.sps:2: At `0' in the expansion of `!b',
1460 define.sps:13: error: DEBUG EXPAND: Expected macro variable name following !DO.
1464 define.sps:3: In the expansion of `!c',
1465 define.sps:14: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1469 In the expansion of `!DO',
1470 define.sps:4: inside the expansion of `!d',
1471 define.sps:15: error: DEBUG EXPAND: Missing !DOEND.
1475 At `x' in the expansion of `!DO',
1476 define.sps:5: inside the expansion of `!e',
1477 define.sps:16: error: DEBUG EXPAND: Macro expression must evaluate to a number
1482 At `x' in the expansion of `!DO',
1483 define.sps:6: inside the expansion of `!f',
1484 define.sps:17: error: DEBUG EXPAND: Expected !TO in numerical !DO loop.
1488 In the expansion of `!DO',
1489 define.sps:7: inside the expansion of `!g',
1490 define.sps:18: error: DEBUG EXPAND: !BY value cannot be zero.
1492 !DO !x = 5 !TO 6 !BY 0
1494 define.sps:8: In the expansion of `!h',
1495 define.sps:19: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1499 define.sps:9: At `0' in the expansion of `!i',
1500 define.sps:20: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
1504 define.sps:10: At `!BREAK' in the expansion of `!j',
1505 define.sps:21: error: DEBUG EXPAND: !BREAK outside !DO.
1511 AT_SETUP([macros in comments])
1512 AT_KEYWORDS([macro])
1513 AT_DATA([define.sps], [dnl
1514 DEFINE !macro() x y z !ENDDEFINE.
1520 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1525 AT_SETUP([DEFINE syntax errors])
1526 AT_KEYWORDS([macro])
1527 AT_DATA([define.sps], [dnl
1528 DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
1529 DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
1530 DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
1531 DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
1532 DEFINE 0() !ENDDEFINE.
1533 DEFINE x y () !ENDDEFINE.
1534 DEFINE !macro(1) !ENDDEFINE.
1535 DEFINE !macro(x 2) !ENDDEFINE.
1536 DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
1537 DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
1538 DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
1539 DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
1540 DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
1541 DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
1542 DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
1543 DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
1544 DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
1545 DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
1546 DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
1547 DEFINE !macro(x=!WTF) !ENDDEFINE.
1548 DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
1551 AT_CHECK([pspp define.sps], [1], [dnl
1552 define.sps:1.36-1.40: error: DEFINE: Syntax error at `'x y'': String must
1553 contain exactly one token.
1555 define.sps:2.40-2.46: error: DEFINE: Syntax error at `!TOKENS': Positional
1556 parameters must precede keyword parameters.
1558 define.sps:3.15-3.16: error: DEFINE: Syntax error at `!a': Keyword macro
1559 parameter must be named in definition without "!" prefix.
1561 define.sps:4.15-4.16: error: DEFINE: Syntax error at `do': Cannot use macro
1562 keyword "do" as an argument name.
1564 define.sps:5.8: error: DEFINE: Syntax error at `0': expecting identifier.
1566 define.sps:6.10: error: DEFINE: Syntax error at `y': expecting `@{:@'.
1568 define.sps:7.15: error: DEFINE: Syntax error at `1': expecting identifier.
1570 define.sps:8.17: error: DEFINE: Syntax error at `2': expecting `='.
1572 define.sps:9.26: error: DEFINE: Syntax error at `3': expecting `@{:@'.
1574 define.sps:10.25: error: DEFINE: Syntax error at `4': expecting `('.
1576 define.sps:11.25: error: DEFINE: Syntax error at `x': Expected positive integer
1579 define.sps:12.27: error: DEFINE: Syntax error at `5': expecting `)'.
1581 define.sps:13.26: error: DEFINE: Syntax error at `6': expecting `('.
1583 define.sps:14.30: error: DEFINE: Syntax error at `y': expecting `,'.
1585 define.sps:15.30: error: DEFINE: Syntax error at `y': expecting string.
1587 define.sps:16.34: error: DEFINE: Syntax error at `z': expecting `)'.
1589 define.sps:17.26: error: DEFINE: Syntax error at `7': expecting `('.
1591 define.sps:18.26: error: DEFINE: Syntax error at `8': expecting string.
1593 define.sps:19.30: error: DEFINE: Syntax error at `9': expecting `)'.
1595 define.sps:20.17-20.20: error: DEFINE: Syntax error at `!WTF': expecting !
1596 TOKENS, !CHAREND, !ENCLOSE, or !CMDEND.
1598 define.sps:21.28: error: DEFINE: Syntax error at `x': expecting `/'.
1600 define.sps:23.1: error: DEFINE: Syntax error at end of command: Expecting macro