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

add halfway support for multiline elixir sigils #2052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/rouge/lexers/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def self.detect?(text)
# Cribbed and adjusted from Ruby lexer
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
# Match a-z for custom sigils too
sigil_opens = Regexp.union(delimiter_map.keys + %w(| / ' "))
sigil_opens = Regexp.union(delimiter_map.keys + [%r/"{3}/] + %w(| / ' "))
rule %r/~([A-Za-z])?(#{sigil_opens})/ do |m|
open = Regexp.escape(m[2])
close = Regexp.escape(delimiter_map[m[2]] || m[2])
Expand All @@ -123,12 +123,18 @@ def self.detect?(text)
push :list_flags
end

if open == '"""'
toktype = Str::Doc
end

token toktype

push do
rule %r/#{close}/, toktype, :pop!

if interp
if toktype == Str::Doc
rule %r/(?:.|\n)*?"""/, toktype, :pop!
elsif interp
mixin :interpoling
rule %r/#/, toktype
else
Expand Down
15 changes: 15 additions & 0 deletions spec/visual/samples/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ string |> String.split(~r/[ -]/) |> Enum.map(&abbreviate_word/1) |> Enum.join()
~S|inter #{pol <> "ati#{o}"} n|
~S/inter #{pol <> "ati#{o}"} n/

# multiline sigil
~S"""
Converts double-quotes to single-quotes.

## Examples

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

~H"""
Current temperature: <%= @temperature %>°F
<button phx-click="inc_temperature">+</button>
"""

# first is Operator, second is &1 variable
&(&1)

Expand Down
Loading