maghoff / bart

A compile time templating language for Rust inspired by Mustache
https://crates.io/crates/bart
MIT License
37 stars 7 forks source link

Support underscore in variable names #6

Closed johshoff closed 7 years ago

johshoff commented 7 years ago

Implement a function to grab a rust identifier. This is more proof of concept than ultimate solution.

I tried using macros, but without succeeding. Along the lines of take_while!(is_identifier_character). There might also be solutions using nom's regexps. This solution is more or less lifted from nom's implementation of alphanumeric. They probably implemented it in rust for a reason. Not sure if it's for speed or if macros weren't sufficient for them either.

Also, implementation aside, this does not actually correctly implement a correct rust identifier parser. That is a lot more complicated:https://doc.rust-lang.org/reference.html#identifiers (which is even disputed)

maghoff commented 7 years ago

Pertaining to issue #3

maghoff commented 7 years ago

syn is a crate that implements parsing of rust code with nom. If we would be able to reuse the identifier parser from syn, that would be perfect. A cursory look seems to indicate that they do not publicly export the identifier nom parser, but they do export one with a slightly different interface: parse_ident.

maghoff commented 7 years ago

In the meantime, I might merge this just to get support for underscore.

maghoff commented 7 years ago

I have fixed the travis config. I think you need to rebase on top of master for the inline travis check to pass.

maghoff commented 7 years ago

I fixed this by completely rewriting the parser, incidentally using syn to verify the identifier names