elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Custom static atom encoder causes errors in the Elixir tokenizer's error formatting

Open fertapric opened this issue 1 year ago • 0 comments

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

Operating system

macOS Big Sur 11.7.10

Current behavior

Code.string_to_quoted("Module(", static_atoms_encoder: fn atom, _metadata -> {:ok, {:atom, [], atom}} end)

Produces:

** (ArgumentError) argument error
    (stdlib 6.0.1) io_lib.erl:297: :io_lib.format(~c"unexpected ( after alias ~ts. Function names and identifiers in Elixir start with lowercase characters or underscore. For example:\n\n    hello_world()\n    _starting_with_underscore()\n    numb3rs_are_allowed()\n    may_finish_with_question_mark?()\n    may_finish_with_exclamation_mark!()\n\nUnexpected token: ", [{:atom, [], "Module"}])
    (elixir 1.17.2) src/elixir_tokenizer.erl:1366: :elixir_tokenizer.handle_terminator/6

Expected behavior

Not sure 😅

One one hand, this is a pretty weird edge case (I'm using the Elixir parser as the base to parse expressions provided by users), so it might be find just leaving it as is.

On the other hand, it would be nice to not raise and return:

{:error, {metadata, "unexpected ( after alias. Function names and identifiers...", "("}}

fertapric avatar Oct 23 '24 09:10 fertapric