Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer error does not provide line number #102

Open
levkk opened this issue Nov 28, 2022 · 3 comments
Open

Lexer error does not provide line number #102

levkk opened this issue Nov 28, 2022 · 3 comments
Assignees
Labels
help wanted Extra attention is needed Type: Bug Bug or Bug fixes

Comments

@levkk
Copy link
Contributor

levkk commented Nov 28, 2022

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.

@Kogia-sima
Copy link
Member

@levkk Could you provide contents of the template file? (i.e., model.html)

@Kogia-sima Kogia-sima added the Status: Need Reproduction Cannot reproduce the issue label Mar 5, 2023
@levkk
Copy link
Contributor Author

levkk commented Mar 6, 2023

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

@Kogia-sima Kogia-sima self-assigned this Mar 6, 2023
@Kogia-sima
Copy link
Member

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...

@Kogia-sima Kogia-sima added Type: Bug Bug or Bug fixes help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request and removed Status: Need Reproduction Cannot reproduce the issue Status: PR Welcome Welcome to Pull Request labels Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Type: Bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants