Skip to content

Commit c1c8eba

Browse files
committed
Tag / as an operator in fragments, closes #14643
1 parent 2350e83 commit c1c8eba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/elixir/lib/code/fragment.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ defmodule Code.Fragment do
302302
{{:local_or_var, acc}, count} -> {{:local_arity, acc}, count}
303303
{{:dot, base, acc}, count} -> {{:dot_arity, base, acc}, count}
304304
{{:operator, acc}, count} -> {{:operator_arity, acc}, count}
305-
{_, _} -> {:none, 0}
305+
{{:sigil, _}, _} -> {:none, 0}
306+
{_, _} -> {{:operator, ~c"/"}, 1}
306307
end
307308
end
308309

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ defmodule CodeFragmentTest do
302302
end
303303

304304
test "operators" do
305+
assert CF.cursor_context("/") == {:operator, ~c"/"}
305306
assert CF.cursor_context("+") == {:operator, ~c"+"}
306307
assert CF.cursor_context("++") == {:operator, ~c"++"}
307308
assert CF.cursor_context("!") == {:operator, ~c"!"}
@@ -361,6 +362,15 @@ defmodule CodeFragmentTest do
361362
assert CF.cursor_context("~r/") == :none
362363
assert CF.cursor_context("~r<") == :none
363364

365+
assert CF.cursor_context("~r''") == :none
366+
assert CF.cursor_context("~r' '") == :none
367+
assert CF.cursor_context("~r'foo'") == :none
368+
369+
# The slash is used in sigils, arities, and operators, so there is ambiguity
370+
assert CF.cursor_context("~r//") == {:operator, ~c"/"}
371+
assert CF.cursor_context("~r/ /") == {:operator, ~c"/"}
372+
assert CF.cursor_context("~r/foo/") == {:local_arity, ~c"foo"}
373+
364374
assert CF.cursor_context("~R") == {:sigil, ~c"R"}
365375
assert CF.cursor_context("~R/") == :none
366376
assert CF.cursor_context("~R<") == :none

0 commit comments

Comments
 (0)