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 General 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/>.
17 AT_BANNER([syntax segmentation])
18 m4_define([PSPP_CHECK_SEGMENT],
19 [AT_CAPTURE_FILE([input])
20 for strip in "" "-s"; do
22 '') sed 's/^-//' < expout-base > expout ;; # (
23 -s) sed '/^-/d' < expout-base > expout ;;
25 AT_CHECK([segment-test $1 $strip input], [0], [expout])
26 AT_CHECK([segment-test -1 $strip $1 input], [0], [expout])
27 AT_CHECK([segment-test -0 $strip $1 input])
28 AT_CHECK([segment-test -01 $strip $1 input])
31 AT_SETUP([identifiers])
32 AT_KEYWORDS([segment])
38 grève@<00A0>@Ângstrom@<00A0>@poté
40 @efg @ @@. @#@ !@ @&t@
46 AT_DATA([expout-base], [dnl
97 identifier #12345 space
117 PSPP_CHECK_SEGMENT([-i])
120 AT_SETUP([identifiers that end in '.'])
121 AT_KEYWORDS([segment])
122 AT_DATA([input], [dnl
134 QRSTUV./* end of line comment */
135 qrstuv. /* end of line comment */
136 QrStUv./* end of line comment */ @&t@
137 wxyz./* unterminated end of line comment
138 WXYZ. /* unterminated end of line comment
139 WxYz./* unterminated end of line comment @&t@
141 AT_DATA([expout-base], [dnl
142 identifier abcd. space
147 identifier ABCD. space
152 identifier aBcD. space
184 start_command . space
193 comment /*_end_of_line_comment_*/
198 comment /*_end_of_line_comment_*/
203 comment /*_end_of_line_comment_*/ space
208 comment /*_unterminated_end_of_line_comment
213 comment /*_unterminated_end_of_line_comment
218 comment /*_unterminated_end_of_line_comment_
223 PSPP_CHECK_SEGMENT([-i])
226 AT_SETUP([reserved words])
227 AT_KEYWORDS([segment])
228 AT_DATA([input], [dnl
229 and or not eq ge gt le lt ne all by to with
230 AND OR NOT EQ GE GT LE LT NE ALL BY TO WITH
231 andx orx notx eqx gex gtx lex ltx nex allx byx tox withx
234 AT_DATA([expout-base], [dnl
235 reserved_word and space
236 reserved_word or space
237 reserved_word not space
238 reserved_word eq space
239 reserved_word ge space
240 reserved_word gt space
241 reserved_word le space
242 reserved_word lt space
243 reserved_word ne space
244 reserved_word all space
245 reserved_word by space
246 reserved_word to space
250 reserved_word AND space
251 reserved_word OR space
252 reserved_word NOT space
253 reserved_word EQ space
254 reserved_word GE space
255 reserved_word GT space
256 reserved_word LE space
257 reserved_word LT space
258 reserved_word NE space
259 reserved_word ALL space
260 reserved_word BY space
261 reserved_word TO space
265 identifier andx space
267 identifier notx space
274 identifier allx space
280 identifier and. space
287 PSPP_CHECK_SEGMENT([-i])
290 AT_SETUP([punctuation])
291 AT_KEYWORDS([segment])
292 AT_DATA([input], [dnl
293 ~ & | = >= > <= < ~= <> ( ) , - + * / [[ ]] **
294 ~&|=>=><=<~=<>(),-+*/[[]]**!*
297 AT_DATA([expout-base], [dnl
357 PSPP_CHECK_SEGMENT([-i])
360 AT_SETUP([positive numbers])
361 AT_KEYWORDS([segment])
362 AT_DATA([input], [dnl
364 123. /* comment 1 */ /* comment 2 */
366 5e1 6E-1 7e+1 6E+01 6e-03
367 .3E1 .4e-1 .5E+1 .6e+01 .7E-03
368 1.23e1 45.6E-1 78.9e+1 99.9E+01 11.2e-03
371 AT_DATA([expout-base], [dnl
382 comment /*_comment_1_*/ space
383 comment /*_comment_2_*/
411 number 99.9E+01 space
415 start_command . space
416 expected_exponent 1e space
418 expected_exponent 1e+ space
419 expected_exponent 1e- space
426 PSPP_CHECK_SEGMENT([-i])
429 AT_SETUP([negative numbers])
430 AT_KEYWORDS([segment])
431 AT_DATA([input], [dnl
433 -123. /* comment 1 */ /* comment 2 */
434 -.1 -0.1 -00.1 -00.10
435 -5e1 -6E-1 -7e+1 -6E+01 -6e-03
436 -.3E1 -.4e-1 -.5E+1 -.6e+01 -.7E-03
437 -1.23e1 -45.6E-1 -78.9e+1 -99.9E+01 -11.2e-03
439 -. -1e -e1 -1e+ -1e- -1.
441 AT_DATA([expout-base], [dnl
453 comment /*_comment_1_*/ space
454 comment /*_comment_2_*/
478 number -45.6E-1 space
479 number -78.9e+1 space
480 number -99.9E+01 space
491 expected_exponent -1e space
494 expected_exponent -1e+ space
495 expected_exponent -1e- space
502 PSPP_CHECK_SEGMENT([-i])
507 AT_KEYWORDS([segment])
508 AT_DATA([input], [dnl
510 'Don''t' "Can't" 'Won''t'
511 """quoted""" '"quoted"'
514 "missing double quote
518 + /* comment */ 'string continuation'
519 + /* also a punctuator on blank line
522 AT_DATA([expout-base], [dnl
523 quoted_string 'x' space
524 quoted_string "y" space
528 quoted_string 'Don''t' space
529 quoted_string "Can't" space
530 quoted_string 'Won''t'
533 quoted_string """quoted""" space
534 quoted_string '"quoted"'
537 quoted_string '' space
541 expected_quote 'missing_end_quote
544 expected_quote "missing_double_quote
547 hex_string x"4142" space
551 unicode_string u'fffd' space
552 unicode_string U"041"
555 start_command + space
561 comment /*_comment_*/ space
562 quoted_string 'string_continuation'
566 comment /*_also_a_punctuator_on_blank_line
569 start_command - space
570 quoted_string 'new_command'
575 PSPP_CHECK_SEGMENT([-i])
578 AT_SETUP([@%:@! construct])
579 AT_KEYWORDS([segment])
580 AT_DATA([input], [dnl
585 AT_DATA([expout-base], [dnl
586 shbang #!_/usr/bin/pspp
589 identifier title space
607 PSPP_CHECK_SEGMENT([-i])
610 AT_SETUP([* and COMMENT commands])
611 AT_KEYWORDS([segment])
612 AT_DATA([input], [dnl
613 * Comment commands "don't
614 have to contain valid tokens.
616 ** Check ambiguity with ** token.
619 comment keyword works too.
621 com is ambiguous with COMPUTE.
623 * Comment need not start at left margin.
625 * Comment ends with blank line
630 AT_DATA([expout-base], [dnl
631 comment_command *_Comment_commands_"don't
634 comment_command have_to_contain_valid_tokens
641 comment_command **_Check_ambiguity_with_**_token
645 comment_command ****************
652 comment_command comment_keyword_works_too
656 comment_command COMM_also
662 identifier ambiguous space
663 reserved_word with space
672 comment_command *_Comment_need_not_start_at_left_margin
679 comment_command *_Comment_ends_with_blank_line
685 identifier next space
695 PSPP_CHECK_SEGMENT([-i])
698 AT_SETUP([DOCUMENT command])
699 AT_KEYWORDS([segment])
700 AT_DATA([input], [dnl
708 isn't parsed as tokens
712 AT_DATA([expout-base], [dnl
714 document DOCUMENT_one_line.
721 newline \n (DOCUMENT)
724 newline \n (DOCUMENT)
727 newline \n (DOCUMENT)
729 document ____________line.
736 newline \n (DOCUMENT)
738 document first.paragraph
739 newline \n (DOCUMENT)
741 document isn't_parsed_as_tokens
742 newline \n (DOCUMENT)
745 newline \n (DOCUMENT)
747 document second_paragraph.
754 PSPP_CHECK_SEGMENT([-i])
757 AT_SETUP([FILE LABEL command])
758 AT_KEYWORDS([segment])
759 AT_DATA([input], [dnl
760 FIL label isn't quoted.
764 /**/ lab not quoted here either
767 AT_DATA([expout-base], [dnl
769 identifier label space
770 unquoted_string isn't_quoted
779 quoted_string 'is_quoted'
783 identifier FILE space
790 unquoted_string not_quoted_here_either
798 PSPP_CHECK_SEGMENT([-i])
801 AT_SETUP([BEGIN DATA command])
802 AT_KEYWORDS([segment])
803 AT_DATA([input], [dnl
828 AT_DATA([expout-base], [dnl
829 identifier begin space
842 identifier begin space
868 inline_data 5_6_7_/*_x
874 inline_data end__data
905 identifier begin space
906 identifier data space
911 identifier begin space
912 identifier data space
917 reserved_word not space
923 PSPP_CHECK_SEGMENT([-i])
926 AT_SETUP([DO REPEAT command])
927 AT_KEYWORDS([segment])
928 AT_DATA([input], [dnl
931 do repeat a=1 thru 5.
935 end /* x */ /* y */ repeat print.
943 AT_DATA([expout-base], [dnl
945 identifier repeat space
960 newline \n (DO REPEAT)
962 do_repeat_command __do_repeat_a=1_thru_5.
963 newline \n (DO REPEAT)
965 do_repeat_command another_command.
966 newline \n (DO REPEAT)
968 do_repeat_command second_command
969 newline \n (DO REPEAT)
971 do_repeat_command +_third_command.
972 newline \n (DO REPEAT)
974 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print.
975 newline \n (DO REPEAT)
988 identifier repeat space
993 newline \n (DO REPEAT)
995 do_repeat_command __inner_command.
996 newline \n (DO REPEAT)
1005 PSPP_CHECK_SEGMENT([-i])
1008 AT_SETUP([DO REPEAT command in batch mode])
1009 AT_KEYWORDS([segment])
1010 AT_DATA([input], [dnl
1013 do repeat a=1 thru 5
1017 end /* x */ /* y */ repeat print
1026 AT_DATA([expout-base], [dnl
1028 identifier repeat space
1045 do_repeat_command do_repeat_a=1_thru_5
1046 newline \n (DO REPEAT)
1048 do_repeat_command another_command
1049 newline \n (DO REPEAT)
1051 do_repeat_command second_command
1052 newline \n (DO REPEAT)
1054 do_repeat_command +_third_command
1055 newline \n (DO REPEAT)
1057 do_repeat_command end_/*_x_*/_/*_y_*/_repeat_print
1058 newline \n (DO REPEAT)
1071 identifier repeat space
1078 newline \n (DO REPEAT)
1080 do_repeat_command __inner_command
1081 newline \n (DO REPEAT)
1083 identifier end space
1089 PSPP_CHECK_SEGMENT([-b])
1092 AT_SETUP([DEFINE command - simple])
1093 AT_KEYWORDS([segment])
1094 AT_DATA([input], [dnl
1096 var1 var2 var3 "!enddefine"
1099 AT_DATA([expout-base], [dnl
1100 identifier define space
1107 macro_body var1_var2_var3_"!enddefine"
1116 PSPP_CHECK_SEGMENT([-i])
1119 AT_SETUP([DEFINE command - no newline after parentheses])
1120 AT_KEYWORDS([segment])
1121 AT_DATA([input], [dnl
1122 define !macro1() var1 var2 var3 /* !enddefine
1125 AT_DATA([expout-base], [dnl
1126 identifier define space
1130 macro_body _var1_var2_var3_/*_!enddefine
1139 PSPP_CHECK_SEGMENT([-i])
1142 AT_SETUP([DEFINE command - no newline before !ENDDEFINE])
1143 AT_KEYWORDS([segment ENDDEFINE])
1144 AT_DATA([input], [dnl
1146 var1 var2 var3!enddefine.
1148 AT_DATA([expout-base], [dnl
1149 identifier define space
1156 macro_body var1_var2_var3
1163 PSPP_CHECK_SEGMENT([-i])
1166 AT_SETUP([DEFINE command - all on one line])
1167 AT_KEYWORDS([segment])
1168 AT_DATA([input], [dnl
1169 define !macro1()var1 var2 var3!enddefine.
1171 AT_DATA([expout-base], [dnl
1172 identifier define space
1176 macro_body var1_var2_var3
1183 PSPP_CHECK_SEGMENT([-i])
1186 AT_SETUP([DEFINE command - empty])
1187 AT_KEYWORDS([segment])
1188 AT_DATA([input], [dnl
1192 AT_DATA([expout-base], [dnl
1193 identifier define space
1206 PSPP_CHECK_SEGMENT([-i])
1209 AT_SETUP([DEFINE command - blank lines])
1210 AT_KEYWORDS([segment])
1211 AT_DATA([input], [dnl
1217 AT_DATA([expout-base], [dnl
1218 identifier define space
1237 PSPP_CHECK_SEGMENT([-i])
1240 AT_SETUP([DEFINE command - arguments])
1241 AT_KEYWORDS([segment])
1242 AT_DATA([input], [dnl
1243 define !macro1(a(), b(), c())
1246 AT_DATA([expout-base], [dnl
1247 identifier define space
1271 PSPP_CHECK_SEGMENT([-i])
1274 AT_SETUP([DEFINE command - multiline arguments])
1275 AT_KEYWORDS([segment])
1276 AT_DATA([input], [dnl
1284 AT_DATA([expout-base], [dnl
1285 identifier define space
1320 PSPP_CHECK_SEGMENT([-i])
1323 AT_SETUP([DEFINE command - arguments start on second line])
1324 AT_KEYWORDS([segment])
1325 AT_DATA([input], [dnl
1333 AT_DATA([expout-base], [dnl
1334 identifier define space
1350 macro_body content_1
1353 macro_body content_2
1362 PSPP_CHECK_SEGMENT([-i])
1365 AT_SETUP([DEFINE command - early end of command 1])
1366 AT_KEYWORDS([segment])
1367 AT_DATA([input], [dnl
1371 AT_DATA([expout-base], [dnl
1372 identifier define space
1377 identifier data space
1378 identifier list space
1387 PSPP_CHECK_SEGMENT([-i])
1390 AT_SETUP([DEFINE command - early end of command 2])
1391 AT_KEYWORDS([segment])
1392 AT_DATA([input], [dnl
1397 AT_DATA([expout-base], [dnl
1398 identifier define space
1406 identifier data space
1407 identifier list space
1416 PSPP_CHECK_SEGMENT([-i])
1419 AT_SETUP([DEFINE command - early end of command 3])
1420 AT_KEYWORDS([segment])
1421 AT_DATA([input], [dnl
1426 AT_DATA([expout-base], [dnl
1427 identifier define space
1437 identifier data space
1438 identifier list space
1447 PSPP_CHECK_SEGMENT([-i])
1450 AT_SETUP([DEFINE command - early end of command 4])
1451 AT_KEYWORDS([segment])
1452 AT_DATA([input], [dnl
1453 dnl Notice the command terminator at the end of the DEFINE command,
1454 dnl which should not be there and ends it early.
1458 AT_DATA([expout-base], [dnl
1459 identifier define space
1464 identifier data space
1465 identifier list space
1474 PSPP_CHECK_SEGMENT([-i])
1477 AT_SETUP([DEFINE command - missing !ENDDEFINE])
1478 AT_KEYWORDS([segment])
1479 AT_DATA([input], [dnl
1484 AT_DATA([expout-base], [dnl
1485 identifier define space
1492 macro_body content_line_1
1495 macro_body content_line_2
1496 -newline \n (DEFINE)
1500 PSPP_CHECK_SEGMENT([-i])
1503 AT_SETUP([batch mode])
1504 AT_KEYWORDS([segment])
1505 AT_DATA([input], [dnl
1507 another line of first command
1514 AT_DATA([expout-base], [dnl
1515 identifier first space
1520 identifier another space
1521 identifier line space
1523 identifier first space
1529 identifier second space
1534 identifier third space
1541 identifier fourth space
1547 identifier fifth space
1554 PSPP_CHECK_SEGMENT([-b])
1557 AT_SETUP([auto mode])
1558 AT_KEYWORDS([segment])
1559 AT_DATA([input], [dnl
1561 another line of command
1564 another line of second command
1574 AT_DATA([expout-base], [dnl
1579 identifier another space
1580 identifier line space
1592 identifier another space
1596 identifier another space
1597 identifier line space
1599 identifier second space
1604 identifier data space
1605 identifier list space
1612 identifier aggregate
1616 identifier print space
1621 identifier twostep space
1631 identifier fourth space
1637 identifier fifth space
1644 PSPP_CHECK_SEGMENT([-a])
1647 # This checks for regression against bug #61253. To see the read of
1648 # uninitialized data, run with valgrind. The test will pass either
1649 # way. (The bug report has a more complicated crashing case.)
1650 AT_SETUP([input ends in carriage return])
1652 AT_DATA([expout-base], [dnl