-module(oaspec@internal@codegen@ir_render). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/oaspec/internal/codegen/ir_render.gleam"). -export([render/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -file("src/oaspec/internal/codegen/ir_render.gleam", 46). ?DOC(false). -spec render_type_def( gleam@string_tree:string_tree(), oaspec@internal@codegen@ir:type_def() ) -> gleam@string_tree:string_tree(). render_type_def(Sb, Type_def) -> case Type_def of {type_alias, Name, Target} -> _pipe = Sb, _pipe@1 = oaspec@internal@util@string_extra:line( _pipe, <<<<<<"pub type "/utf8, Name/binary>>/binary, " = "/utf8>>/binary, Target/binary>> ), oaspec@internal@util@string_extra:blank_line(_pipe@1); {record_type, Name@1, Fields} -> Sb@1 = begin _pipe@2 = Sb, oaspec@internal@util@string_extra:line( _pipe@2, <<<<"pub type "/utf8, Name@1/binary>>/binary, " {"/utf8>> ) end, Field_strs = gleam@list:map( Fields, fun(F) -> <<<<(erlang:element(2, F))/binary, ": "/utf8>>/binary, (erlang:element(3, F))/binary>> end ), Sb@2 = begin _pipe@3 = Sb@1, oaspec@internal@util@string_extra:indent( _pipe@3, 1, <<<<<>/binary, (gleam@string:join(Field_strs, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ) end, _pipe@4 = Sb@2, _pipe@5 = oaspec@internal@util@string_extra:line( _pipe@4, <<"}"/utf8>> ), oaspec@internal@util@string_extra:blank_line(_pipe@5); {union_type, Name@2, Variants} -> Sb@3 = begin _pipe@6 = Sb, oaspec@internal@util@string_extra:line( _pipe@6, <<<<"pub type "/utf8, Name@2/binary>>/binary, " {"/utf8>> ) end, Sb@5 = gleam@list:fold( Variants, Sb@3, fun(Sb@4, Variant) -> case Variant of {variant_with_type, Vname, Inner_type} -> _pipe@7 = Sb@4, oaspec@internal@util@string_extra:indent( _pipe@7, 1, <<<<<>/binary, Inner_type/binary>>/binary, ")"/utf8>> ); {variant_empty, Vname@1} -> _pipe@8 = Sb@4, oaspec@internal@util@string_extra:indent( _pipe@8, 1, Vname@1 ); {variant_with_type_and_headers, Vname@2, Inner_type@1, Headers_type} -> _pipe@9 = Sb@4, oaspec@internal@util@string_extra:indent( _pipe@9, 1, <<<<<<<<<>/binary, Inner_type@1/binary>>/binary, ", "/utf8>>/binary, Headers_type/binary>>/binary, ")"/utf8>> ); {variant_with_headers, Vname@3, Headers_type@1} -> _pipe@10 = Sb@4, oaspec@internal@util@string_extra:indent( _pipe@10, 1, <<<<<>/binary, Headers_type@1/binary>>/binary, ")"/utf8>> ) end end ), _pipe@11 = Sb@5, _pipe@12 = oaspec@internal@util@string_extra:line( _pipe@11, <<"}"/utf8>> ), oaspec@internal@util@string_extra:blank_line(_pipe@12); {enum_type, Name@3, Variants@1} -> Sb@6 = begin _pipe@13 = Sb, oaspec@internal@util@string_extra:line( _pipe@13, <<<<"pub type "/utf8, Name@3/binary>>/binary, " {"/utf8>> ) end, Sb@8 = gleam@list:fold( Variants@1, Sb@6, fun(Sb@7, Variant_name) -> _pipe@14 = Sb@7, oaspec@internal@util@string_extra:indent( _pipe@14, 1, Variant_name ) end ), _pipe@15 = Sb@8, _pipe@16 = oaspec@internal@util@string_extra:line( _pipe@15, <<"}"/utf8>> ), oaspec@internal@util@string_extra:blank_line(_pipe@16) end. -file("src/oaspec/internal/codegen/ir_render.gleam", 34). ?DOC(false). -spec render_declaration( gleam@string_tree:string_tree(), oaspec@internal@codegen@ir:declaration() ) -> gleam@string_tree:string_tree(). render_declaration(Sb, Decl) -> Sb@1 = case oaspec@internal@codegen@ir:declaration_doc(Decl) of {some, Doc} -> _pipe = Sb, oaspec@internal@util@string_extra:doc_comment(_pipe, Doc); none -> Sb end, render_type_def(Sb@1, oaspec@internal@codegen@ir:declaration_type_def(Decl)). -file("src/oaspec/internal/codegen/ir_render.gleam", 101). ?DOC(false). -spec render_header_record( gleam@string_tree:string_tree(), oaspec@internal@codegen@ir:response_header_record() ) -> gleam@string_tree:string_tree(). render_header_record(Sb, Rec) -> Name = erlang:element(2, Rec), Field_strs = gleam@list:map( erlang:element(3, Rec), fun(F) -> <<<<(erlang:element(2, F))/binary, ": "/utf8>>/binary, (erlang:element(3, F))/binary>> end ), _pipe = Sb, _pipe@1 = oaspec@internal@util@string_extra:line( _pipe, <<<<"pub type "/utf8, Name/binary>>/binary, " {"/utf8>> ), _pipe@2 = oaspec@internal@util@string_extra:indent( _pipe@1, 1, <<<<<>/binary, (gleam@string:join(Field_strs, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ), _pipe@3 = oaspec@internal@util@string_extra:line(_pipe@2, <<"}"/utf8>>), oaspec@internal@util@string_extra:blank_line(_pipe@3). -file("src/oaspec/internal/codegen/ir_render.gleam", 15). ?DOC(false). -spec render(oaspec@internal@codegen@ir:module_()) -> binary(). render(Module) -> Sb = begin _pipe = oaspec@internal@util@string_extra:file_header(<<"0.34.0"/utf8>>), oaspec@internal@util@string_extra:imports( _pipe, oaspec@internal@codegen@ir:module_imports(Module) ) end, Sb@2 = gleam@list:fold( oaspec@internal@codegen@ir:module_declarations(Module), Sb, fun(Sb@1, Decl) -> render_declaration(Sb@1, Decl) end ), Sb@4 = gleam@list:fold( oaspec@internal@codegen@ir:module_header_records(Module), Sb@2, fun(Sb@3, Rec) -> render_header_record(Sb@3, Rec) end ), oaspec@internal@util@string_extra:to_string(Sb@4).