summaryrefslogtreecommitdiffstats
path: root/crates/grep
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2020-02-17 18:19:19 -0500
committerAndrew Gallant <jamslam@gmail.com>2020-02-17 19:24:53 -0500
commitfdd8510fdda6109c562e479c718d42c8ecc26263 (patch)
treef510c952f62d0ebdcbf689000b2d7aebc90d5ba7 /crates/grep
parent0bc4f0447b05468f043e06278a3ca2b1c5646f9b (diff)
repo: move all source code in crates directory
The top-level listing was just getting a bit too long for my taste. So put all of the code in one directory and shrink the large top-level mess to a small top-level mess. NOTE: This commit only contains renames. The subsequent commit will actually make ripgrep build again. We do it this way with the naive hope that this will make it easier for git history to track the renames. Sigh.
Diffstat (limited to 'crates/grep')
-rw-r--r--crates/grep/COPYING3
-rw-r--r--crates/grep/Cargo.toml32
-rw-r--r--crates/grep/LICENSE-MIT21
-rw-r--r--crates/grep/README.md41
-rw-r--r--crates/grep/UNLICENSE24
-rw-r--r--crates/grep/examples/simplegrep.rs72
-rw-r--r--crates/grep/src/lib.rs23
7 files changed, 216 insertions, 0 deletions
diff --git a/crates/grep/COPYING b/crates/grep/COPYING
new file mode 100644
index 00000000..bb9c20a0
--- /dev/null
+++ b/crates/grep/COPYING
@@ -0,0 +1,3 @@
+This project is dual-licensed under the Unlicense and MIT licenses.
+
+You may use this code under the terms of either license.
diff --git a/crates/grep/Cargo.toml b/crates/grep/Cargo.toml
new file mode 100644
index 00000000..d37ceff7
--- /dev/null
+++ b/crates/grep/Cargo.toml
@@ -0,0 +1,32 @@
+[package]
+name = "grep"
+version = "0.2.4" #:version
+authors = ["Andrew Gallant <jamslam@gmail.com>"]
+description = """
+Fast line oriented regex searching as a library.
+"""
+documentation = "http://burntsushi.net/rustdoc/grep/"
+homepage = "https://github.com/BurntSushi/ripgrep"
+repository = "https://github.com/BurntSushi/ripgrep"
+readme = "README.md"
+keywords = ["regex", "grep", "egrep", "search", "pattern"]
+license = "Unlicense/MIT"
+
+[dependencies]
+grep-cli = { version = "0.1.2", path = "../grep-cli" }
+grep-matcher = { version = "0.1.2", path = "../grep-matcher" }
+grep-pcre2 = { version = "0.1.3", path = "../grep-pcre2", optional = true }
+grep-printer = { version = "0.1.2", path = "../grep-printer" }
+grep-regex = { version = "0.1.3", path = "../grep-regex" }
+grep-searcher = { version = "0.1.4", path = "../grep-searcher" }
+
+[dev-dependencies]
+termcolor = "1.0.4"
+walkdir = "2.2.7"
+
+[features]
+simd-accel = ["grep-searcher/simd-accel"]
+pcre2 = ["grep-pcre2"]
+
+# This feature is DEPRECATED. Runtime dispatch is used for SIMD now.
+avx-accel = []
diff --git a/crates/grep/LICENSE-MIT b/crates/grep/LICENSE-MIT
new file mode 100644
index 00000000..3b0a5dc0
--- /dev/null
+++ b/crates/grep/LICENSE-MIT
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Andrew Gallant
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/crates/grep/README.md b/crates/grep/README.md
new file mode 100644
index 00000000..c376d8af
--- /dev/null
+++ b/crates/grep/README.md
@@ -0,0 +1,41 @@
+grep
+----
+ripgrep, as a library.
+
+[![Linux build status](https://api.travis-ci.org/BurntSushi/ripgrep.svg)](https://travis-ci.org/BurntSushi/ripgrep)
+[![Windows build status](https://ci.appveyor.com/api/projects/status/github/BurntSushi/ripgrep?svg=true)](https://ci.appveyor.com/project/BurntSushi/ripgrep)
+[![](https://img.shields.io/crates/v/grep.svg)](https://crates.io/crates/grep)
+
+Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
+
+
+### Documentation
+
+[https://docs.rs/grep](https://docs.rs/grep)
+
+NOTE: This crate isn't ready for wide use yet. Ambitious individuals can
+probably piece together the parts, but there is no high level documentation
+describing how all of the pieces fit together.
+
+
+### Usage
+
+Add this to your `Cargo.toml`:
+
+```toml
+[dependencies]
+grep = "0.2"
+```
+
+and this to your crate root:
+
+```rust
+extern crate grep;
+```
+
+
+### Features
+
+This crate provides a `pcre2` feature (disabled by default) which, when
+enabled, re-exports the `grep-pcre2` crate as an alternative `Matcher`
+implementation to the standard `grep-regex` implementation.
diff --git a/crates/grep/UNLICENSE b/crates/grep/UNLICENSE
new file mode 100644
index 00000000..68a49daa
--- /dev/null
+++ b/crates/grep/UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/crates/grep/examples/simplegrep.rs b/crates/grep/examples/simplegrep.rs
new file mode 100644
index 00000000..749cff26
--- /dev/null
+++ b/crates/grep/examples/simplegrep.rs
@@ -0,0 +1,72 @@
+extern crate grep;
+extern crate termcolor;
+extern crate walkdir;
+
+use std::env;
+use std::error::Error;
+use std::ffi::OsString;
+use std::process;
+
+use grep::cli;
+use grep::printer::{ColorSpecs, StandardBuilder};
+use grep::regex::RegexMatcher;
+use grep::searcher::{BinaryDetection, SearcherBuilder};
+use termcolor::ColorChoice;
+use walkdir::WalkDir;
+
+fn main() {
+ if let Err(err) = try_main() {
+ eprintln!("{}", err);
+ process::exit(1);
+ }
+}
+
+fn try_main() -> Result<(), Box<dyn Error>> {
+ let mut args: Vec<OsString> = env::args_os().collect();
+ if args.len() < 2 {
+ return Err("Usage: simplegrep <pattern> [<path> ...]".into());
+ }
+ if args.len() == 2 {
+ args.push(OsString::from("./"));
+ }
+ search(cli::pattern_from_os(&args[1])?, &args[2..])
+}
+
+fn search(pattern: &str, paths: &[OsString]) -> Result<(), Box<dyn Error>> {
+ let matcher = RegexMatcher::new_line_matcher(&pattern)?;
+ let mut searcher = SearcherBuilder::new()
+ .binary_detection(BinaryDetection::quit(b'\x00'))
+ .line_number(false)
+ .build();
+ let mut printer = StandardBuilder::new()
+ .color_specs(ColorSpecs::default_with_color())
+ .build(cli::stdout(if cli::is_tty_stdout() {
+ ColorChoice::Auto
+ } else {
+ ColorChoice::Never
+ }));
+
+ for path in paths {
+ for result in WalkDir::new(path) {
+ let dent = match result {
+ Ok(dent) => dent,
+ Err(err) => {
+ eprintln!("{}", err);
+ continue;
+ }
+ };
+ if !dent.file_type().is_file() {
+ continue;
+ }
+ let result = searcher.search_path(
+ &matcher,
+ dent.path(),
+ printer.sink_with_path(&matcher, dent.path()),
+ );
+ if let Err(err) = result {
+ eprintln!("{}: {}", dent.path().display(), err);
+ }
+ }
+ }
+ Ok(())
+}
diff --git a/crates/grep/src/lib.rs b/crates/grep/src/lib.rs
new file mode 100644
index 00000000..13eaee25
--- /dev/null
+++ b/crates/grep/src/lib.rs
@@ -0,0 +1,23 @@
+/*!
+ripgrep, as a library.
+
+This library is intended to provide a high level facade to the crates that
+make up ripgrep's core searching routines. However, there is no high level
+documentation available yet guiding users on how to fit all of the pieces
+together.
+
+Every public API item in the constituent crates is documented, but examples
+are sparse.
+
+A cookbook and a guide are planned.
+*/
+
+#![deny(missing_docs)]
+
+pub extern crate grep_cli as cli;
+pub extern crate grep_matcher as matcher;
+#[cfg(feature = "pcre2")]
+pub extern crate grep_pcre2 as pcre2;
+pub extern crate grep_printer as printer;
+pub extern crate grep_regex as regex;
+pub extern crate grep_searcher as searcher;