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

Interpolation support for any expression (not only identifiers) #430

Open
davesnx opened this issue Mar 7, 2024 · 1 comment
Open

Interpolation support for any expression (not only identifiers) #430

davesnx opened this issue Mar 7, 2024 · 1 comment
Labels
parser Parsing or lexing issues

Comments

@davesnx
Copy link
Owner

davesnx commented Mar 7, 2024

Explore how difficult is to support any expression inside the interpolation syntax.

[%css "font-size: $(string_of_int(23))"];

let base = 33;
[%css "font-size: $(string_of_int(base))"];

let darken = (color, num) => { ... };
[%css "color: $(darken(CssJs.blue, 0.3))"];

Any expression it might be virtually impossible to parse by styled-ppx, but we can “stop parsing” until a matching ) appears.

Another approach is trying to run the "current parser" as a single expression inside the interpolated value, I'm unsure how to do this since embeding ReScript/OCaml/Reason parsers is not an option (would bloat the binary)

Other ppxes that support some sort of expression interp is because the entire payload is valid: https://github.com/thierry-martinez/metapp.

metaquote uses a trick where [%expr] is the ppx, and [%e ] can be placed inside expr for any expression. Errors are tricky, and DX seems bad. Similar case is https://github.com/stedolan/ppx_stage

The last idea is to have a mini parser for only function calls in OCaml/Reason and ReScript that we support, similar on how ppx_str works https://github.com/AriaFallah/ppx_str/blob/master/src/ppx/ppx_str.ml and warn the user about it, so they can always extract into a function.

@davesnx davesnx added the parser Parsing or lexing issues label Mar 7, 2024
@davesnx
Copy link
Owner Author

davesnx commented Nov 3, 2024

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

No branches or pull requests

1 participant