error: no rules expected the token `tmpl`
Closed this issue · 6 comments
As a prenote I only have a general idea of how rust works and are making a web site/server to learn it.
I have multiple functions that return Box<RenderBox>
that are later used in a function that returns the rendered string.
Version: 0.6.2
Log
error: no rules expected the token `tmpl`
--> src\resources\partials\element.rs:131:5
|
131 | / box_html! {
132 | | nav(class="nav nav_top full_width") {
133 | | ul(class="nav__menu flex flex--nowrap flex__center wrapper") {
134 | | li(class="nav__items--container") {
... |
151 | | }
152 | | }
| |_____^
|
= note: this error originates in a macro outside of the current crate
Code
box_html! {
nav(class="nav nav_top full_width") {
ul(class="nav__menu flex flex--nowrap flex__center wrapper") {
li(class="nav__items--container") {
ul(class="nav__items--list flex flex--nowrap") {
li(class="flex__item") {
a(href="/", class="nav__link") {
: "Story";
b : "Archive";
}
}
: navbar_item(item_grow)
@ if navbar_drawer {
: navbar_drawer(drawer);
} else {
: navbar_item(item_login);
}
}
}
}
}
}
You're missing a semicolon before @ if nabar_drawer
(what, you wanted a nice error message?). In the past, issuing compiler errors from macros was impossible so I didn't even bother trying to handle error cases nicely but that has since changed with the introduction of the compile_error
macro so I'll open an issue for sane errors.
Thank you that fixed it, I though I got all those. I also never knew that macros couldn't have error handling, but yes having any type of error handling would be nice other than the 'it failed' kind it has now.
They can now but it's still very difficult. For example, there's no way to get the line on which a token occurs in a macro (as far as I know at least).
Note: This only applies to declarative macros (like horrorshow). Procedural macros are a lot more flexible (they're just procedural code).
Perhaps it could be done by the render, like it walks through and if it finds something that breaks then it takes note of it and logs it.
Unfortunately not. That happens at run-time but macro syntax errors happen at compile time.