MyNixOS website logo
Description

grep-like CLI using Parsec parsers instead of regex.

pgrep is a grep-like command-line tool that uses Parsec parser combinators instead of regular expressions for pattern matching. Write patterns using a familiar Haskell-like DSL with combinators like 'some digit', 'string TODO', or 'manyTill anyChar (string END)'.

scrappy-file

File system utilities for the scrappy web scraping library, plus pgrep - a grep-like CLI that uses Parsec parsers instead of regex.

pgrep

Search files using Parsec parser patterns instead of regular expressions.

Installation

cabal build pgrep
cabal install pgrep

Make sure ~/.local/bin is in your PATH:

export PATH="$HOME/.local/bin:$PATH"

Usage

pgrep PATTERN FILE...
pgrep [OPTIONS] PATTERN FILE...

DSL Primitives

PrimitiveExampleDescription
charchar 'x'Single character
stringstring "abc"Literal string
anyCharanyCharAny character
digitdigit0-9
letterlettera-z, A-Z
alphaNumalphaNumLetter or digit
spacespaceSingle whitespace
spacesspacesZero or more whitespace
newlinenewlineNewline character
oneOfoneOf "abc"Match one of chars
noneOfnoneOf "xyz"Match none of chars

DSL Combinators

CombinatorSyntaxDescription
Sequencep1 >> p2Run p1 then p2, return p2's result
Concatp1 <+> p2Run both, concatenate results
Alternativep1 <|> p2Try p1, else p2
Manymany pZero or more
Somesome pOne or more
Optionaloptional pZero or one
Trytry pBacktracking
Betweenbetween '(' ')' pParse between delimiters
Countcount 3 pExactly n repetitions
ManyTillmanyTill p endNon-greedy: match p until end

Examples

# Find digits
pgrep 'some digit' file.txt

# Find email patterns
pgrep 'some alphaNum <+> char '\''@'\'' <+> some alphaNum <+> char '\''.'\'' <+> some letter' contacts.txt

# Find TODO comments
pgrep 'string "TODO"' -r ./src/

# Search recursively with extension filter
pgrep -r -e .hs 'string "import"' ./src/

# Count matches
pgrep -c 'digit' data.txt

# JSON output
pgrep --json 'some digit' file.txt

# Non-greedy matching: find everything between X and Y
pgrep 'string "START" <+> manyTill anyChar (string "END")' file.txt

Options

-r, --recursive      Search directories recursively
-e, --extension EXT  Only search files with extension (e.g., .hs, .txt)
-v, --verbose        Verbose output with full match text
-c, --count          Only print count of matches
-q, --quiet          Quiet mode (exit code only)
-m, --max-results N  Maximum number of results to show
--json               Output results as JSON

Output Format

Default output is grep-like:

file.txt:1:28:123
file.txt:2:5:[email protected]

Format: filepath:line:column:matched_text

Library API

The Scrappy.Grep.* modules expose:

  • Scrappy.Grep.DSL - AST types (ParserExpr, MatchResult)
  • Scrappy.Grep.DSL.Parser - Parse DSL strings to AST
  • Scrappy.Grep.DSL.Interpreter - Convert AST to Parsec parsers
  • Scrappy.Grep.Search - File/directory search functions
  • Scrappy.Grep.Output - Result formatting.
Metadata

Version

0.1.0.0

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows