You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
910 B
Rust
31 lines
910 B
Rust
use proc_macro::{Diagnostic, Level, Span};
|
|
use proc_macro2::TokenStream;
|
|
|
|
pub trait Compile: Sized {
|
|
fn compile(self) -> TokenStream;
|
|
}
|
|
|
|
pub fn emit_err(span: impl Into<Option<Span>>, msg: impl Into<String>) {
|
|
emit_diagnostic(span.into(), Level::Error, msg)
|
|
}
|
|
|
|
pub fn emit_warning(span: impl Into<Option<Span>>, msg: impl Into<String>) {
|
|
emit_diagnostic(span.into(), Level::Warning, msg)
|
|
}
|
|
|
|
pub fn emit_note(span: impl Into<Option<Span>>, msg: impl Into<String>) {
|
|
emit_diagnostic(span.into(), Level::Note, msg)
|
|
}
|
|
|
|
pub fn emit_help(span: impl Into<Option<Span>>, msg: impl Into<String>) {
|
|
emit_diagnostic(span.into(), Level::Help, msg)
|
|
}
|
|
|
|
fn emit_diagnostic(span: Option<Span>, level: Level, msg: impl Into<String>) {
|
|
let diagnostic = match span {
|
|
Some(span) => Diagnostic::spanned(span, level, msg),
|
|
None => Diagnostic::new(level, msg),
|
|
};
|
|
diagnostic.emit();
|
|
}
|