Ticket #10458: continuation.patch

File continuation.patch, 2.2 KB (added by Keshav Kini, 12 years ago)

patch to make sage recognize "....:" continuation line prefixes in doctests

  • sage-doctest

    # HG changeset patch
    # User Keshav Kini <kini@member.ams.org>
    # Date 1292261117 -28800
    # Node ID f91e8c13f6559d043186a2786bc121bdacd756bd
    # Parent  4047e578febc6e9895d6b5650dc81f0515a170c5
    Add support for "....: "-style continuation line prefixes, such as the sage interpreter prompt displays (may be incomplete)
    
    diff -r 4047e578febc -r f91e8c13f655 sage-doctest
    a b  
    248248    """
    249249    Run the preparser on the documentation string s.
    250250    This *only* preparses the input lines, i.e., those
    251     that begin with "sage:".or with "..."
     251    that begin with "sage:", "....:", or "...".
    252252    """
    253253    sl = s.lower()
    254254
     
    286286                # and an empty line, to ignore the output given in the test
    287287                line += '\n' + ' '*i + 'ignore ...\n'
    288288            t.append(line)
     289
     290        elif begin == '....:':
     291            t.append(preparse_line_with_prompt(L))
    289292           
    290293        elif begin.startswith('...'):
    291294            comment = last_prompt_comment
     
    384387            while j < len(F) and L.endswith('\\') and not L.endswith('\\\\'):
    385388                j += 1
    386389                i += 1
    387                 L = L[:-1] + F[j].lstrip().lstrip('...').rstrip()
     390                L = L[:-1] + F[j].lstrip().lstrip('....:').lstrip('...').rstrip()
    388391            L += '###_sage"line %s:_sage_    %s_sage"'%(i, L.strip())
    389392        j += 1
    390393        i += 1
     
    477480    if n == 0:
    478481        return  ''
    479482    s += test_code(os.path.abspath(file_name))
    480 
    481     # Allow for "sage:" instead of the traditional Python ">>>".
    482     s = s.replace("sage:",">>>").replace('_sage"','')
     483   
     484    # Allow for "sage: " and "....: " instead of the traditional Python ">>> " and "... ".
     485    s = s.replace("sage:",">>>").replace("....:","...").replace('_sage"','')
    483486   
    484487    return s
    485488
     
    607610        cnt += 1
    608611        if cnt > 1000:
    609612            break
    610     s = s.replace(':_sage_',':\n').replace('>>>','sage:')
     613    s = s.replace(':_sage_',':\n').replace('>>>','sage:').replace('... ','....: ')
    611614    c = '###line [0-9]*\n'
    612615    r = re.compile(c)
    613616    s = r.sub('\n',s)