• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍇 Syntax-aware grep-like for Clojure

grapes.

Grape

Grape is a syntax-aware grep-like utility for Clojure code. It allows you to search for code patterns using Clojure data structures.

Note: this project is not maintained. It works as is, but I don’t use Clojure these days and I don’t have the time/motivation to add more features. If you wish to improve the project, please contact me so I can give you commit access. Otherwise, see Grasp for a similar and more-maintained tool.

Command-line

$ grape [options] <pattern> [<file> ...]

For example, to find all usages of map called with three arguments in grape’s own code:

grape --unindent '(map $ $ $)' src

Output:

src/grape/impl/match.clj:
29:(map match?
        trees
        patterns)

src/grape/cli.clj:
137:(map #(when (= %1 %2) %1) prefix line-prefix)

Options:

  • -c, --count: show the total matches count and exit.
  • -F, --no-filenames: by default, grape shows the matching filenames when run on multiple files. This option disables that.
  • -u, --unindent: un-indent matches.
  • --line-numbers first|all|none: control line numbers. The default is first, i.e. only the first line of each match is prefixed by its line number. all shows all line numbers; none remove them.
  • -n, --all-line-numbers: alias for --line-numbers all
  • -N, --no-line-numbers: alias for --line-numbers none
  • --inline: force matches on one line. Note this doesn’t change multi-line strings.

Run grape --help to show all options.

Install

Either get the standalone binary (faster) or a jar from the Releases page.

If you have Homebrew, you can install it like so:

brew install bfontaine/utils/grape

Thanks to @ngrunwald, there’s also an Arch Linux grape-bin package. For example, if you use yay:

yay -S grape-bin

Library

Clojars Project

(require '[grape.core :as g])

(def my-code (slurp "myfile.clj"))

;; Find all occurrences of map called with three arguments
(g/find-codes my-code (g/pattern "(map $ $ $)"))

;; Find all occurrences of (condp = ...)
(g/find-codes my-code (g/pattern "(condp = $&)"))

;; Find all occurrences of `if` with no `else` clause
(g/find-codes my-code (g/pattern "(if $ $)"))
; => ({:match "(if …)", :meta {…}}, …)

Matches are map with a :match key that contains a string with the matching code and a :meta key with line/column metadata which you can use to locate the code in your file.

Patterns

A pattern is any valid Clojure expression. It can contain some special symbols that are interpreted as wildcards.

Comments, whitespaces, and discard reader macros (#_) are ignored when matching.

Wildcards

  • $: any expression.
  • $&: any number of expressions, including zero. (f $&) matches (f), (f 1), (f 1 2), etc.
  • $string, $list, etc: any expression of the given type.

See the full patterns documentation. See more examples.

Wildcards can be combined: #{$ $&} matches a set with at least one element.

License

Copyright © 2019-2023 Baptiste Fontaine

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

See also

  • Grasp, to grep Clojure code using clojure.spec regexes

More Repositories

1

term2048

🎉 2048 in your terminal
Python
802
star
2

rfc

📄 Read RFCs from the command-line
Shell
217
star
3

freesms

📱 Send SMSes to yourself through the 'Free Mobile' SMS API
Python
55
star
4

httpdoc

📓 HTTP documentation right in your terminal.
Go
35
star
5

clygments

🎨 Code highlighting using Pygments in Clojure
Clojure
29
star
6

vanish

✨ Temporary files and directories made easy
Go
27
star
7

Katas

☕ 27 katas; each in a different language (not only CoffeeScript, GitHub!)
CoffeeScript
20
star
8

clj

🐨 (Clojure-like) Lazy iterators in Python
Python
19
star
9

Dotfiles

🍭 personal dotfiles
Vim Script
18
star
10

Brewfile.vim

Brewfile syntax for Vim
Vim Script
16
star
11

gzsize

Print the uncompressed size of a GZip file.
C
13
star
12

lein-fore-prob

A leiningen plugin to make a local copy of a problem from 4clojure
Clojure
12
star
13

badges2svg

Replace your README badges with resolution-independent SVG ones
Ruby
10
star
14

iwc

Interactive wc(1)
C
10
star
15

Historize

jQuery plugin which allows you to keep an history on an input and a tab-completion system, like in a shell.
JavaScript
9
star
16

drive

Google Drive client wrapper in Python
Python
9
star
17

jquery-djangocsrf

A lightweight jQuery plugin to automatically add Django CSRF token to your AJAX calls
JavaScript
9
star
18

ud

🤘 Urban Dictionary in your terminal.
Ruby
8
star
19

homebrew-tools

🔧 Some tools for contributing to Homebrew
Ruby
8
star
20

jsons

💼 Read & write .jsons files in Go
Go
7
star
21

mvb

⏪ mv. reversed.
Shell
6
star
22

ascii2svg

Draw SVG graphs from text files
JavaScript
6
star
23

homer

Daemonize all the things
C
6
star
24

homebrew-search

🔎 Unofficial Homebrew search engine
Ruby
6
star
25

wptranslate

Wikipedia-based command-line translator
Python
5
star
26

blabbr

Twitter bot
Python
5
star
27

zprint.vim

A Vim plugin that runs zprint when you save.
Vim Script
5
star
28

homebrew-utils

🚙 Homebrew tap for personal utilities
Ruby
5
star
29

pouf

play random sounds from your command-line
Ruby
5
star
30

RemindMe

Web app to create SMS reminders
Python
4
star
31

k0s

8 less than k8s.
4
star
32

flatkeys

flatten dict keys in Python
Python
4
star
33

Dazibao

school project
C
4
star
34

crosswords

Crosswords help in the terminal
Python
4
star
35

UP7Connect

Connection to Paris Diderot’s WiFi made easy.
Ruby
4
star
36

gsutil-extra

gsutil with extra features
Ruby
4
star
37

Graphs.rb

Some Ruby functions to manipulate graph files
Ruby
4
star
38

ctrie

Compact tries in Python
Python
4
star
39

simple-progress

Simple progress bar for your Clojure programs
Clojure
4
star
40

pipe2mattermost

Pipe text into Mattermost
Go
3
star
41

task.sh

Easy step-by-step Bash scripts output
Shell
3
star
42

Summarify

Python library to get a title & description for a URL
Python
3
star
43

p7magma-web

Web interface for p7magma
Python
3
star
44

omgrofl.vim

Vim syntax file for the Omgrofl language
Vim Script
3
star
45

expd

📎 Expand text snippets on the command-line
Ruby
3
star
46

p7magma

A Python interface to Magma (a website for CS students at Paris Diderot)
Python
3
star
47

which

the `which` you’re used to, written in Go.
Go
3
star
48

AjaxEdit

Lightweight jQuery plugin to edit HTML text without reloading the page.
JavaScript
3
star
49

k

Enums for Python
Python
3
star
50

gosh

Simple shell written in Go
Go
3
star
51

wheresmystuff

📦 Where’s that stuff I ordered on Amazon yesterday?
Go
3
star
52

eolas

Toy programming language
Python
3
star
53

toggle-text

Quick library to make togglable text
JavaScript
3
star
54

movielens-data-analysis

Some code to analyse MovieLens’ datasets
Python
3
star
55

up

one command to update all your package managers
Shell
3
star
56

ArrayDB

Use your arrays as DB tables, and make queries on them.
JavaScript
2
star
57

Advent-of-Code-2017

My solutions to the Advent of Code 2017
Go
2
star
58

ecqopcd

A Website that tells you if you can go out running in Paris tomorrow
Python
2
star
59

LazyScraper

The easy way to make lazy entity-oriented Web scrapers
Ruby
2
star
60

didelcli

DidEL in the command-line.
Python
2
star
61

Antroid

School project
Go
2
star
62

M1Algo

school project
Python
2
star
63

trigrams

Trigrams-based random text generation
Python
2
star
64

AC6

school project
OCaml
2
star
65

web-pp

📜 Web port of alfred-pp
Python
2
star
66

EulerSolutions

Solutions to the Project Euler problems in Python
Python
2
star
67

pykbg

Python wrapper around Kelbongoo’s website
Python
2
star
68

p7doi

🔗 Open a research paper in your browser from its DOI
Python
2
star
69

previewer

Generate link previews as an image
Python
2
star
70

etutriche

Automatically detect cheating students
Python
2
star
71

shortjs

Shorten numbers
JavaScript
2
star
72

Doto

Quick & easy builders in Java
Java
2
star
73

SocioNoel

Books mentioned in #SocioNoel on Twitter, 2015
Ruby
2
star
74

epp

(fast) EDN pretty-printer
Go
2
star
75

clython

Call Python from Clojure
Clojure
2
star
76

gostruct

populate Go structs from webpages using CSS selectors
Go
2
star
77

shutils

🔌 shell utilities
Go
2
star
78

Pheasant.js

Easy colors manipulations.
JavaScript
2
star
79

alfred-pp

⏩ Alfred workflow to open Paris Diderot CS teachers’ personal homepages
Python
2
star
80

classy

Inspect .class Java files from Go
Go
2
star
81

tweets2fortune

script to transform a user's tweets into a fortune file
Io
1
star
82

WhitePage

simple online scratch pad
JavaScript
1
star
83

PrettyInputs

Make your inputs look like Dropbox’ ones.
JavaScript
1
star
84

Teebr

🐱 Twitter accounts recommendation
Python
1
star
85

webassets-iife

webassets filter to wrap a JS bundle in an IIFE to avoid global leaks and improve minification
Python
1
star
86

Reversi

Reversi game for the C class (LC4)
C
1
star
87

solarized-quora

Solarized theme for Quora’s code blocks
CSS
1
star
88

heck

Hexadecimal calculator
Go
1
star
89

cryptopals-solutions

Python
1
star
90

sq

📄 Bulk PDFs downloader
Ruby
1
star
91

slg

🤘 Slengo.it in your terminal.
Ruby
1
star
92

advent-of-code

Advent of Code 2015-2021 solutions in various languages
Python
1
star
93

clr

clear temporary files
Shell
1
star
94

defcli

Utilities library for some CLI tools
Ruby
1
star
95

lines

Experimental tools for line-based file formats
Go
1
star
96

ghtasklist

✔️ Fast Github task list formatting
Go
1
star
97

E.vim

E vim syntax file
Vim Script
1
star
98

.github

🏥 Default community health files for the bfontaine user on GitHub.
1
star
99

FormulaJS

Basic formulas interpreter
JavaScript
1
star
100

neural-nets

Playing with Tensorflow
Python
1
star