Skip to content
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
12 changes: 6 additions & 6 deletions lib/rouge/lexers/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,27 @@ def self.detect?(text)

state :sigil_strings do
# ~-sigiled strings
# ~(abc), ~[abc], ~<abc>, ~|abc|, ~r/abc/, etc
# ~r(abc), ~r[abc], ~r<abc>, ~r|abc|, ~r/abc/, etc
# Cribbed and adjusted from Ruby lexer
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
# Match a-z for custom sigils too
sigil_opens = Regexp.union(delimiter_map.keys + %w(| / ' "))
rule %r/~([A-Za-z])?(#{sigil_opens})/ do |m|
# Match [a-z] or [A-Z][A-Z0-9]* for custom sigils too
rule %r/~([a-z]|[A-Z][A-Z0-9]*)(#{sigil_opens})/ do |m|
open = Regexp.escape(m[2])
close = Regexp.escape(delimiter_map[m[2]] || m[2])
interp = /[SRCW]/ === m[1]
interp = /^[srcw]$/ === m[1]
toktype = Str::Other

puts " open: #{open.inspect}" if @debug
puts " close: #{close.inspect}" if @debug

# regexes
if 'Rr'.include? m[1]
if m[1] == 'r' || m[1] == 'R'
toktype = Str::Regex
push :regex_flags
end

if 'Ww'.include? m[1]
if m[1] == 'w' || m[1] == 'W'
push :list_flags
end

Expand Down
19 changes: 12 additions & 7 deletions spec/visual/samples/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ string |> String.split(~r/[ -]/) |> Enum.map(&abbreviate_word/1) |> Enum.join()
~c||
~c//

~S(inter #{pol <> "ati#{o}"} n)
~S[inter #{pol <> "ati#{o}"} n]
~S<inter #{pol <> "ati#{o}"} n>
~S'inter #{pol <> "ati#{o}"} n'
~S"inter #{pol <> "ati#{o}"} n"
~S|inter #{pol <> "ati#{o}"} n|
~S/inter #{pol <> "ati#{o}"} n/
~s(inter #{pol <> "ati#{o}"} n)
~s[inter #{pol <> "ati#{o}"} n]
~s<inter #{pol <> "ati#{o}"} n>
~s'inter #{pol <> "ati#{o}"} n'
~s"inter #{pol <> "ati#{o}"} n"
~s|inter #{pol <> "ati#{o}"} n|
~s/inter #{pol <> "ati#{o}"} n/

# custom sigils
~i(13)
~CUSTOM(custom uppercase)
~ABC123(with digits)

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