diff --git a/rebar.lock b/rebar.lock index abc19a1..f1e6bf6 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,12 +1,17 @@ -{"1.1.0", +{"1.2.0", [{<<"aleppo">>,{pkg,<<"aleppo">>,<<"0.9.0">>},0}, {<<"ast_walk">>,{pkg,<<"ast_walk">>,<<"0.3.1">>},0}, {<<"efene">>,{pkg,<<"efene">>,<<"0.99.2">>},0}, - {<<"jsx">>,{pkg,<<"jsx">>,<<"2.9.0">>},0}]}. + {<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},0}]}. [ {pkg_hash,[ {<<"aleppo">>, <<"43B4EC269FA136E39DCECBD4323D4346E0EF069A62528A9154F1BB3ACD26E3E4">>}, {<<"ast_walk">>, <<"3E513446DCEF39ADB62DD578AEEA32E1DA6802482170A2E7500B2F0575E14ABF">>}, {<<"efene">>, <<"FC74F9506DBA3232B0C4D6A5494426FC6D1C73AB71CAD0D066E933E79BC1120E">>}, - {<<"jsx">>, <<"D2F6E5F069C00266CAD52FB15D87C428579EA4D7D73A33669E12679E203329DD">>}]} + {<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>}]}, +{pkg_hash_ext,[ + {<<"aleppo">>, <<"2F360631D64DA53F40621714E157FD33805A95D0160D5C62FCFB3E132986CE71">>}, + {<<"ast_walk">>, <<"9548DD7629FD9614F1520AFFDD05DB14E5A2103B7A91856EB4DACD84ED089C25">>}, + {<<"efene">>, <<"4796846239DB628F4180848FFBDD0EACA54D5EA472AAC34EE621810EF91C34AC">>}, + {<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>}]} ]. diff --git a/src/erlplorer.fn b/src/erlplorer.fn index 1b028e7..2f47f0a 100644 --- a/src/erlplorer.fn +++ b/src/erlplorer.fn @@ -27,6 +27,12 @@ fn main @public io.format("Error: ~p~n", [Error]) erlang.halt(0) end + case "count-atoms" :: Paths: + StateOut = lists.foldl({}, Paths) <<- case Path, StateIn: + count_atoms(Path, StateIn) + end + + format_atom_count(StateOut) case Args: io.format("Unknown Arguments: ~p~n", [Args]) usage() @@ -151,7 +157,7 @@ end fn search_path case Path, QMod: match parse_file(Path): case ok, Ast: - State0 = {filename: Path} + State0 = {} Walker = fn QMod.walk:2 ast_walk.walk(Ast, Walker, State0) case error, Reason: @@ -159,6 +165,33 @@ fn search_path case Path, QMod: end end +fn walk_count_atoms +case State, Ast = (atom, _Anno, Atom): + (Ast, maps.update_with(Atom, fn case V: V + 1 end, 1, State)) +case State, Ast: + (Ast, State) +end + +fn count_atoms case Path, StateIn: + match parse_file(Path): + case ok, Ast: + Walker = fn walk_count_atoms:2 + (_, State1) = ast_walk.walk(Ast, Walker, StateIn) + State1 + case error, Reason: + io.format("Error parsing ~s: ~p", [Path, Reason]) + StateIn + end +end + +fn format_atom_count case State: + AtomList0 = maps.to_list(State) + AtomListSorted = lists.sort(fn case (_, A), (_, B): A <= B end, AtomList0) + for (Atom, Count) in AtomListSorted: + io.format("~p: ~p~n", [Atom, Count]) + end +end + fn parse_file case Path: match lists.reverse(Path): case "lre." ++ _: