1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
%%
%% Demo file for the Syntax Tools package.
%%
%% The program is self-instructing. Compile `demo' from the shell and
%% execute `demo:run()'.
-module(demo).
-export([run/0, run_1/0, run_2/0, run_3/0, run_4/0,
view/1, view/2, view/3]).
small_file() -> "test.erl".
medium_file() -> "test_comprehensions.erl".
big_file() -> "erl_comment_scan.erl".
run() ->
make:all([load]),
io:fwrite("\n\n** Enter `demo:run_1()' to parse and pretty-print\n"
"the file \"~s\" with the default field width.\n\n",
[small_file()]),
ok.
run_1() ->
view(small_file()),
io:fwrite("\n\n\n** Enter `demo:run_2()' to parse and pretty-print\n"
"the file \"~s\" with a small field width.\n\n",
[small_file()]),
ok.
run_2() ->
view(small_file(), 15),
io:fwrite("\n\n\n** Enter `demo:run_3()' to parse and pretty-print\n"
"the file \"~s\" with field width 35\n\n",
[medium_file()]),
ok.
run_3() ->
view(medium_file(), 35),
io:fwrite("\n\n\n** Enter `demo:run_4()' to parse and pretty-print\n"
"the file \"~s\" with field width 55 and ribbon width 40.\n\n",
[big_file()]),
ok.
run_4() ->
view(big_file(), 55, 40),
io:fwrite("\n\n\n** Done! Now you can play around with the function\n"
"`demo:view(FileName, PaperWidth, RibbonWidth)' on any\n"
"Erlang source files you have around you.\n"
"(Include the \".erl\" suffix in the file name.\n"
"RibbonWidth and PaperWidth are optional.)\n\n"),
ok.
view(Name) ->
SyntaxTree = read(Name),
print(SyntaxTree).
view(Name, Paper) ->
SyntaxTree = read(Name),
print(SyntaxTree, Paper).
view(Name, Paper, Ribbon) ->
SyntaxTree = read(Name),
print(SyntaxTree, Paper, Ribbon).
print(SyntaxTree) ->
io:put_chars(erl_prettypr:format(SyntaxTree)).
print(SyntaxTree, Paper) ->
io:put_chars(erl_prettypr:format(SyntaxTree, [{paper, Paper}])).
print(SyntaxTree, Paper, Ribbon) ->
io:put_chars(erl_prettypr:format(SyntaxTree, [{paper, Paper},
{ribbon, Ribbon}])).
read(Name) ->
{ok, Forms} = epp:parse_file(Name, [], []),
Comments = erl_comment_scan:file(Name),
erl_recomment:recomment_forms(Forms, Comments).
|