Hi all,While building my own EEx Engine I encountered an issue, which might be easily resolved, if EEx.Engine allow to use custom markers.
As it stands in the documentation of EEx.Engine behaviour:
The allowed markers so far are: "" and "=".
The EExEngine API is prepared for having custom markers, as handle_expr/3 receives the marker, but currently it receives only "=" or "". Trying to put own marker treats it as a part of the expression.
My proposition is to create a list of additional markers to use by a developer who writes own EEx Engine. For a begin, it could be:
(none of those markers should confuse the "" marker, as they should not appear at the beginning of any Elixr expression)
By default, those markers may behave as "=". But when you create your own EEx Engine, you would be able to override handle_expr/3 for those markers.
-----------
Rough example:
defmodule ExtendedEngine do
use EEx.Engine
def handle_expr(buffer, "/", expr) do
super(buffer, "=", modified_expression(expr))
end
def handle_expr(buffer, mark, expr) do
super(buffer, mark, expr)
end
end
Current behaviour:
iex> EEx.eval_string "foo <%/ bar %>", [bar: "baz"], engine: ExtendedEngine
** (SyntaxError) nofile:1: syntax error before: '/'
lib/eex/compiler.ex:36: EEx.Compiler.generate_buffer/4
lib/eex.ex:196: EEx.eval_string/3
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(iex) lib/iex/evaluator.ex:182: IEx.Evaluator.handle_eval/6
(iex) lib/iex/evaluator.ex:175: IEx.Evaluator.do_eval/4
Expected behaviour:
iex> EEx.eval_string "foo <%/ bar %>", [bar: "baz"], engine: ExtendedEngine
"foo BAZ"