(e: CompilationError)
Format code with highlighted syntax error.
Format code with highlighted syntax error.
Format code with highlighted syntax error .
def _get_lines_with_highlighted_error(e: CompilationError) -> Iterable[str]:
    """Format code with highlighted syntax error."""
    error_line = e.lineno - 1
    lines = e.code.split('\n')
    padding = len(str(len(lines)))

    from_line = error_line - const.SYNTAX_ERROR_OFFSET
    if from_line < 0:
        from_line = 0

    if from_line < error_line:
        for n in range(from_line, error_line):
            yield _format_line(lines[n], n, padding)

    yield '  {dim}{n}{reset}: {bright}{line}{reset}'.format(
        dim=Style.DIM,
        n=str(error_line + 1).zfill(padding),
        line=lines[error_line],
        reset=Style.RESET_ALL,
        bright=Style.BRIGHT)
    yield '  {padding}{bright}^{reset}'.format(
        padding=' ' * (padding + e.offset + 1),
        bright=Style.BRIGHT,
        reset=Style.RESET_ALL)

    to_line = error_line + const.SYNTAX_ERROR_OFFSET
    if to_line > len(lines):
        to_line = len(lines)
    for n in range(error_line + 1, to_line):
        yield _format_line(lines[n], n, padding)
def _get_lines_with_highlighted_error ( e : CompilationError ) -> Iterable [ str ] : error_line = e . lineno - 1 lines = e . code . split ( '\n' ) padding = len ( str ( len ( lines ) ) ) from_line = error_line - const . SYNTAX_ERROR_OFFSET if from_line < 0 : from_line = 0 if from_line < error_line : for n in range ( from_line , error_line ) : yield _format_line ( lines [ n ] , n , padding ) yield '  {dim}{n}{reset}: {bright}{line}{reset}' . format ( dim = Style . DIM , n = str ( error_line + 1 ) . zfill ( padding ) , line = lines [ error_line ] , reset = Style . RESET_ALL , bright = Style . BRIGHT ) yield '  {padding}{bright}^{reset}' . format ( padding = ' ' * ( padding + e . offset + 1 ) , bright = Style . BRIGHT , reset = Style . RESET_ALL ) to_line = error_line + const . SYNTAX_ERROR_OFFSET if to_line > len ( lines ) : to_line = len ( lines ) for n in range ( error_line + 1 , to_line ) : yield _format_line ( lines [ n ] , n , padding )