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