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

error: no rules expected the token tmpl #17

Closed
Txuritan opened this issue Oct 6, 2017 · 6 comments
Closed

error: no rules expected the token tmpl #17

Txuritan opened this issue Oct 6, 2017 · 6 comments

Comments

@Txuritan
Copy link

Txuritan commented Oct 6, 2017

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);
                        }
                    }
                }
            }
        }
    }
@Stebalien
Copy link
Owner

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.

@Stebalien
Copy link
Owner

#18

@Txuritan
Copy link
Author

Txuritan commented Oct 6, 2017

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.

@Stebalien
Copy link
Owner

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

@Txuritan
Copy link
Author

Txuritan commented Oct 7, 2017

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.

@Stebalien
Copy link
Owner

Unfortunately not. That happens at run-time but macro syntax errors happen at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants