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

Support additional delimiters #16

Open
geauxvirtual opened this issue Jan 3, 2020 · 4 comments
Open

Support additional delimiters #16

geauxvirtual opened this issue Jan 3, 2020 · 4 comments

Comments

@geauxvirtual
Copy link

Golang allows setting the delimiters to use when parsing a template if the template is not using the default delimiters. It would be nice to have the same support here.

@fiji-flo
Copy link
Owner

fiji-flo commented Jan 8, 2020

I think this line made me not do this for now: https://github.com/golang/go/blob/master/src/text/template/parse/lex.go#L531

I'm just curious, do you have a use case for this, or is this about feature parity? And what's your delimiter of choice?

It's about adding the delimiters here: https://github.com/fiji-flo/gtmpl-rust/blob/master/src/lexer.rs#L103

@geauxvirtual
Copy link
Author

I've got a project that currently implements a server in Go, and this server can take a Go template for a configuration item. Ansible is used to set up this configuration item, and I wanted the ability to be able to configure settings in this template via Ansible/Jinja2, which uses {{ }} delimiters without affecting the fields the Go server needs to fill in the template. So for this particular use case, I chose [[ ]] as the delimiters for this template that gets passed into the server.

Where this comes into Rust and this library is that I'm writing a simulator in Rust for scale testing this server (and to assist in testing the server rewrite in Rust). Passing in the Go template isn't the issue from the simulator, but I'd like to be able to generate the same output in my simulator to compare against the output from the server, and this is where I'm currently looking for support for additional delimiters since the Go server is expecting [[ ]] for the template passed in.

Even after re-writing the server in Rust, the configuration will still occur via Ansible for the foreseeable future, so the current use case stated above will still exist for the Rust version of this server.

@fiji-flo
Copy link
Owner

fiji-flo commented Jan 9, 2020

I'll take a look at this when I have some free time. In the meanwhile feel free to open PR. As mentioned above, this should be a small change. However, we should add a strong warning that weird delimiters might break things (go doesn't take care of this either).

@geauxvirtual
Copy link
Author

I started to take a look at this today and have a branch here with my changes so far https://github.com/geauxvirtual/gtmpl-rust/commits/tb/add_delim_support

One thing I've noticed is that in src/parse.rs, there is a test testing Display for the parsed tree, and it appears that the delimiters are hard coded when writing out the parsed tree.

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

No branches or pull requests

2 participants