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

Escape dots - end of expression #64

Closed
Aunmag opened this issue Dec 9, 2019 · 2 comments · Fixed by #65
Closed

Escape dots - end of expression #64

Aunmag opened this issue Dec 9, 2019 · 2 comments · Fixed by #65

Comments

@Aunmag
Copy link

Aunmag commented Dec 9, 2019

I've been migrating from Java to Rust with ructe, and got into a problem which I don't now how to solve. So I have a number of SQL temples like this one, and they cannot be compiled:

ALTER SEQUENCE @(model.schema).@(model.get_sequence_name())
	OWNED BY @(model.schema).@(model.name).id;

I got:

error[E0609]: no field `id` on type `std::string::String`
  --> D:\Development\coderator-rs\target\debug\build\coderator-94163fea6e350a38\out\templates\template_create_html.rs:24:12
   |
24 | model.name.id.to_html(&mut out)?;
   |            ^^ unknown field

error: aborting due to previous error

For more information about this error, try `rustc --explain E0609`.
error: could not compile `coderator`.

To learn more, run the command again with --verbose.

Please, consider to implement rocker-like eval expressions from the beast Java template engine I've ever seen. Everything outside @(...) should be treated as a template text, not as an expression.

I know that there already was #2 but I still don't know to make my templates work.

@Aunmag Aunmag changed the title Escape dots Escape dots - end of expression Dec 9, 2019
@kaj
Copy link
Owner

kaj commented Dec 11, 2019

You use ructe for sql? Cool! :-)

Ah. The @[email protected]_sequence_name() part should be no problem problem even without the parentesis, but then you have the @(model.name).id part.

One way of fixing this would be to say that if an expression starts with an open parenthesis, then it ends when that parenthesis is closed. That would make your example behave correctly. And if we just allow the same things inside those parenthesis as we allow in expressions today, I don't see any real down-side. Does that sound ok to you?

kaj added a commit that referenced this issue Dec 11, 2019
BREAKING CHANGE.  If an expession stars with an open parenthesis, the
expression ends on the closing parenthesis (and that outer parenthesis
is not part of the expression.

This fixes cases where an expression is immediately followed by
something that could be part of the expression.

Before this change, calling a function on the result of some
subexpression could be written as `@(a - b).abs()`.  After this
change, that should be changed to `@((a - b).abs())` unless the intent
is to have the result of (a - b) followed by the template string
`.abs()`.

Fixes #64.
@Aunmag
Copy link
Author

Aunmag commented Dec 11, 2019

That sounds awesome! 👍

kaj added a commit that referenced this issue Dec 14, 2019
BREAKING CHANGE.  If an expession starts with an open parenthesis, the
expression ends on the closing parenthesis (and that outer parenthesis
is not part of the expression.

This fixes cases where an expression is immediately followed by
something that could be part of the expression.

Before this change, calling a function on the result of some
subexpression could be written as `@(a - b).abs()`.  After this
change, that should be changed to `@((a - b).abs())` unless the intent
is to have the result of (a - b) followed by the template string
`.abs()`.

Fixes #64.
@kaj kaj closed this as completed in #65 Dec 14, 2019
kaj added a commit that referenced this issue Dec 25, 2019
* PR #65, Issue #64: An expression starting with paren ends on close.
* RucteError now implements std::error::Error.
* Specify which references in examples are `dyn` or `impl`.
* Remove a useless string clone.
* Update rsass to 0.12.0.

Thanks to @Aunmag.
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

Successfully merging a pull request may close this issue.

2 participants