diff --git a/CHANGELOG.md b/CHANGELOG.md index 57bc6d8..7e93ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## [v0.3.3](https://github.com/Kogia-sima/sailfish/compare/v0.3.2...v0.3.3) (2021-04-06) + +## Fix + +* Improve error message for missing semicolon in code blocks + ## [v0.3.2](https://github.com/Kogia-sima/sailfish/compare/v0.3.1...v0.3.2) (2021-03-29) diff --git a/Cargo.lock b/Cargo.lock index a921cc3..8831237 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,7 +66,7 @@ dependencies = [ [[package]] name = "integration-tests" -version = "0.3.2" +version = "0.3.3" dependencies = [ "pretty_assertions", "sailfish", @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -168,7 +168,7 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "sailfish" -version = "0.3.2" +version = "0.3.3" dependencies = [ "itoap", "ryu", @@ -180,7 +180,7 @@ dependencies = [ [[package]] name = "sailfish-compiler" -version = "0.3.2" +version = "0.3.3" dependencies = [ "filetime", "home", @@ -194,7 +194,7 @@ dependencies = [ [[package]] name = "sailfish-macros" -version = "0.3.2" +version = "0.3.3" dependencies = [ "proc-macro2", "sailfish-compiler", @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.30" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2" +checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md index fc061c5..f0995f7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Dependencies: ```toml [dependencies] -sailfish = "0.3.2" +sailfish = "0.3.3" ``` Template file (templates/hello.stpl): diff --git a/docs/en/docs/installation.md b/docs/en/docs/installation.md index 06be926..387b877 100644 --- a/docs/en/docs/installation.md +++ b/docs/en/docs/installation.md @@ -4,7 +4,7 @@ In order to use sailfish templates, you have add two dependencies in your `Cargo ``` toml [dependencies] -sailfish = "0.3.2" +sailfish = "0.3.3" ``` ## Feature Flags diff --git a/examples/Cargo.toml b/examples/Cargo.toml index cf42a43..65a18ed 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sailfish-examples" -version = "0.3.2" +version = "0.3.3" authors = ["Ryohei Machida "] edition = "2018" publish = false diff --git a/sailfish-compiler/Cargo.toml b/sailfish-compiler/Cargo.toml index 24b1f72..c36a792 100644 --- a/sailfish-compiler/Cargo.toml +++ b/sailfish-compiler/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "sailfish-compiler" -version = "0.3.2" +version = "0.3.3" authors = ["Ryohei Machida "] -description = "Really fast, intuitive template engine for Rust" +description = "Simple, small, and extremely fast template engine for Rust" homepage = "https://github.com/Kogia-sima/sailfish" repository = "https://github.com/Kogia-sima/sailfish" readme = "../README.md" @@ -34,7 +34,7 @@ default-features = false features = ["parsing", "full", "visit-mut", "printing"] [dependencies.proc-macro2] -version = ">=1.0.11, <=1.0.24" +version = ">=1.0.11, <=1.0.26" default-features = false features = ["span-locations"] diff --git a/sailfish-compiler/src/translator.rs b/sailfish-compiler/src/translator.rs index e4ada46..527a1da 100644 --- a/sailfish-compiler/src/translator.rs +++ b/sailfish-compiler/src/translator.rs @@ -116,6 +116,14 @@ impl SourceBuilder { fn write_text<'a>(&mut self, token: &Token<'a>) -> Result<(), Error> { use std::fmt::Write; + // if error has occured at the first byte of `render_text!` macro, it + // will be mapped to the first byte of text + self.source_map.entries.push(SourceMapEntry { + original: token.offset(), + new: self.source.len(), + length: 1, + }); + self.source.push_str("__sf_rt::render_text!(__sf_buf, "); // write text token with Debug::fmt write!(self.source, "{:?}", token.as_str()).unwrap(); diff --git a/sailfish-macros/Cargo.toml b/sailfish-macros/Cargo.toml index 3fa1f91..74cdb00 100644 --- a/sailfish-macros/Cargo.toml +++ b/sailfish-macros/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "sailfish-macros" -version = "0.3.2" +version = "0.3.3" authors = ["Ryohei Machida "] -description = "Really fast, intuitive template engine for Rust" +description = "Simple, small, and extremely fast template engine for Rust" homepage = "https://github.com/Kogia-sima/sailfish" repository = "https://github.com/Kogia-sima/sailfish" readme = "../README.md" @@ -30,6 +30,6 @@ proc-macro2 = "1.0.11" [dependencies.sailfish-compiler] path = "../sailfish-compiler" -version = "0.3.2" +version = "0.3.3" default-features = false features = ["procmacro"] diff --git a/sailfish-tests/fuzzing-tests/Cargo.toml b/sailfish-tests/fuzzing-tests/Cargo.toml index 9a7e83f..2ee0185 100644 --- a/sailfish-tests/fuzzing-tests/Cargo.toml +++ b/sailfish-tests/fuzzing-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fuzzing-tests" -version = "0.3.2" +version = "0.3.3" authors = ["Ryohei Machida "] edition = "2018" publish = false diff --git a/sailfish-tests/integration-tests/Cargo.toml b/sailfish-tests/integration-tests/Cargo.toml index 8c414b9..dec0ca7 100644 --- a/sailfish-tests/integration-tests/Cargo.toml +++ b/sailfish-tests/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "integration-tests" -version = "0.3.2" +version = "0.3.3" authors = ["Kogia-sima "] edition = "2018" publish = false diff --git a/sailfish-tests/integration-tests/tests/fails/missing_semicolon.rs b/sailfish-tests/integration-tests/tests/fails/missing_semicolon.rs new file mode 100644 index 0000000..8d68d31 --- /dev/null +++ b/sailfish-tests/integration-tests/tests/fails/missing_semicolon.rs @@ -0,0 +1,10 @@ +use sailfish::TemplateOnce; +use sailfish_macros::TemplateOnce; + +#[derive(TemplateOnce)] +#[template(path = "missing_semicolon.stpl")] +struct MissingSemicolon {} + +fn main() { + println!("{}", (MissingSemicolon {}).render_once().unwrap()); +} diff --git a/sailfish-tests/integration-tests/tests/fails/missing_semicolon.stderr b/sailfish-tests/integration-tests/tests/fails/missing_semicolon.stderr new file mode 100644 index 0000000..0f9bc79 --- /dev/null +++ b/sailfish-tests/integration-tests/tests/fails/missing_semicolon.stderr @@ -0,0 +1,37 @@ +error: Failed to compile template. +caused by: Rust Syntax Error (unexpected token) + +file: missing_semicolon.stpl +position: line 1, column 17 + + | +1 |
<% "foo" %>
+ | ^ + + --> $DIR/missing_semicolon.rs:4:10 + | +4 | #[derive(TemplateOnce)] + | ^^^^^^^^^^^^ + | + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0599]: no method named `render_once` found for struct `MissingSemicolon` in the current scope + --> $DIR/missing_semicolon.rs:9:42 + | +6 | struct MissingSemicolon {} + | ----------------------- method `render_once` not found for this +... +9 | println!("{}", (MissingSemicolon {}).render_once().unwrap()); + | ^^^^^^^^^^^ method not found in `MissingSemicolon` + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `render_once`, perhaps you need to implement it: + candidate #1: `TemplateOnce` + +warning: unused import: `sailfish::TemplateOnce` + --> $DIR/missing_semicolon.rs:1:5 + | +1 | use sailfish::TemplateOnce; + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default diff --git a/sailfish-tests/integration-tests/tests/fails/templates/missing_semicolon.stpl b/sailfish-tests/integration-tests/tests/fails/templates/missing_semicolon.stpl new file mode 100644 index 0000000..0895829 --- /dev/null +++ b/sailfish-tests/integration-tests/tests/fails/templates/missing_semicolon.stpl @@ -0,0 +1 @@ +
<% "foo" %>
diff --git a/sailfish-tests/integration-tests/tests/fails/unbalanced_brace.stderr b/sailfish-tests/integration-tests/tests/fails/unbalanced_brace.stderr index 8946b65..ca181b7 100644 --- a/sailfish-tests/integration-tests/tests/fails/unbalanced_brace.stderr +++ b/sailfish-tests/integration-tests/tests/fails/unbalanced_brace.stderr @@ -1,5 +1,5 @@ error: Failed to compile template. -caused by: Rust Syntax Error (LexError) +caused by: Rust Syntax Error (lex error) file: unbalanced_brace.stpl diff --git a/sailfish/Cargo.toml b/sailfish/Cargo.toml index efc4bcb..772ee79 100644 --- a/sailfish/Cargo.toml +++ b/sailfish/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "sailfish" -version = "0.3.2" +version = "0.3.3" authors = ["Ryohei Machida "] -description = "Really fast, intuitive template engine for Rust" +description = "Simple, small, and extremely fast template engine for Rust" homepage = "https://github.com/Kogia-sima/sailfish" repository = "https://github.com/Kogia-sima/sailfish" readme = "../README.md" @@ -29,7 +29,7 @@ serde_json = { version = "1.0.53", optional = true } [dependencies.sailfish-macros] path = "../sailfish-macros" -version = "0.3.2" +version = "0.3.3" optional = true [build-dependencies]