Lexer error does not provide line number
Hi,
Thank you for making an awesome crate. This is my favorite Rust template library by a mile.
When writing relatively large templates, I occasionally make mistakes in the template syntax and I get a lexer error like this one:
error: Failed to compile template.
caused by: Rust Syntax Error (lex error)
file: /home/lev/Projects/dashboard/templates/model.html
#[derive(TemplateOnce)]
note: this error originates in the derive macro `TemplateOnce` (in Nightly builds, run with -Z macro-backtrace for more info)
Unfortunately, it doesn't tell me which line number the error is on, so it's pretty difficult to debug. Is it possible to count line numbers when parsing and report the line number accordingly?
Thank you.
@levkk Could you provide contents of the template file? (i.e., model.html)
main.rs
use sailfish::TemplateOnce;
#[derive(TemplateOnce)]
#[template(path = "example.html")]
pub struct Example {
title: String,
}
templates/example.html
<html>
<head><%= title %></head>
</html>
<% if { non_ %>
$ cargo build
Compiling example v0.1.0 (/home/lev/code/example)
error: Failed to compile template.
caused by: Rust Syntax Error (lex error)
file: /home/lev/code/example/templates/example.html
--> src/main.rs:3:10
|
3 | #[derive(TemplateOnce)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `TemplateOnce` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `example` due to previous error
It seems that the extra brace causes proc_macro2::LexError with unpredictable span.
{
"feed": "{\nif { non_\n\n}",
"error": "lex error",
"span": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 0
}
}
}
Maybe we need to implement Rust lexer from scratch in order to solve this error...