From fb5595d20025a3d1cc24d402d010d659e268a4bb Mon Sep 17 00:00:00 2001 From: Vladislav Botvin Date: Tue, 25 Jun 2024 21:28:32 +0300 Subject: [PATCH] trim context during pipe --- gleam.toml | 2 +- manifest.toml | 4 ++-- src/glerd.gleam | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/gleam.toml b/gleam.toml index 8325e9c..6b2ea55 100644 --- a/gleam.toml +++ b/gleam.toml @@ -11,7 +11,7 @@ glance = ">= 0.11.0" gleam_stdlib = ">= 0.34.0 and < 2.0.0" gleamyshell = ">= 1.0.0" glexer = ">= 1.0.1 and < 2.0.0" -gluple = ">= 2.0.0" +gluple = ">= 2.2.0" simplifile = ">= 1.7.0" [dev-dependencies] diff --git a/manifest.toml b/manifest.toml index 1ef1504..535e45d 100644 --- a/manifest.toml +++ b/manifest.toml @@ -10,7 +10,7 @@ packages = [ { name = "gleamyshell", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleamyshell", source = "hex", outer_checksum = "48FEEDD643B6381817222D94DB94BD3803C4B3575911B73A8C8C96620F09DBCF" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, { name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" }, - { name = "gluple", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gluple", source = "hex", outer_checksum = "914CE96C09D55CF72B657DFFF10302D2038276125CC1F78656BCF4BBC4291A58" }, + { name = "gluple", version = "2.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gluple", source = "hex", outer_checksum = "7D61583F17EFBF26043C14A417FF56D1BC709A45F75BB499E35CA28C9C3A8EB9" }, { name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" }, ] @@ -21,5 +21,5 @@ gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } gleamyshell = { version = ">= 1.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } glexer = { version = ">= 1.0.1 and < 2.0.0" } -gluple = { version = ">= 2.0.0" } +gluple = { version = ">= 2.2.0" } simplifile = { version = ">= 1.7.0" } diff --git a/src/glerd.gleam b/src/glerd.gleam index 051a689..cdfebb3 100644 --- a/src/glerd.gleam +++ b/src/glerd.gleam @@ -12,6 +12,7 @@ import gleamyshell import glexer.{type Position, Position} import glexer/token.{CommentDoc, UpperName} import gluple/addition as ga +import gluple/removal as gr import simplifile type FilePath { @@ -65,7 +66,15 @@ pub fn generate(root) { #(file_path, content |> FileContent) }) |> iterator.map(fn(ctx) { - use _, file_content <- ga.with_append2(ctx) + use file_path, _ <- ga.with_append2(ctx) + file_path.val + |> string.replace(root <> "/", "") + |> string.replace(".gleam", "") + |> ModuleName + }) + |> iterator.map(fn(ctx) { ctx |> gr.remove_first3 }) + |> iterator.map(fn(ctx) { + use file_content, _ <- ga.with_append2(ctx) file_content.val |> glexer.new |> glexer.lex @@ -87,14 +96,7 @@ pub fn generate(root) { |> MetaDict }) |> iterator.map(fn(ctx) { - use file_path, _, _ <- ga.with_append3(ctx) - file_path.val - |> string.replace(root <> "/", "") - |> string.replace(".gleam", "") - |> ModuleName - }) - |> iterator.map(fn(ctx) { - use _, file_content, _, _ <- ga.with_append4(ctx) + use file_content, _, _ <- ga.with_append3(ctx) let assert Ok(module) = file_content.val |> glance.module let Module(_, custom_types_definitions, ..) = module use custom_type_definition <- list.flat_map(custom_types_definitions) @@ -102,8 +104,9 @@ pub fn generate(root) { let CustomType(_, _, _, _, variants) = custom_type variants }) + |> iterator.map(fn(ctx) { ctx |> gr.remove_first4 }) |> iterator.map(fn(ctx) { - let #(_, _, meta_dict, module_name, variants) = ctx + let #(module_name, meta_dict, variants) = ctx use Variant(record_name, fields) <- list.map(variants) let fields = fields