Skip to content

Commit

Permalink
Use lib_elixir instead of vendoring elixir modules manually
Browse files Browse the repository at this point in the history
  • Loading branch information
doorgan committed Aug 8, 2024
1 parent 6027a3b commit b7e42b4
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 39,206 deletions.
21 changes: 10 additions & 11 deletions lib/sourceror.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Sourceror do
|> String.split("<!-- MDOC !-->")
|> Enum.fetch!(1)

alias Sourceror.LibElixir
alias Sourceror.TraversalState

@line_fields ~w[closing do end end_of_expression]a
Expand All @@ -24,12 +25,6 @@ defmodule Sourceror do

@type traversal_function :: (Macro.t(), TraversalState.t() -> {Macro.t(), TraversalState.t()})

@code_module (if Version.match?(System.version(), "~> 1.13") do
Code
else
Sourceror.Code
end)

@doc """
A wrapper around `Code.string_to_quoted_with_comments!/2` for compatibility
with pre 1.13 Elixir versions.
Expand All @@ -38,7 +33,7 @@ defmodule Sourceror do
map_literal_fix? = Version.match?(System.version(), "< 1.17.0")

quote bind_quoted: [
code_module: @code_module,
code_module: LibElixir.Code,
string: string,
opts: opts,
map_literal_fix?: map_literal_fix?
Expand All @@ -56,7 +51,7 @@ defmodule Sourceror do
map_literal_fix? = Version.match?(System.version(), "< 1.17.0")

quote bind_quoted: [
code_module: @code_module,
code_module: LibElixir.Code,
string: string,
opts: opts,
map_literal_fix?: map_literal_fix?
Expand Down Expand Up @@ -96,7 +91,7 @@ defmodule Sourceror do
Elixir versions.
"""
defmacro quoted_to_algebra(quoted, opts) do
quote bind_quoted: [code_module: @code_module, quoted: quoted, opts: opts] do
quote bind_quoted: [code_module: LibElixir.Code, quoted: quoted, opts: opts] do
if opts |> Keyword.get(:quoted_to_algebra) |> is_function(2) do
opts[:quoted_to_algebra].(quoted, opts)
else
Expand Down Expand Up @@ -539,7 +534,11 @@ defmodule Sourceror do
end

def get_start_position({_, meta, _}, default) do
position = Keyword.take(meta, [:line, :column])
line = Keyword.get(meta, :line, default[:line])
column = Keyword.get(meta, :column, default[:column])

position = [line: line, column: column]

Keyword.merge(default, position)
end

Expand All @@ -565,7 +564,7 @@ defmodule Sourceror do
...> end
...> "\"" |> Sourceror.parse_string!()
iex> Sourceror.get_end_position(quoted)
[line: 3, column: 1]
[line: 3, column: 3]
iex> quoted = ~S"\""
...> foo(
Expand Down
2 changes: 1 addition & 1 deletion lib/sourceror/identifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ defmodule Sourceror.Identifier do
iex> is_atomic_literal({:__block__, [], [{:node, [], nil}]})
false
iex> is_atomic_literal('foo')
iex> is_atomic_literal(~c'foo')
false
"""
@spec is_atomic_literal(Macro.t()) :: Macro.t()
Expand Down
Loading

0 comments on commit b7e42b4

Please sign in to comment.