Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdl-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default = ["serde"]
java = ["genco", "once_cell"]

[dependencies]
codespan-reporting = "0.11.1"
codespan-reporting = "0.13.1"
heck = "0.4.1"
pest = "2.7.6"
pest_derive = "2.7.6"
Expand Down
12 changes: 10 additions & 2 deletions pdl-compiler/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use codespan_reporting::files;
use codespan_reporting::term;
use codespan_reporting::term::termcolor;
use std::collections::HashMap;
use std::fmt;

use crate::ast::*;

Expand Down Expand Up @@ -87,6 +88,7 @@ impl Size {

/// List of unique errors reported as analyzer diagnostics.
#[repr(u16)]
#[derive(Copy, Clone)]
pub enum ErrorCode {
DuplicateDeclIdentifier = 1,
RecursiveDecl = 2,
Expand Down Expand Up @@ -142,9 +144,15 @@ pub enum ErrorCode {
InvalidPacketSize = 53,
}

impl fmt::Display for ErrorCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "E{}", *self as u16)
}
}

impl From<ErrorCode> for String {
fn from(code: ErrorCode) -> Self {
format!("E{}", code as u16)
format!("{}", code)
}
}

Expand Down Expand Up @@ -198,7 +206,7 @@ impl Diagnostics {
) -> Result<(), files::Error> {
let config = term::Config::default();
for d in self.diagnostics.iter() {
term::emit(writer, &config, sources, d)?;
term::emit_to_write_style(writer, &config, sources, d)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pdl-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn generate_backend(opt: &Opt) -> Result<(), String> {
Err(err) => {
let writer = termcolor::StandardStream::stderr(termcolor::ColorChoice::Always);
let config = term::Config::default();
term::emit(&mut writer.lock(), &config, &sources, &err).expect("Could not print error");
term::emit_to_write_style(&mut writer.lock(), &config, &sources, &err).expect("Could not print error");
Err(String::from("Error while parsing input"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pdl-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "pdl_derive"
proc-macro = true

[dependencies]
codespan-reporting = "0.11.1"
codespan-reporting = "0.13.1"
pdl-compiler = {path = "../pdl-compiler", version = "0.4.2"}
proc-macro2 = "1.0.66"
quote = "1.0.33"
Expand Down
4 changes: 2 additions & 2 deletions pdl-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn pdl_proc_macro(path: syn::LitStr, input: syn::ItemMod) -> TokenStream {
Ok(file) => file,
Err(err) => {
let mut buffer = termcolor::Buffer::no_color();
term::emit(&mut buffer, &term::Config::default(), &sources, &err)
term::emit_to_write_style(&mut buffer, &term::Config::default(), &sources, &err)
.expect("could not emit parser diagnostics");
return syn::Error::new(path.span(), String::from_utf8(buffer.into_inner()).unwrap())
.to_compile_error();
Expand Down Expand Up @@ -81,7 +81,7 @@ fn pdl_inline_proc_macro(code: syn::LitStr, input: syn::ItemMod) -> TokenStream
Ok(file) => file,
Err(err) => {
let mut buffer = termcolor::Buffer::no_color();
term::emit(&mut buffer, &term::Config::default(), &sources, &err)
term::emit_to_write_style(&mut buffer, &term::Config::default(), &sources, &err)
.expect("could not emit parser diagnostics");
return syn::Error::new(code.span(), String::from_utf8(buffer.into_inner()).unwrap())
.to_compile_error();
Expand Down
2 changes: 1 addition & 1 deletion pdl-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ thiserror = "1.0.47"
pdl-compiler = {path = "../pdl-compiler"}
pdl-runtime = {path = "../pdl-runtime"}
pdl-derive = {path = "../pdl-derive"}
codespan-reporting = "0.11.1"
codespan-reporting = "0.13.1"
proc-macro2 = "1.0.66"
quote = "1.0.33"
syn = {version = "2.0.29", features = ["full"]}
Expand Down
Loading