chiark / gitweb /
tests/filter/extract-doctests: Improve an error message
[subdirmk.git] / tests / filter / extract-doctests
index 707da89fbaec7438902cdf8634075e9cdbdcbb8a..a617b85789df29e9238124914b8720d253daa9c3 100755 (executable)
@@ -1,6 +1,9 @@
 #!/usr/bin/perl -w
-#
-# script for extracting doctests from README
+# subdirmk - script for extracting doctests from README
+#  Copyright 2019 Mark Wooding
+#  Copyright 2019 Ian Jackson
+# SPDX-License-Identifier: LGPL-2.0-or-later
+# There is NO WARRANTY.
 #
 # usage:
 #   expand <README | tests/filter/extract-doctests tests/filter/
@@ -42,9 +45,9 @@ while (<>) {
     next unless m{\=\>} or ($cent and m{ \.\. });
     my $mapop = '=>';
     # adhoc: special case NEWQUOTE here so we recognise things in changequote
-    if (s{^(\s*)(\&\S+|NEWQUOTE\S+|\$)\s+(\=\>|\.\.)\s+(\S+)\s+}{} ||
-       s{^()(\&\:\w+(?: \S+)*)\s{2,}(\=\>)\s{2,}($withspcs)$}{} ||
-        $cent && s{^()($withspcs)\s{2,}(\.\.)\s{2,}($withspcs)$}{}) {
+    if (s{^()(\&\:\w+(?: \S+)*)\s{2,}(\=\>)\s{2,}($withspcs)$}{} ||
+        s{^(\s*)(\&\S+|NEWQUOTE\S+|\$)\s+(\=\>|\.\.)\s+(\S+)\s+}{} ||
+       $cent && s{^()($withspcs)\s{2,}(\.\.)\s{2,}($withspcs)$}{}) {
        # adhoc: expected indented iff in changequote part
        confess if length($1) xor $in_changequote;
        $mapop = $3;
@@ -55,13 +58,13 @@ while (<>) {
            s{^or (\S+)$}{}) {
            $e->{OutTop} = $1 eq 'nothing' ? '' : $1;
        } elsif (# parse: expect other wordish things to be comments
-                m{^(?!or\b)\w{2,} }) {
+                m{^(?!or\b)\(?\w{2,} }) {
        } elsif (# adhoc: slightly special case for $(eval $(call
                 m{^\$\{.*}) {
            $e->{Out} .= ' '.$&;
        } elsif (m/^$/) {
        } else {
-           confess "unk rhs $_ ?";
+           confess "unk rhs $_ (In=\"$e->{In}\" out=\"$e->{Out}\"?";
        }
        $e->{CQ} = $in_changequote;
        # adhoc: rely on this specific section title
@@ -144,7 +147,7 @@ sub writeout ($) {
                      # adhoc: skip &:macro in already-doubling part
                      return 0 if $e->{In} =~ m{^\&\:macro};
                      # adhoc: skip &${ ie eval in already-doubling part
-                     return 0 if $e->{In} =~ m{^\&\$\{};
+                     return 0 if $e->{In} =~ m{^\&\{};
                      return 0 if $e->{CQ};
                      return $e->{DD} || !grep {
                          # If there are two entries with the same In,