PHPackages                             emanuelecoppola/phpeg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. emanuelecoppola/phpeg

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

emanuelecoppola/phpeg
=====================

A modern PHP PEG parsing library.

v1.0.1(1mo ago)01↓100%MITPHPPHP &gt;=8.1 &lt;9.0CI passing

Since May 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/EmanueleCoppola/phpeg)[ Packagist](https://packagist.org/packages/emanuelecoppola/phpeg)[ Fund](https://www.buymeacoffee.com/emanuelecoppola)[ GitHub Sponsors](https://github.com/EmanueleCoppola)[ RSS](/packages/emanuelecoppola-phpeg/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

PHPeg
=====

[](#phpeg)

[![Tests](https://camo.githubusercontent.com/00505a3d4603151e85b92f99ef023cedbed87d1aa5a2692de3ea1476720b1847/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f456d616e75656c65436f70706f6c612f70687065672f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/EmanueleCoppola/phpeg/actions/workflows/tests.yml)[![Latest Version](https://camo.githubusercontent.com/dc61568055b6cc0a17ba69a68d6f8b1a1b25342135cab86746c78f65ac58df6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d616e75656c65636f70706f6c612f70687065672e737667)](https://packagist.org/packages/emanuelecoppola/phpeg)[![Total Downloads](https://camo.githubusercontent.com/79a5cb0f81609386a15c2974a092f681f236441094ddac7f3bcce9c027d218d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d616e75656c65636f70706f6c612f70687065672e737667)](https://packagist.org/packages/emanuelecoppola/phpeg)[![License](https://camo.githubusercontent.com/19fd0606f80f3b901a8da8c47f7e5dbcb0672b535d2e7441a89a2b4ffef7d117/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656d616e75656c65636f70706f6c612f70687065672e737667)](./LICENSE)

PHPeg is a modern PEG parsing library for PHP.

It gives you:

- a fluent PHP grammar builder
- two grammar loaders: CleanPeg for compact grammars with built-in conveniences, Classic PEG for explicit traditional PEG syntax
- AST querying, mutation, and source-preserving printing
- configurable parsing trade-offs for speed, memory, and diagnostics
- left-recursive grammars are detected and handled automatically

If you want to parse PHP-native grammars and still get serious AST tooling and source-preserving editing, this library is built for that.

Installation
------------

[](#installation)

```
composer require emanuelecoppola/phpeg
```

Quick Start
-----------

[](#quick-start)

This example parses a tiny `env`-style line and then replaces its value in place.

```
