Skip to content

Commit 45fe1cb

Browse files
ericmjJosé Valim
authored andcommitted
Expand attributes and macros in record extractor
Achieved by using :epp.parse_file/2 instead of :epp_dodger.quick_parse_file/1. Signed-off-by: José Valim <[email protected]>
1 parent 3f0e7c5 commit 45fe1cb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/elixir/lib/record/extractor.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ defmodule Record.Extractor do
4545
end
4646

4747
# Read a file and return its abstract syntax form that also
48-
# includes record and other preprocessor modules. This is done
49-
# by using Erlang's epp_dodger.
48+
# includes record but with macros and other attributes expanded,
49+
# such as `-include(...)` and `-include_lib(...)`. This is done
50+
# by using Erlang's epp.
5051
defp read_file(file) do
51-
case :epp_dodger.quick_parse_file(file) do
52+
case :epp.parse_file(file, []) do
5253
{:ok, form} ->
5354
form
5455
other ->
@@ -80,11 +81,11 @@ defmodule Record.Extractor do
8081

8182
defp eval_record(cons, form) do
8283
form = form ++
83-
[ {:function, 0, :hello, 0, [
84-
{:clause, 0, [], [], [ cons ]} ]} ]
84+
[{:function, 0, :hello, 0, [
85+
{:clause, 0, [], [], [cons]}]}]
8586

8687
{:function, 0, :hello, 0, [
87-
{:clause, 0, [], [], [ record_ast ]} ]} = :erl_expand_records.module(form, []) |> List.last
88+
{:clause, 0, [], [], [record_ast]}]} = :erl_expand_records.module(form, []) |> List.last
8889

8990
{:value, record, _} = :erl_eval.expr(record_ast, [])
9091
record

lib/elixir/test/elixir/record_test.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ defmodule RecordTest do
5252

5353
Record.defrecord :timestamp, [:date, :time]
5454
Record.defrecord :user, __MODULE__, name: "john", age: 25
55-
Record.defrecordp :file_info, Record.extract(:file_info, from_lib: "kernel/include/file.hrl")
55+
Record.defrecordp :file_info,
56+
Record.extract(:file_info, from_lib: "kernel/include/file.hrl")
57+
Record.defrecordp :certificate, :OTPCertificate,
58+
Record.extract(:OTPCertificate, from_lib: "public_key/include/public_key.hrl")
5659

5760
test "records generates macros that generates tuples" do
5861
record = user()

0 commit comments

Comments
 (0)