diff --git a/compiled_starters/gleam/.gitattributes b/compiled_starters/gleam/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/gleam/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/gleam/.gitignore b/compiled_starters/gleam/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/compiled_starters/gleam/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/compiled_starters/gleam/README.md b/compiled_starters/gleam/README.md new file mode 100644 index 0000000..33ba3ae --- /dev/null +++ b/compiled_starters/gleam/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for Gleam solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/grep.gleam`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/grep.gleam`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/compiled_starters/gleam/codecrafters.yml b/compiled_starters/gleam/codecrafters.yml new file mode 100644 index 0000000..0ed6333 --- /dev/null +++ b/compiled_starters/gleam/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.0 +language_pack: gleam-1.0 diff --git a/compiled_starters/gleam/gleam.toml b/compiled_starters/gleam/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/compiled_starters/gleam/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/compiled_starters/gleam/manifest.toml b/compiled_starters/gleam/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/compiled_starters/gleam/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/compiled_starters/gleam/src/grep.gleam b/compiled_starters/gleam/src/grep.gleam new file mode 100644 index 0000000..cd130bb --- /dev/null +++ b/compiled_starters/gleam/src/grep.gleam @@ -0,0 +1,38 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this to pass the first stage + // let args = argv.load().arguments + // let assert Ok(input_line) = erlang.get_line("") + // case args { + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") + // } + // _ -> { + // io.println("Expected first argument to be '-E'") + // } + // } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/compiled_starters/gleam/your_grep.sh b/compiled_starters/gleam/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/compiled_starters/gleam/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file diff --git a/dockerfiles/gleam-1.0.Dockerfile b/dockerfiles/gleam-1.0.Dockerfile new file mode 100644 index 0000000..2d62298 --- /dev/null +++ b/dockerfiles/gleam-1.0.Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine + +# Pre-compile steps +RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && gleam build" > /codecrafters-precompile.sh +RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/gleam/01-cq2/code/.gitattributes b/solutions/gleam/01-cq2/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/gleam/01-cq2/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/gleam/01-cq2/code/.gitignore b/solutions/gleam/01-cq2/code/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/solutions/gleam/01-cq2/code/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/solutions/gleam/01-cq2/code/README.md b/solutions/gleam/01-cq2/code/README.md new file mode 100644 index 0000000..33ba3ae --- /dev/null +++ b/solutions/gleam/01-cq2/code/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for Gleam solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/grep.gleam`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/grep.gleam`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/gleam/01-cq2/code/codecrafters.yml b/solutions/gleam/01-cq2/code/codecrafters.yml new file mode 100644 index 0000000..0ed6333 --- /dev/null +++ b/solutions/gleam/01-cq2/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.0 +language_pack: gleam-1.0 diff --git a/solutions/gleam/01-cq2/code/gleam.toml b/solutions/gleam/01-cq2/code/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/solutions/gleam/01-cq2/code/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/solutions/gleam/01-cq2/code/manifest.toml b/solutions/gleam/01-cq2/code/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/solutions/gleam/01-cq2/code/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/solutions/gleam/01-cq2/code/src/grep.gleam b/solutions/gleam/01-cq2/code/src/grep.gleam new file mode 100644 index 0000000..0cf803e --- /dev/null +++ b/solutions/gleam/01-cq2/code/src/grep.gleam @@ -0,0 +1,34 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") + } + } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/solutions/gleam/01-cq2/code/your_grep.sh b/solutions/gleam/01-cq2/code/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/solutions/gleam/01-cq2/code/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file diff --git a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff new file mode 100644 index 0000000..1f36180 --- /dev/null +++ b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff @@ -0,0 +1,53 @@ +@@ -1,38 +1,34 @@ + import argv + import gleam/io + import gleam/string + import gleam/erlang + + pub fn main() { +- // You can use print statements as follows for debugging, they'll be visible when running tests. +- io.println("Logs from your program will appear here!") +- +- // Uncomment this to pass the first stage +- // let args = argv.load().arguments +- // let assert Ok(input_line) = erlang.get_line("") +- // case args { +- // ["-E", pattern, ..] -> { +- // case match_pattern(input_line, pattern) { +- // True -> exit(0) +- // False -> exit(1) +- // } +- // io.println("Success") +- // } +- // _ -> { +- // io.println("Expected first argument to be '-E'") +- // } +- // } ++ let args = argv.load().arguments ++ let assert Ok(input_line) = erlang.get_line("") ++ case args { ++ ["-E", pattern, ..] -> { ++ case match_pattern(input_line, pattern) { ++ True -> exit(0) ++ False -> exit(1) ++ } ++ io.println("Success") ++ } ++ _ -> { ++ io.println("Expected first argument to be '-E'") ++ } ++ } + } + + fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } + } + + @external(erlang, "erlang", "halt") + pub fn exit(code: Int) -> Int diff --git a/solutions/gleam/01-cq2/explanation.md b/solutions/gleam/01-cq2/explanation.md new file mode 100644 index 0000000..27d7eba --- /dev/null +++ b/solutions/gleam/01-cq2/explanation.md @@ -0,0 +1,29 @@ +The entry point for your grep implementation is in `src/grep.gleam`. + +Study and uncomment the relevant code: + +```gleam +// Uncomment this to pass the first stage +let args = argv.load().arguments +let assert Ok(input_line) = erlang.get_line("") +case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") + } +} +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index fd58c69..037aacf 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -193,3 +193,25 @@ template_attributes: required_executable: "bun (1.1)" user_editable_file: "app/main.ts" + +- language: gleam + file_mappings: + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/gleam/src/grep.gleam + target: src/grep.gleam + - source: starter_templates/gleam/.gitignore + target: .gitignore + - source: starter_templates/gleam/gleam.toml + target: gleam.toml + - source: starter_templates/gleam/manifest.toml + target: manifest.toml + - source: starter_templates/gleam/your_grep.sh + target: your_grep.sh + - source: starter_templates/.gitattributes + target: .gitattributes + template_attributes: + required_executable: "gleam (1.0)" + user_editable_file: "src/grep.gleam" diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index 26574a1..a182a87 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -79,3 +79,7 @@ language_pack: cpp-20 # Available versions: bun-1.1 language_pack: bun-1.1 {{/language_is_typescript}} +{{#language_is_gleam}} +# Available versions: gleam-1.0 +language_pack: gleam-1.0 +{{/language_is_gleam}} diff --git a/starter_templates/gleam/.gitignore b/starter_templates/gleam/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/starter_templates/gleam/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/starter_templates/gleam/gleam.toml b/starter_templates/gleam/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/starter_templates/gleam/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/starter_templates/gleam/manifest.toml b/starter_templates/gleam/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/starter_templates/gleam/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/starter_templates/gleam/src/grep.gleam b/starter_templates/gleam/src/grep.gleam new file mode 100644 index 0000000..cd130bb --- /dev/null +++ b/starter_templates/gleam/src/grep.gleam @@ -0,0 +1,38 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this to pass the first stage + // let args = argv.load().arguments + // let assert Ok(input_line) = erlang.get_line("") + // case args { + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") + // } + // _ -> { + // io.println("Expected first argument to be '-E'") + // } + // } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/starter_templates/gleam/src/tmp.gleam b/starter_templates/gleam/src/tmp.gleam new file mode 100644 index 0000000..9dffc29 --- /dev/null +++ b/starter_templates/gleam/src/tmp.gleam @@ -0,0 +1,32 @@ +import argv + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + let args = argv.load().arguments + input_line = io.read_line() + + // Uncomment this to pass the first stage + case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> io.exit(0) + False -> io.exit(1) + } + } + _ -> { + io.println("Expected first argument to be '-E'") + } + } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} \ No newline at end of file diff --git a/starter_templates/gleam/your_grep.sh b/starter_templates/gleam/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/starter_templates/gleam/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file