From: Jeff King Date: Wed, 08 Aug 2018 22:50:12 GMT Subject: Re: [PATCH 1/5] chainlint: match arbitrary here-docs tags rather than hard-coded names Message-ID: <20180808225011.GC3902@sigill.intra.peff.net> In-Reply-To: <20180807082135.60913-2-sunshine@sunshineco.com> On Tue, Aug 07, 2018 at 04:21:31AM -0400, Eric Sunshine wrote: > diff --git a/t/chainlint.sed b/t/chainlint.sed > index 5f0882cb38..bd76c5d181 100644 > --- a/t/chainlint.sed > +++ b/t/chainlint.sed > @@ -61,6 +61,22 @@ > # "else", and "fi" in if-then-else likewise must not end with "&&", thus > # receives similar treatment. > # > +# Swallowing here-docs with arbitrary tags requires a bit of finesse. When a > +# line such as "cat <out" is seen, the here-doc tag is moved to the front > +# of the line enclosed in angle brackets as a sentinel, giving "cat >out". > +# As each subsequent line is read, it is appended to the target line and a > +# (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if > +# the content inside "<...>" matches the entirety of the newly-read line. For > +# instance, if the next line read is "some data", when concatenated with the > +# target line, it becomes "cat >out\nsome data", and a match is attempted > +# to see if "EOF" matches "some data". Since it doesn't, the next line is > +# attempted. When a line consisting of only "EOF" (and possible whitespace) is > +# encountered, it is appended to the target line giving "cat >out\nEOF", > +# in which case the "EOF" inside "<...>" does match the text following the > +# newline, thus the closing here-doc tag has been found. The closing tag line > +# and the "<...>" prefix on the target line are then discarded, leaving just > +# the target line "cat >out". Gross, but OK, as long as we would not get confused by a line that actually started with at the start. > +/<<[ ]*[-\\]*[A-Z0-9_][A-Z0-9_]*/ { > + s/^\(.*\)<<[ ]*[-\\]*\([A-Z0-9_][A-Z0-9_]*\)/<\2>\1< + s/[ ]*<