-module(internal@ast). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([files_ast/1, files_paths_with_ast/2, is_pub_member_used/4]). -export_type([file_ast/0, another_files_ast/0, module_name/0, imported_info/0, public_member/0]). -type file_ast() :: {file_ast, glance:module_()}. -type another_files_ast() :: {another_files_ast, gleam@yielder:yielder(file_ast())}. -type module_name() :: {module_name, binary()}. -type imported_info() :: {module_imported, module_name()} | imported_as_alias. -type public_member() :: {public_fun, binary()} | {public_const, binary()} | {public_type, binary()}. -file("/Users/darky/Projects/cleam/src/internal/ast.gleam", 34). -spec files_ast(list(internal@fs:file_content())) -> list(file_ast()). files_ast(Files_contents) -> gleam@list:map( Files_contents, fun(Content) -> {file_content, Content@1} = Content, _assert_subject = glance:module(Content@1), {ok, Ast} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"internal/ast"/utf8>>, function => <<"files_ast"/utf8>>, line => 37}) end, {file_ast, Ast} end ). -file("/Users/darky/Projects/cleam/src/internal/ast.gleam", 41). -spec files_paths_with_ast( internal@fs:files_dir(), gleam@option:option(internal@fs:files_dir()) ) -> list({internal@fs:file_path(), file_ast(), another_files_ast()}). files_paths_with_ast(Dir, Test_dir) -> File_paths = internal@fs:files_paths(Dir), Flle_contents = internal@fs:files_contents(File_paths), Test_file_contents = case Test_dir of {some, {files_dir, _} = Test_dir@1} -> _pipe = internal@fs:files_paths(Test_dir@1), internal@fs:files_contents(_pipe); none -> [] end, Ast_list = begin _pipe@1 = Flle_contents, _pipe@2 = lists:append(_pipe@1, Test_file_contents), files_ast(_pipe@2) end, gleam@list:map( begin _pipe@3 = File_paths, gleam@list:zip(_pipe@3, Ast_list) end, fun(_use0) -> {File_path, File_ast} = _use0, {File_path, File_ast, {another_files_ast, begin _pipe@4 = Ast_list, _pipe@5 = gleam@yielder:from_list(_pipe@4), gleam@yielder:filter( _pipe@5, fun(Ast) -> File_ast /= Ast end ) end}} end ). -file("/Users/darky/Projects/cleam/src/internal/ast.gleam", 129). -spec module_full_name_to_module_name(internal@fs:module_full_name()) -> module_name(). module_full_name_to_module_name(Module_full_name) -> {module_full_name, Module_full_name@1} = Module_full_name, _assert_subject = begin _pipe = gleam@string:split(Module_full_name@1, <<"/"/utf8>>), gleam@list:last(_pipe) end, {ok, Module_name} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"internal/ast"/utf8>>, function => <<"module_full_name_to_module_name"/utf8>>, line => 131}) end, {module_name, Module_name}. -file("/Users/darky/Projects/cleam/src/internal/ast.gleam", 72). -spec imported_info( list(glance:definition(glance:import())), internal@fs:module_full_name(), public_member() ) -> list(imported_info()). imported_info(Imports, Module_full_name, Exported) -> gleam@list:filter_map(Imports, fun(Imp) -> case Imp of {definition, _, {import, Import_name, Module_alias, Type_aliases, Aliases}} when {module_full_name, Import_name} =:= Module_full_name -> case begin _pipe = Aliases, _pipe@1 = lists:append(_pipe, Type_aliases), gleam@list:any( _pipe@1, fun(Alias) -> {unqualified_import, Imported, _} = Alias, (({public_fun, Imported} =:= Exported) orelse ({public_const, Imported} =:= Exported)) orelse ({public_type, Imported} =:= Exported) end ) end of true -> {ok, imported_as_alias}; false -> case Module_alias of {some, {named, Alias@1}} -> {ok, {module_imported, {module_name, Alias@1}}}; {some, {discarded, _}} -> {error, nil}; none -> {ok, {module_imported, module_full_name_to_module_name( Module_full_name )}} end end; _ -> {error, nil} end end). -file("/Users/darky/Projects/cleam/src/internal/ast.gleam", 106). -spec is_pub_member_used( another_files_ast(), public_member(), internal@fs:module_full_name(), fun((list(glance:statement()), public_member(), module_name()) -> {ok, nil} | {error, any()}) ) -> {ok, nil} | {error, nil}. is_pub_member_used(Files_ast, Pub_member_name, Module_full_name, Check_usage) -> {another_files_ast, Files_ast@1} = Files_ast, gleam@yielder:find_map( Files_ast@1, fun(File_ast) -> {file_ast, Ast} = File_ast, {module, Imports, _, _, _, Fns} = Ast, Imported_info_list = imported_info( Imports, Module_full_name, Pub_member_name ), gleam@list:find_map( Imported_info_list, fun(Imported_info) -> case Imported_info of imported_as_alias -> {ok, nil}; {module_imported, Module_name} -> gleam@list:find_map( Fns, fun(Fun_def) -> {definition, _, {function, _, _, _, _, Statements, _}} = Fun_def, Check_usage( Statements, Pub_member_name, Module_name ) end ) end end ) end ).