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

Elixir triple-quoted strings after a sigil sign produce unexpected results #2051

Open
bsmithgall opened this issue Jun 4, 2024 · 0 comments · May be fixed by #2052
Open

Elixir triple-quoted strings after a sigil sign produce unexpected results #2051

bsmithgall opened this issue Jun 4, 2024 · 0 comments · May be fixed by #2052
Labels
bugfix-request A request for a bugfix to be developed.

Comments

@bsmithgall
Copy link

Name of the lexer
Elixir

Code sample

This is taken from the elixir documentation about sigils and character escaping:

~S"""
Converts double-quotes to single-quotes.

## Examples

    iex> convert("\"foo\"")
    "'foo'"

"""

Link to jneen example: rouge.jneen.net.

Additional context

I wasn't sure whether to file this as a bug or feature request, but the primary driver here is adding support for HEEx templates, which were added to the Phoenix web framework somewhat recently. Those embed what is something like eex syntax directly inside of an Elixir .ex file.

Here is an example from the Phoenix LiveView getting started documentation:

defmodule MyAppWeb.ThermostatLive do
  # In Phoenix v1.6+ apps, the line is typically: use MyAppWeb, :live_view
  use Phoenix.LiveView

  def render(assigns) do
    ~H"""
    Current temperature: <%= @temperature %>°F
    <button phx-click="inc_temperature">+</button>
    """
  end

  def mount(_params, _session, socket) do
    temperature = 70 # Let's assume a fixed temperature for now
    {:ok, assign(socket, :temperature, temperature)}
  end

  def handle_event("inc_temperature", _params, socket) do
    {:noreply, update(socket, :temperature, &(&1 + 1))}
  end
end

(and relevant jneen link)

However, when I was exploring further, I realized that in general sigils that use """ delimiters also don't work as expected. I think adding support for HEEx completely (like, for example, in tree-sitter-heex) would be nice but difficult. In the short term, doing what GitHub does and ensuring that """-enclosed sigils are treated as strings would be great.

@bsmithgall bsmithgall added the bugfix-request A request for a bugfix to be developed. label Jun 4, 2024
@bsmithgall bsmithgall linked a pull request Jun 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant