|
diff --git a/README.md b/README.md
|
| 1 |
# crep - like grep but for code |
1 |
`crep` is a command-line tool designed for searching code using [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) queries. Unlike traditional `grep`, which operates on text lines, `crep` understands the structure of your code, allowing for more precise semantic searching. |
|
|
2 |
|
|
|
3 |
## Features |
|
|
4 |
|
|
|
5 |
- **Semantic Search**: Uses Tree-sitter to parse code into Concrete Syntax Trees (CSTs) and execute queries against them. |
|
|
6 |
- **Language Support**: Currently supports **C** and **Python**. |
|
|
7 |
- **Multi-threaded**: Utilizes a custom thread pool for efficient scanning of large codebases. |
|
|
8 |
- **Detailed Output**: Reports file path, line number, return type, function name, and parameters for each match. |
|
|
9 |
|
|
|
10 |
## Prerequisites |
|
|
11 |
|
|
|
12 |
To build `crep`, you need: |
|
|
13 |
- A C compiler (GCC or Clang) |
|
|
14 |
- `make` |
|
|
15 |
- `xxd` (used for embedding Tree-sitter queries) |
|
|
16 |
- `pthread` library |
|
|
17 |
|
|
|
18 |
## Installation |
|
|
19 |
|
|
|
20 |
```bash |
|
|
21 |
git clone https://github.com/mitjafelicijan/crep.git |
|
|
22 |
cd crep |
|
|
23 |
make all |
|
|
24 |
``` |
|
|
25 |
|
|
|
26 |
## Usage |
|
|
27 |
|
|
|
28 |
```bash |
|
|
29 |
./crep <search_term> [path] |
|
|
30 |
``` |
|
|
31 |
|
|
|
32 |
- `<search_term>`: The string to search for within function names. |
|
|
33 |
- `[path]`: Optional. The directory or file to search (defaults to current directory). |
|
|
34 |
|
|
|
35 |
### Examples |
|
|
36 |
|
|
|
37 |
Search for all functions containing "init" in the current directory: |
|
|
38 |
```bash |
|
|
39 |
./crep init . |
|
|
40 |
``` |
| 2 |
|
41 |
|
| 3 |
## What is crep? |
42 |
Search for functions containing "parse" in a specific file: |
|
|
43 |
```bash |
|
|
44 |
./crep parse main.c |
|
|
45 |
``` |
| 4 |
|
46 |
|
| 5 |
If grep and etags had a baby. You should use ctags or etags. Seriously. This is |
47 |
## How It Works |
| 6 |
an experimental thingy. |
|
|
| 7 |
|
48 |
|
| 8 |
- https://en.wikipedia.org/wiki/Ctags |
49 |
`crep` works by: |
| 9 |
- https://www.emacswiki.org/emacs/TagsFile |
50 |
1. Identifying supported files. |
|
|
51 |
2. Parsing the files using Tree-sitter grammars. |
|
|
52 |
3. Executing a structural query to find function/method definitions. |
|
|
53 |
4. Matching the identifier against the provided search term. |
|
|
54 |
5. Displaying the results in a format similar to grep but with added semantic context. |
| 10 |
|
55 |
|
| 11 |
## Additional resources |
56 |
## Additional resources |
| 12 |
|
57 |
|
|
|
58 |
- https://en.wikipedia.org/wiki/Ctags |
|
|
59 |
- https://www.emacswiki.org/emacs/TagsFile |
| 13 |
- https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm |
60 |
- https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm |
| 14 |
- https://en.wikipedia.org/wiki/Levenshtein_distance |
61 |
- https://en.wikipedia.org/wiki/Levenshtein_distance |
| 15 |
- https://github.com/tree-sitter/tree-sitter |
62 |
- https://github.com/tree-sitter/tree-sitter |
| ... |