18 lines
507 B
Rust
18 lines
507 B
Rust
use ansi_markup::parse_ansi_markup;
|
|
use proc_macro::TokenStream;
|
|
use quote::ToTokens;
|
|
use syn::{parse_macro_input, Lit};
|
|
|
|
#[proc_macro]
|
|
pub fn ansi(input: TokenStream) -> TokenStream {
|
|
let raw = match parse_macro_input!(input as Lit) {
|
|
Lit::Str(lit_str) => lit_str.value(),
|
|
_ => panic!("Expected a string literal"),
|
|
};
|
|
TokenStream::from(
|
|
parse_ansi_markup(&raw)
|
|
.unwrap_or_else(|e| panic!("Bad ansi literal: {}", e))
|
|
.into_token_stream(),
|
|
)
|
|
}
|