This commit adds a heuristics-based syntax highlighter for the `rustc --explain` command. It uses `rsutc_lexer`'s lexer to parse input in tokens, and matches on them to determine their color.
29 lines
488 B
Rust
29 lines
488 B
Rust
//@ run-pass
|
|
//@ check-run-results
|
|
|
|
#![feature(rustc_private)]
|
|
use std::io::Write;
|
|
extern crate rustc_driver;
|
|
extern crate rustc_driver_impl;
|
|
|
|
use rustc_driver_impl::highlighter::highlight;
|
|
|
|
const TEST_INPUT: &str = "
|
|
struct Foo;
|
|
|
|
fn baz(x: i32) {
|
|
// A function
|
|
}
|
|
|
|
fn main() {
|
|
let foo = Foo;
|
|
foo.bar();
|
|
}
|
|
";
|
|
|
|
fn main() {
|
|
let mut buf = Vec::new();
|
|
highlight(TEST_INPUT, &mut buf).unwrap();
|
|
let mut stdout = std::io::stdout();
|
|
stdout.write_all(&buf).unwrap();
|
|
}
|