[issue36714] Tweak doctest 'example' regex to allow a leading ellipsis in 'want' line

Brian Skinn report at bugs.python.org
Fri Aug 9 14:06:25 EDT 2019


Brian Skinn <bskinn at alum.mit.edu> added the comment:

Mm, agreed--that regex wouldn't be hard to write.

The problem is, AFAICT there's irresolvable syntactic ambiguity in a line starting with exactly three periods, if the doctest PS2 specification is not constrained to be exactly "... ". In such a case, "..." could mark either (1) an ellipsis standing in for an entire line of 'want', or (2) a PS2, marking a blank line in 'source'.

I don't really think aggressive lookahead would help much -- an arbitrary number of following lines could contain exactly "...", and the intended transition from 'source' to 'want' could lie at any one of them.  The nonrecursive nature of regex is unhelpful here, but I don't think one could even write a recursive-descent parser, or similar, that could be 100% reliable on a single comparison. It would have to test the string against all the various splits between 'source' and 'want' along those "..." lines, and see if any match. Hairy mess.

AFAICT, defining "... " as PS2, and "..." as 'ellipsis representing a whole line' is the cleanest solution from a logical point of view.

Of course, then it's *visually* confusing, because trailing space. ¯\_(ツ)_/¯

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36714>
_______________________________________


More information about the Python-bugs-list mailing list