Skip to content

yilun-lee/minigrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minigrep

This is my minigrep tool made only for learning rust, trying to learn from the famous ripgrep. It is aimed to provided similar functionality with grep. But for now it is still work in progress. There are currently two crate here. First is argtool, for parse sys arg, used by minigrep. The other is grep, the main program for minigrep.

grep

Installation

# cd to this repo
cargo build --release
# This is binary location
./target/release/minigrep -h

Current usage

Basic pattern

./minigrep "YourPattern" "YourDir/*"

Print all fn in codes.

./target/release/minigrep "fn" "minigrep/*" 

Print help

./target/release/minigrep -h
./target/release/minigrep --help

Print with line number and the following two line.

./target/release/minigrep "fn" "minigrep/*" -n -B 2

Multiple match: struct, trait, and enum

./target/release/minigrep "trait" "minigrep/*" -n  -M "struct" -M "enum" -B 3 -A 1

Extract match pattern, here the pattern is function name
🪲: There are some wrong behavior in extract, need capture group. If parenthesis is added, that is "fn [A-Za-z0-9_]+\(" Some of matched line will be empty.

./target/release/minigrep "fn" "minigrep/*" -n -E "fn [A-Za-z0-9_]+"

Replace -> with ==>
🪲: if replacer is --> there will be error. - need to be escaped. We need "\->" for -R only, there is no need to specify it twice.

./target/release/minigrep "\->" "minigrep/*" -n -R "\->" -r "==>"

Benchmark

Done by hyperfine! It is still slow compared to ripgrep, at least close to grep. Keep working! benchmark

argtool

My argparser. Go to github page generated by rust docs

About

A argparser and minigrep implemented in rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published