Allow access to compiler_options while compiling EEx

35 views
Skip to first unread message

Wannes Gennar

unread,
Jun 19, 2021, 1:42:54 PM6/19/21
to elixir-lang-core

Currently the only way to modify the options passed into EEx's Code.string_to_quoted!/2 call is by calling Code.put_compiler_option/2 for :parser_options.

Specifically I'd want to pass in a custom :static_atoms_encoder function while compiling certain EEx templates. However Code.put_compiler_option feels a bit hackey and it modifies configuration that not only affects the compilation of my specific EEx templates.

Ideally you'd be able to pass along options to EEx.compile_* that get passed down to Code.string_to_quoted to allow for more fine grained control over the code generation.

José Valim

unread,
Jun 19, 2021, 2:21:19 PM6/19/21
to elixir-l...@googlegroups.com
Makes total sense. A PR for "parser_options" is welcome!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/85799e27-9ec8-4579-9790-75150d73a57cn%40googlegroups.com.

Wannes Gennar

unread,
Jun 19, 2021, 2:30:54 PM6/19/21
to elixir-lang-core
Given that EEx.compile_string/2 already has an optional options parameter I don't think adding a third one would be wise as that would definitely start breaking stuff.
Maybe add something like :parser_options as a possible option you can pass in?

The call would look something like: EEx.compile_string("something here", [parser_options: [static_atoms_encoder: fn (a, b) -> something end]])
If you think that works I'll get going on a PR!

Wojtek Mach

unread,
Jun 19, 2021, 2:33:15 PM6/19/21
to elixir-lang-core
I know for a fact that :parser_options key is exactly what José had in mind :)

Wannes Gennar

unread,
Jun 19, 2021, 3:00:28 PM6/19/21
to elixir-lang-core
Just wanted to make sure :)

Reply all
Reply to author
Forward
0 new messages