diff --git a/Cargo.lock b/Cargo.lock index 5898f03..7dbe469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "heraclitus-compiler" -version = "1.7.2" +version = "1.7.3" dependencies = [ "capitalize", "colored", diff --git a/Cargo.toml b/Cargo.toml index 157f782..7615937 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heraclitus-compiler" -version = "1.7.2" +version = "1.7.3" edition = "2021" description = "Compiler frontend for developing great programming languages" license = "MIT" diff --git a/README.md b/README.md index 5fd72a6..aaa956d 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ let tokens = cc.tokenize()?; # Change log 🚀 +## Version 1.7.3 +### Fix: +- `Logger::text` now doesn't end with a new line +### Feature: +- Added `Logger::line` method that adds a new line in the end (works just like old `Logger::text`) + ## Version 1.7.2 ### Fix: - `PositionInfo::from_between_tokens` shows the range even if the end token is None diff --git a/src/compiling/failing/logger.rs b/src/compiling/failing/logger.rs index 8ede4fc..0ecfed4 100644 --- a/src/compiling/failing/logger.rs +++ b/src/compiling/failing/logger.rs @@ -43,20 +43,28 @@ impl Logger { .black() .bold() .on_color(self.kind_to_color()); - eprintln!("{formatted}"); + eprint!("{formatted} "); self } /// Render text with supplied coloring pub fn text(self, text: Option) -> Self { + if let Some(text) = text { + eprint!("{}", text.color(self.kind_to_color())); + } + self + } + + /// Render text with supplied coloring and end it with a newline + pub fn line(self, text: Option) -> Self { if let Some(text) = text { eprintln!("{}", text.color(self.kind_to_color())); } self } - /// Render padded text with supplied coloring - pub fn padded_text(self, text: Option) -> Self { + /// Render padded text with a newline, applying the supplied coloring, and end it with another newline + pub fn padded_line(self, text: Option) -> Self { if let Some(text) = text { eprintln!("\n{}", text.color(self.kind_to_color())); } @@ -83,7 +91,7 @@ impl Logger { None => { "at [unknown]:0:0".to_string() } - }; + }.trim_end().to_string(); eprintln!("{}", path.color(self.kind_to_color()).dimmed()); self } @@ -233,7 +241,7 @@ mod test { ]; super::Logger::new(MessageType::Error, &trace) .header(MessageType::Error) - .text(Some(format!("Cannot call function \"foobar\" on a number"))) + .line(Some(format!("Cannot call function \"foobar\" on a number"))) .path() .snippet(Some(code)); } @@ -250,7 +258,7 @@ mod test { ]; super::Logger::new(MessageType::Error, &trace) .header(MessageType::Error) - .text(Some(format!("Cannot call function \"foobar\" on a number"))) + .line(Some(format!("Cannot call function \"foobar\" on a number"))) .path() .snippet(Some(code)); } @@ -270,7 +278,7 @@ mod test { ]; super::Logger::new(MessageType::Error, &trace) .header(MessageType::Error) - .text(Some(format!("Cannot call function \"foobar\" on a number"))) + .line(Some(format!("Cannot call function \"foobar\" on a number"))) .path() .snippet(Some(code)); } diff --git a/src/compiling/failing/message.rs b/src/compiling/failing/message.rs index 222dc18..f9c80d3 100644 --- a/src/compiling/failing/message.rs +++ b/src/compiling/failing/message.rs @@ -1,5 +1,5 @@ //! Display your errors -//! +//! //! Logger makes it easy for you to display errors. This sub-module is pretty powerful //! to be used extensively instead of building own implementation of such mechanism. //! However, if you need more specific functionality - it is encouraged to create your @@ -22,7 +22,7 @@ pub enum MessageType { } /// Logger itself -/// +/// /// Log the message you want to show to the user /// # Example /// ```should_panic @@ -144,7 +144,7 @@ impl Message { self } - /// Shows (renders) the message while giving + /// Shows (renders) the message while giving /// the ownership to this object away pub fn show(&self) { // If this error is based in code @@ -153,7 +153,7 @@ impl Message { .header(self.kind.clone()) .text(self.message.clone()) .path() - .padded_text(self.comment.clone()) + .padded_line(self.comment.clone()) .snippet(self.code.clone()); } // If this error is a message error @@ -161,7 +161,7 @@ impl Message { Logger::new(self.kind.clone(), &self.trace) .header(self.kind.clone()) .text(self.message.clone()) - .padded_text(self.comment.clone()); + .padded_line(self.comment.clone()); } } @@ -174,7 +174,7 @@ impl Message { #[cfg(test)] mod test { - + #[test] fn test_logger() { // use super::Logger; @@ -184,6 +184,3 @@ mod test { // .exit(); } } - - -