init [skip ci]
This commit is contained in:
commit
3b694f13b5
11
.codecrafters/compile.sh
Executable file
11
.codecrafters/compile.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile your program on CodeCrafters
|
||||
#
|
||||
# This runs before .codecrafters/run.sh
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
set -e # Exit on failure
|
||||
|
||||
cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml
|
||||
11
.codecrafters/run.sh
Executable file
11
.codecrafters/run.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to run your program on CodeCrafters
|
||||
#
|
||||
# This runs after .codecrafters/compile.sh
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
set -e # Exit on failure
|
||||
|
||||
exec /tmp/codecrafters-grep-target/release/grep-starter-rust "$@"
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto
|
||||
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
79
Cargo.lock
generated
Normal file
79
Cargo.lock
generated
Normal file
@ -0,0 +1,79 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
|
||||
|
||||
[[package]]
|
||||
name = "grep-starter-rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
24
Cargo.toml
Normal file
24
Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
# DON'T EDIT THIS!
|
||||
#
|
||||
# Codecrafters relies on this file being intact to run tests successfully. Any changes
|
||||
# here will not reflect when CodeCrafters tests your code, and might even cause build
|
||||
# failures.
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
[package]
|
||||
name = "grep-starter-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["Codecrafters <hello@codecrafters.io>"]
|
||||
edition = "2021"
|
||||
|
||||
# DON'T EDIT THIS!
|
||||
#
|
||||
# Codecrafters relies on this file being intact to run tests successfully. Any changes
|
||||
# here will not reflect when CodeCrafters tests your code, and might even cause build
|
||||
# failures.
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
[dependencies]
|
||||
anyhow = "1.0.68" # error handling
|
||||
bytes = "1.3.0" # helps manage buffers
|
||||
thiserror = "1.0.38" # error handling
|
||||
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
||||
[](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
|
||||
|
||||
This is a starting point for Rust 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/main.rs`. 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 `cargo (1.62)` installed locally
|
||||
1. Run `./your_program.sh` to run your program, which is implemented in
|
||||
`src/main.rs`. This command compiles your Rust project, so it might be slow
|
||||
the first time you run it. Subsequent runs will be fast.
|
||||
1. Commit your changes and run `git push origin master` to submit your solution
|
||||
to CodeCrafters. Test output will be streamed to your terminal.
|
||||
11
codecrafters.yml
Normal file
11
codecrafters.yml
Normal file
@ -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 Rust version used to run your code
|
||||
# on Codecrafters.
|
||||
#
|
||||
# Available versions: rust-1.77
|
||||
language_pack: rust-1.77
|
||||
34
src/main.rs
Normal file
34
src/main.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::process;
|
||||
|
||||
fn match_pattern(input_line: &str, pattern: &str) -> bool {
|
||||
if pattern.chars().count() == 1 {
|
||||
return input_line.contains(pattern);
|
||||
} else {
|
||||
panic!("Unhandled pattern: {}", pattern)
|
||||
}
|
||||
}
|
||||
|
||||
// Usage: echo <input_text> | your_program.sh -E <pattern>
|
||||
fn main() {
|
||||
// You can use print statements as follows for debugging, they'll be visible when running tests.
|
||||
println!("Logs from your program will appear here!");
|
||||
|
||||
if env::args().nth(1).unwrap() != "-E" {
|
||||
println!("Expected first argument to be '-E'");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let pattern = env::args().nth(2).unwrap();
|
||||
let mut input_line = String::new();
|
||||
|
||||
io::stdin().read_line(&mut input_line).unwrap();
|
||||
|
||||
// Uncomment this block to pass the first stage
|
||||
// if match_pattern(&input_line, &pattern) {
|
||||
// process::exit(0)
|
||||
// } else {
|
||||
// process::exit(1)
|
||||
// }
|
||||
}
|
||||
24
your_program.sh
Executable file
24
your_program.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Use this script to run your program LOCALLY.
|
||||
#
|
||||
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
set -e # Exit early if any commands fail
|
||||
|
||||
# Copied from .codecrafters/compile.sh
|
||||
#
|
||||
# - Edit this to change how your program compiles locally
|
||||
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
|
||||
(
|
||||
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
|
||||
cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml
|
||||
)
|
||||
|
||||
# Copied from .codecrafters/run.sh
|
||||
#
|
||||
# - Edit this to change how your program runs locally
|
||||
# - Edit .codecrafters/run.sh to change how your program runs remotely
|
||||
exec /tmp/codecrafters-grep-target/release/grep-starter-rust "$@"
|
||||
Loading…
x
Reference in New Issue
Block a user