Skip to content

Commit 6ed8acd

Browse files
committed
Rename source -> raw
1 parent 7fe9bcc commit 6ed8acd

File tree

15 files changed

+100
-100
lines changed

15 files changed

+100
-100
lines changed

Diff for: docs/cheatsheets/adoption.cheatmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ end
7474

7575
### Wrapping Raw Specs
7676

77-
You can make existing raw match specs play nice with `Matcha` APIs using [`Matcha.Spec.from_source!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_source!/2)
77+
You can make existing raw match specs play nice with `Matcha` APIs using [`Matcha.Spec.from_raw!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_raw!/2)
7878

7979
```elixir
8080
raw_spec = [{{:"$1", :"$2"}, [{:>, :"$1", 10}], [:"$_"]}]
81-
matcha_spec = Matcha.Spec.from_source!(:table, raw_spec)
81+
matcha_spec = Matcha.Spec.from_raw!(:table, raw_spec)
8282
```
8383

8484
## Using Matcha Specs

Diff for: docs/guides/adoption.livemd

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ If you want to convince yourself that these do the same thing, see _"Reading Raw
9999

100100
## Wrapping Raw Specs
101101

102-
If you are not using the [`Macro.spec/1`](https://hexdocs.pm/matcha/Matcha.html#spec/2) macro to build your specs, you can still wrap existing ones for usage with `Matcha` APIs: provide them to [`Matcha.Spec.from_source!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_source!/2) to get a `Matcha.Spec` struct. For example:
102+
If you are not using the [`Macro.spec/1`](https://hexdocs.pm/matcha/Matcha.html#spec/2) macro to build your specs, you can still wrap existing ones for usage with `Matcha` APIs: provide them to [`Matcha.Spec.from_raw!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_raw!/2) to get a `Matcha.Spec` struct. For example:
103103

104104
```elixir
105105
raw_spec = [{{:"$1", :"$2"}, [{:>, :"$1", 10}], [:"$_"]}]
106-
matcha_spec = Matcha.Spec.from_source!(:table, raw_spec)
106+
matcha_spec = Matcha.Spec.from_raw!(:table, raw_spec)
107107
```
108108

109109
## Testing Specs With Erlang APIs
@@ -115,7 +115,7 @@ matcha_spec = Matcha.Spec.from_source!(:table, raw_spec)
115115
At this point, you have `Matcha.Spec` structs you want to use, either from:
116116

117117
- Using the [`Matcha.spec/1`](https://hexdocs.pm/matcha/Matcha.html#spec/2) macro to build them
118-
- Using [`Matcha.Spec.from_source!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_source!/2) to wrap existing ones
118+
- Using [`Matcha.Spec.from_raw!/2`](https://hexdocs.pm/matcha/Matcha.Spec.html#from_raw!/2) to wrap existing ones
119119

120120
<!-- livebook:{"break_markdown":true} -->
121121

Diff for: lib/matcha/context.ex

+11-11
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule Matcha.Context do
7070
end
7171

7272
alias Matcha.Error
73-
alias Matcha.Source
73+
alias Matcha.Raw
7474

7575
alias Matcha.Spec
7676

@@ -95,12 +95,12 @@ defmodule Matcha.Context do
9595
@doc """
9696
Which primitive Erlang context this context module wraps.
9797
"""
98-
@callback __erl_spec_type__() :: Source.type()
98+
@callback __erl_spec_type__() :: Raw.type()
9999

100100
@doc """
101101
A default value to use when executing match specs in this context.
102102
103-
This function is used to provide `Matcha.Source.test/3` with a target value to test against,
103+
This function is used to provide `Matcha.Raw.test/3` with a target value to test against,
104104
in situations where it is being used to simply validate the match spec itself,
105105
but we do not acutally care if the input matches the spec.
106106
@@ -112,8 +112,8 @@ defmodule Matcha.Context do
112112
@doc """
113113
A validator that runs before executing a match spec against a `target` in this context.
114114
115-
This validator is run before any match specs are executed on inputs to `Matcha.Source.test/3`,
116-
and all elements of the enumerable input to `Matcha.Source.run/2`.
115+
This validator is run before any match specs are executed on inputs to `Matcha.Raw.test/3`,
116+
and all elements of the enumerable input to `Matcha.Raw.run/2`.
117117
118118
If this function returns false, the match spec will not be executed, instead
119119
returning a `t:Matcha.Error.error_problem` with a `t:Matcha.Error.message`
@@ -141,8 +141,8 @@ defmodule Matcha.Context do
141141
- `c:__transform_erl_test_result__/1`
142142
- `c:__emit_erl_test_result__/1`
143143
"""
144-
@callback __prepare_source__(source :: Source.uncompiled()) ::
145-
{:ok, new_source :: Source.uncompiled()} | {:error, Error.problems()}
144+
@callback __prepare_source__(source :: Raw.uncompiled()) ::
145+
{:ok, new_source :: Raw.uncompiled()} | {:error, Error.problems()}
146146
@doc """
147147
Transforms the result of a spec match just after calling `:erlang.match_spec_test/3`.
148148
@@ -252,8 +252,8 @@ defmodule Matcha.Context do
252252
results =
253253
if supports_compilation?(context) do
254254
source
255-
|> Source.compile()
256-
|> Source.run(match_targets)
255+
|> Raw.compile()
256+
|> Raw.run(match_targets)
257257
else
258258
do_run_without_compilation(match_targets, spec, source)
259259
end
@@ -353,7 +353,7 @@ defmodule Matcha.Context do
353353
test(spec, context.__default_match_target__())
354354
end
355355

356-
@spec test(Spec.t(), Source.match_target()) ::
356+
@spec test(Spec.t(), Raw.match_target()) ::
357357
{:ok, any} | {:error, Error.problems()}
358358
@doc """
359359
Tests that the provided `spec` in its `Matcha.Context` correctly matches a provided `match_target`.
@@ -381,7 +381,7 @@ defmodule Matcha.Context do
381381

382382
defp do_test(source, context, match_target) do
383383
source
384-
|> Source.test(context.__erl_spec_type__(), match_target)
384+
|> Raw.test(context.__erl_spec_type__(), match_target)
385385
|> context.__transform_erl_test_result__()
386386
end
387387
end

Diff for: lib/matcha/filter.ex

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ defmodule Matcha.Filter do
88
alias Matcha.Context
99
alias Matcha.Error
1010
alias Matcha.Rewrite
11-
alias Matcha.Source
11+
alias Matcha.Raw
1212

1313
alias Matcha.Spec
1414

1515
import Kernel, except: [match?: 2]
1616

17-
defstruct [:source, :bindings]
17+
defstruct [:raw, :bindings]
1818

1919
@test_spec_context Matcha.Context.Match
2020
@default_to_spec_context @test_spec_context
2121

2222
@type t :: %__MODULE__{
23-
source: Source.filter(),
23+
raw: Raw.filter(),
2424
bindings: %{atom() => term()}
2525
}
2626

27-
@spec raw(t()) :: Source.filter()
28-
def raw(%__MODULE__{source: source} = _filter) do
29-
source
27+
@spec raw(t()) :: Raw.filter()
28+
def raw(%__MODULE__{raw: raw} = _filter) do
29+
raw
3030
end
3131

3232
@spec bindings(t()) :: %{atom() => non_neg_integer()}

Diff for: lib/matcha/pattern.ex

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ defmodule Matcha.Pattern do
88
alias Matcha.Context
99
alias Matcha.Error
1010
alias Matcha.Rewrite
11-
alias Matcha.Source
11+
alias Matcha.Raw
1212

1313
alias Matcha.Spec
1414

1515
import Kernel, except: [match?: 2]
1616

17-
defstruct [:source, :bindings]
17+
defstruct [:raw, :bindings]
1818

1919
@test_spec_context Matcha.Context.Match
2020
@default_to_spec_context @test_spec_context
2121

2222
@type t :: %__MODULE__{
23-
source: Source.pattern(),
23+
raw: Raw.pattern(),
2424
bindings: %{atom() => term()}
2525
}
2626

27-
@spec raw(t()) :: Source.pattern()
28-
def raw(%__MODULE__{source: source} = _pattern) do
29-
source
27+
@spec raw(t()) :: Raw.pattern()
28+
def raw(%__MODULE__{raw: raw} = _pattern) do
29+
raw
3030
end
3131

3232
@spec bindings(t()) :: %{atom() => non_neg_integer()}

Diff for: lib/matcha/rewrite.ex

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Matcha.Rewrite do
88

99
alias Matcha.Context
1010
alias Matcha.Error
11-
alias Matcha.Source
11+
alias Matcha.Raw
1212

1313
alias Matcha.Pattern
1414
alias Matcha.Filter
@@ -26,7 +26,7 @@ defmodule Matcha.Rewrite do
2626
}
2727
}
2828

29-
@spec code(t()) :: Source.uncompiled()
29+
@spec code(t()) :: Raw.uncompiled()
3030
def code(%Rewrite{code: code} = _rewrite) do
3131
code
3232
end
@@ -47,16 +47,16 @@ defmodule Matcha.Rewrite do
4747
# Rewrite Elixir AST to Macha constructs
4848

4949
def build_pattern(env = %Macro.Env{}, pattern) do
50-
{source, bindings} =
50+
{raw, bindings} =
5151
%Rewrite{env: env, code: pattern}
5252
|> pattern(pattern)
5353

54-
source = Macro.escape(source, unquote: true)
54+
raw = Macro.escape(raw, unquote: true)
5555
bindings = Macro.escape(bindings, unquote: true)
5656

5757
quote location: :keep do
5858
%Matcha.Pattern{
59-
source: unquote(source),
59+
raw: unquote(raw),
6060
bindings: unquote(bindings)
6161
}
6262
|> Matcha.Pattern.validate!()
@@ -78,16 +78,16 @@ defmodule Matcha.Rewrite do
7878
end
7979

8080
def build_filter(env = %Macro.Env{}, filter) do
81-
{source, bindings} =
81+
{raw, bindings} =
8282
%Rewrite{env: env, code: filter}
8383
|> filter(filter)
8484

85-
source = Macro.escape(source, unquote: true)
85+
raw = Macro.escape(raw, unquote: true)
8686
bindings = Macro.escape(bindings, unquote: true)
8787

8888
quote location: :keep do
8989
%Matcha.Filter{
90-
source: unquote(source),
90+
raw: unquote(raw),
9191
bindings: unquote(bindings)
9292
}
9393
|> Matcha.Filter.validate!()
@@ -163,20 +163,20 @@ defmodule Matcha.Rewrite do
163163
|> perform_expansion(env)
164164
|> Context.resolve()
165165

166-
{source, bindings} =
166+
{raw, bindings} =
167167
%Rewrite{env: env, context: context, code: clauses}
168168
|> spec(clauses)
169169
|> Enum.with_index()
170-
|> Enum.reduce({[], %{}}, fn {{clause, bindings}, index}, {source, all_bindings} ->
171-
{[clause | source], Map.put(all_bindings, index, bindings)}
170+
|> Enum.reduce({[], %{}}, fn {{clause, bindings}, index}, {raw, all_bindings} ->
171+
{[clause | raw], Map.put(all_bindings, index, bindings)}
172172
end)
173173

174-
source = Macro.escape(:lists.reverse(source), unquote: true)
174+
raw = Macro.escape(:lists.reverse(raw), unquote: true)
175175
bindings = Macro.escape(bindings)
176176

177177
quote location: :keep do
178178
%Matcha.Spec{
179-
source: unquote(source),
179+
raw: unquote(raw),
180180
context: unquote(context),
181181
bindings: unquote(bindings)
182182
}
@@ -315,7 +315,7 @@ defmodule Matcha.Rewrite do
315315
@spec pattern_to_spec(Context.t(), Pattern.t()) :: {:ok, Spec.t()} | {:error, Error.problems()}
316316
def pattern_to_spec(context, %Pattern{} = pattern) do
317317
%Spec{
318-
source: [{Pattern.raw(pattern), [], [Source.__match_all__()]}],
318+
raw: [{Pattern.raw(pattern), [], [Raw.__match_all__()]}],
319319
context: Context.resolve(context),
320320
bindings: %{0 => pattern.bindings}
321321
}
@@ -326,7 +326,7 @@ defmodule Matcha.Rewrite do
326326
{:ok, Spec.t()} | {:error, Error.problems()}
327327
def pattern_to_matched_variables_spec(context, %Pattern{} = pattern) do
328328
%Spec{
329-
source: [{Pattern.raw(pattern), [], [Source.__all_matches__()]}],
329+
raw: [{Pattern.raw(pattern), [], [Raw.__all_matches__()]}],
330330
context: Context.resolve(context),
331331
bindings: %{0 => pattern.bindings}
332332
}
@@ -338,7 +338,7 @@ defmodule Matcha.Rewrite do
338338
{match, conditions} = Filter.raw(filter)
339339

340340
%Spec{
341-
source: [{match, conditions, [Source.__match_all__()]}],
341+
raw: [{match, conditions, [Raw.__match_all__()]}],
342342
context: Context.resolve(context),
343343
bindings: %{0 => filter.bindings}
344344
}
@@ -351,7 +351,7 @@ defmodule Matcha.Rewrite do
351351
{match, conditions} = Filter.raw(filter)
352352

353353
%Spec{
354-
source: [{match, conditions, [Source.__all_matches__()]}],
354+
raw: [{match, conditions, [Raw.__all_matches__()]}],
355355
context: Context.resolve(context),
356356
bindings: %{0 => filter.bindings}
357357
}

Diff for: lib/matcha/rewrite/bindings.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Matcha.Rewrite.Bindings do
77
"""
88

99
alias Matcha.Rewrite
10-
alias Matcha.Source
10+
alias Matcha.Raw
1111

1212
import Matcha.Rewrite.AST, only: :macros
1313

@@ -44,7 +44,7 @@ defmodule Matcha.Rewrite.Bindings do
4444
end
4545

4646
def bound_var_to_source(_rewrite, 0) do
47-
Source.__match_all__()
47+
Raw.__match_all__()
4848
end
4949

5050
def bound_var_to_source(_rewrite, integer) when is_integer(integer) and integer > 0 do

Diff for: lib/matcha/source.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Matcha.Source do
1+
defmodule Matcha.Raw do
22
@moduledoc """
33
Functions that work with the raw Erlang terms representing a match spec.
44

0 commit comments

Comments
 (0)