comparison contrib/testparseutil.py @ 44020:ac3cb5e05a38

cleanup: replace contiguous spaces in regex patterns with an explicit count Flagged by PyCharm, this form should be more readable. Differential Revision: https://phab.mercurial-scm.org/D7765
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 28 Dec 2019 01:12:19 -0500
parents 70d42e2ad9b4
children 89a2afe31e82
comparison
equal deleted inserted replaced
44019:5bbd770d1324 44020:ac3cb5e05a38
329 namepat = ( 329 namepat = (
330 r'\s*>>?\s*(?P<nquote>["\']?)(?P<name>%s)(?P=nquote)' % namepat 330 r'\s*>>?\s*(?P<nquote>["\']?)(?P<name>%s)(?P=nquote)' % namepat
331 ) 331 )
332 self._fileres = [ 332 self._fileres = [
333 # "cat > NAME << LIMIT" case 333 # "cat > NAME << LIMIT" case
334 re.compile(r' \$ \s*cat' + namepat + heredoclimitpat), 334 re.compile(r' {2}\$ \s*cat' + namepat + heredoclimitpat),
335 # "cat << LIMIT > NAME" case 335 # "cat << LIMIT > NAME" case
336 re.compile(r' \$ \s*cat' + heredoclimitpat + namepat), 336 re.compile(r' {2}\$ \s*cat' + heredoclimitpat + namepat),
337 ] 337 ]
338 338
339 def startsat(self, line): 339 def startsat(self, line):
340 # ctx is (filename, END-LINE-OF-EMBEDDED-CODE) tuple 340 # ctx is (filename, END-LINE-OF-EMBEDDED-CODE) tuple
341 for filere in self._fileres: 341 for filere in self._fileres:
424 True 424 True
425 >>> matcher.codeatend(ctx, end) 425 >>> matcher.codeatend(ctx, end)
426 """ 426 """
427 427
428 _prefix = ' >>> ' 428 _prefix = ' >>> '
429 _prefixre = re.compile(r' (>>>|\.\.\.) ') 429 _prefixre = re.compile(r' {2}(>>>|\.\.\.) ')
430 430
431 # If a line matches against not _prefixre but _outputre, that line 431 # If a line matches against not _prefixre but _outputre, that line
432 # is "an expected output line" (= not a part of code fragment). 432 # is "an expected output line" (= not a part of code fragment).
433 # 433 #
434 # Strictly speaking, a line matching against "(#if|#else|#endif)" 434 # Strictly speaking, a line matching against "(#if|#else|#endif)"
435 # is also treated similarly in "inline python code" semantics by 435 # is also treated similarly in "inline python code" semantics by
436 # run-tests.py. But "directive line inside inline python code" 436 # run-tests.py. But "directive line inside inline python code"
437 # should be rejected by Mercurial reviewers. Therefore, this 437 # should be rejected by Mercurial reviewers. Therefore, this
438 # regexp does not matche against such directive lines. 438 # regexp does not matche against such directive lines.
439 _outputre = re.compile(r' $| [^$]') 439 _outputre = re.compile(r' {2}$| {2}[^$]')
440 440
441 def __init__(self): 441 def __init__(self):
442 super(pydoctestmatcher, self).__init__("doctest style python code") 442 super(pydoctestmatcher, self).__init__("doctest style python code")
443 443
444 def startsat(self, line): 444 def startsat(self, line):
507 """ 507 """
508 508
509 _prefix = ' > ' 509 _prefix = ' > '
510 510
511 _startre = re.compile( 511 _startre = re.compile(
512 r' \$ (\$PYTHON|"\$PYTHON"|python).*' + heredoclimitpat 512 r' {2}\$ (\$PYTHON|"\$PYTHON"|python).*' + heredoclimitpat
513 ) 513 )
514 514
515 def __init__(self): 515 def __init__(self):
516 super(pyheredocmatcher, self).__init__("heredoc python invocation") 516 super(pyheredocmatcher, self).__init__("heredoc python invocation")
517 517