rust/compiler/rustc_errors/src
Trevor Gross 6a1c10bd85 Add a simple markdown parser for formatting rustc --explain
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.

This patch consists of three major components:

1.  A markdown parser. This is an extremely simple non-backtracking recursive
    implementation that requires normalization of the final token stream
2.  A utility to write the token stream to an output buffer
3.  Configuration within rustc_driver_impl to invoke this combination for
    `--explain`. Like the current implementation, it first attempts to print to
    a pager with a fallback colorized terminal, and standard print as a last
    resort.

    If color is disabled, or if the output does not support it, or if printing
    with color fails, it will write the raw markdown (which matches current
    behavior).

    Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
    and `delta`.

The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:

-   Headings, including formatting
-   Comments
-   Code, inline and fenced block (no indented block)
-   Strong, emphasis, and strikethrough formatted text
-   Links, anchor, inline, and reference-style
-   Horizontal rules
-   Unordered and ordered list items, including formatting

This parser and writer should be reusable by other systems if ever needed.
2023-07-03 16:04:18 -04:00
..
json various: translation resources from cg backend 2023-02-22 09:15:54 +00:00
markdown Add a simple markdown parser for formatting rustc --explain 2023-07-03 16:04:18 -04:00
annotate_snippet_emitter_writer.rs Create AnnotationColumn struct to fix hard tab column numbers in errors 2023-03-28 09:18:55 -04:00
diagnostic_builder.rs Remove adt_const_params usage from compiler 2023-06-01 18:21:42 +00:00
diagnostic_impls.rs Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
diagnostic.rs Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
emitter.rs Add a simple markdown parser for formatting rustc --explain 2023-07-03 16:04:18 -04:00
error.rs Make translate_message return result and add tests 2023-01-08 23:35:43 +01:00
json.rs refactor: statically guarantee that current error codes are documented 2023-02-26 20:12:36 +13:00
lib.rs Add a simple markdown parser for formatting rustc --explain 2023-07-03 16:04:18 -04:00
lock.rs bump windows crate 0.46 -> 0.48 in workspace 2023-05-09 18:20:13 +03:00
registry.rs refactor: statically guarantee that current error codes are documented 2023-02-26 20:12:36 +13:00
snippet.rs Create AnnotationColumn struct to fix hard tab column numbers in errors 2023-03-28 09:18:55 -04:00
styled_buffer.rs Replace some _ == _ || _ == _s with matches!(_, _ | _)s 2023-01-30 12:26:26 +00:00
tests.rs correct literals for dyn thread safe 2023-05-06 09:34:53 +08:00
translation.rs Restore behavior when primary bundle is missing 2023-02-23 01:14:10 +01:00