# Install peg with Homebrew, apk, apt, MacPorts, Nix, pacman, zypper

Program to perform pattern matching on text. Version 0.1.19 via Homebrew; verified 2026-06-14. Also installable with debian: sudo apt install peg.

## Install

```sh
sudo av install brew:peg
```

Additional install commands:

### macOS

- Homebrew (100%):

```sh
brew install peg
```

  Evidence: local Homebrew formula metadata

- MacPorts (94%):

```sh
sudo port install peg
```

  Evidence: MacPorts ports tree: devel/peg/Portfile from https://api.github.com/repos/macports/macports-ports/git/trees/master?recursive=1

### Linux

- apk (92%):

```sh
sudo apk add peg
```

  Evidence: Alpine Linux edge package indexes: peg from https://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz

- Debian apt (92%):

```sh
sudo apt install peg
```

  Evidence: Debian stable package indexes: peg from https://deb.debian.org/debian/dists/stable/main/binary-amd64/Packages.xz

- Nix (92%):

```sh
nix profile install nixpkgs#peg
```

  Evidence: nixpkgs package indexes: pkgs/by-name/pe/peg/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1

- pacman (92%):

```sh
sudo pacman -S peg
```

  Evidence: Arch Linux sync databases: peg from https://geo.mirror.pkgbuild.com/extra/os/x86_64/extra.db.tar.gz

- zypper (92%):

```sh
sudo zypper install peg
```

  Evidence: openSUSE Tumbleweed package metadata: peg from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst

## Package facts

- **Package key:** brew:peg
- **Package manager:** Homebrew
- **Version:** 0.1.19
- **Source summary:** Program to perform pattern matching on text
- **Homepage:** <https://www.piumarta.com/software/peg/>
- **Last updated:** 2026-06-14T14:47:59+02:00
- **Generated:** 2026-08-03T19:37:03+00:00

## Executables

- leg (alias)
- peg (alias)

## Install behavior

- Bottle: not available

## Freshness

- Page generated: 2026-08-03
- Package-manager version: 0.1.19
## Project history and usage

peg and leg are recursive-descent parser generators for C. They process Parsing Expression Grammars and generate C parsers, with `peg` following Bryan Ford's original PEG syntax and `leg` using conventions intended as an alternative to lex and yacc.

### Project history

Ian Piumarta's official page lists peg/leg as tools for generating recursive-descent parsers from Parsing Expression Grammars. The first public release in the official version history is 0.1.1 on 2007-05-15.

The manual page explains that peg reads grammar files or standard input and generates C source defining `yyparse()`, while leg uses a syntax intended to make it attractive to users familiar with lex and yacc workflows.

The official version history shows steady maintenance through 0.1.19 stable in 2023, including reentrant parsing support, error actions, UTF-8 fixes, C++ support improvements, and Windows/Mac build files.

### Adoption history

peg/leg spread through Unix-like package managers as a small C parser-generation tool: the input metadata lists Homebrew, Debian, Ubuntu, Arch, MacPorts, Nix, Alpine, and openSUSE package names.

Its niche is smaller than yacc-family tools, but it remains useful where a project wants PEG-style ordered choice, unlimited backtracking, and combined scanning and parsing in generated C.

### How it is used

Typical use is to run `peg` or `leg` over a grammar file and compile or include the generated C source in a client program.

The official manual documents options such as `-o` for output file selection, `-P` for suppressing `#line` directives, `-v` for verbose mode, and `-V` for version output.

### Why package nerds care

peg/leg is package-manager-friendly because it is a compact C command-line tool with a stable manual page, source tarballs, and a long version history.

For package nerds it is also a useful contrast with lex/yacc: a small PEG-based generator that produces embeddable C parsers without requiring a larger parser framework.

### Timeline

- 2007-05-15: First public release, 0.1.1.
- 2013-06-03: 0.1.11 added error actions, C++ support improvements, and Win32/Mac build files.
- 2016-07-22: 0.1.18 added the `-P` option to disable `#line` directives.
- 2023-03-06: 0.1.19 stable added experimental re-entrant parsing through `yyparsefrom_r()`.
- 2023-11-19: 0.1.20 development version listed with experimental inline-action variables and semantic values.

### Related projects

- Bryan Ford's 2004 Parsing Expression Grammars paper is the formal grammar reference cited by the official page.
- lex and yacc are the comparison point used by the official page and manual.

### Sources

- <https://www.piumarta.com/software/peg>
- <https://www.piumarta.com/software/peg/peg.1.html>
- source_facts.package-manager


## Security Notes

narrow executable package without higher-risk signals.

- **Geiger risk:** green / low
- narrow executable package without higher-risk signals

## Other Package-Manager Records

- Debian apt - peg - 0.1.20+really0.1.18-1: normalized package name match | Debian stable package indexes: peg from https://deb.debian.org/debian/dists/stable/main/binary-amd64/Packages.xz | recursive-descent parser generators for C | https://piumarta.com/software/peg/
- Nix - peg: normalized package name match | nixpkgs package indexes: pkgs/by-name/pe/peg/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1
- Ubuntu apt - peg - 0.1.18-1build1: normalized package name match | Ubuntu 24.04 LTS package indexes: peg from https://archive.ubuntu.com/ubuntu/dists/noble/universe/binary-amd64/Packages.gz | recursive-descent parser generators for C | http://piumarta.com/software/peg/
- apk - peg - 0.1.18-r1: normalized package name match | Alpine Linux edge package indexes: peg from https://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz | Recursive-descent parser generators for C | https://www.piumarta.com/software/peg/
- apk - peg-doc - 0.1.18-r1: normalized package name match | Alpine Linux edge package indexes: peg-doc from https://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz | Recursive-descent parser generators for C (documentation) | https://www.piumarta.com/software/peg/
- pacman - peg - 0.1.19-1: normalized package name match | Arch Linux sync databases: peg from https://geo.mirror.pkgbuild.com/extra/os/x86_64/extra.db.tar.gz | recursive-descent parser generators for C | http://piumarta.com/software/peg/
- zypper - peg - 0.1.20-1.9: normalized package name match | openSUSE Tumbleweed package metadata: peg from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst | Recursive-Descent parser generators for C | https://piumarta.com/software/peg/
- MacPorts - peg: normalized package name match | MacPorts ports tree: devel/peg/Portfile from https://api.github.com/repos/macports/macports-ports/git/trees/master?recursive=1


## Combined YAML source

View the package source record on GitHub. [combined/peg.yml](https://github.com/mxcl/pkgdb/blob/main/combined/peg.yml)


## Sources

- pkg.so package database
- Geiger risk classifier
- curated package history
- pkgdb category and tag curation
- external package-manager database matches
- cross-ecosystem install command graph
