PHPackages                             pvandommelen/parser - 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. pvandommelen/parser

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

pvandommelen/parser
===================

A parser generator for PHP

3141PHP

Since Jun 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pvandommelen/parser)[ Packagist](https://packagist.org/packages/pvandommelen/parser)[ RSS](/packages/pvandommelen-parser/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

A parser generator written in PHP.

Features
--------

[](#features)

Supports backtracking.

Detects left recursion.

Directly matches strings so it contains no lexing (tokenizer) step

General usage
-------------

[](#general-usage)

The available helper class and its static methods should be used:

```
PeterVanDommelen\Parser\ParserHelper::compile(ExpressionInterface $expression)
PeterVanDommelen\Parser\ParserHelper::compileWithGrammar(ExpressionInterface $expression, Grammar $grammar)

```

These methods accept an expression (see below which ones are available) and maybe a grammar (see below). The return value is the parser which offers one method:

```
PeterVanDommelen\Parser\Parser\ParserInterface::parse(string $string)

```

The parse method will return null if the parser was unable to match the string. The parser will always match from the start. If succesfully matched a result object corresponding to the parsed expression will be returned.

The result object implements ExpressionResultInterface which has the following two methods describing the matched string:

```
PeterVanDommelen\Parser\Expression\ExpressionResultInterface::getString()
PeterVanDommelen\Parser\Expression\ExpressionResultInterface::getLength()

```

The specific implementation depends on the expression used and may have additional methods available, see the examples.

Available expressions
---------------------

[](#available-expressions)

### Constant

[](#constant)

PeterVanDommelen\\Parser\\Expression\\Constant\\ConstantExpression

```
new ConstantExpression(string $string)

```

Basic terminal.

### Concatenated

[](#concatenated)

PeterVanDommelen\\Parser\\Expression\\Concatenated\\ConcatenatedExpression

```
new ConcatenatedExpression(ExpressionInterface[] $parts);

```

Example:

```
$result = ParserHelper::compile(new ConcatenatedExpression(array(
    new ConstantExpression("a"),
    new ConstantExpression("b"),
)))->parse("abc");

$result->getString(); // "ab"
$result->getPart(0)->getString(); // "a"
$result->getPart(1)->getString(); // "b"

```

### Alternative

[](#alternative)

PeterVanDommelen\\Parser\\Expression\\Alternative\\AlternativeExpression

```
new AlternativeExpression(ExpressionInterface[] $alternatives)

```

Matches one of the expressions.

```
$result = ParserHelper::compile(new AlternativeExpression(array(
    new ConstantExpression("a"),
    new ConstantExpression("b"),
)))->parse("abc");

$result->getString(); // "a"
$result->getKey(); // 0
$result->getResult()->getString(); // "a"

```

### Repeater

[](#repeater)

PeterVanDommelen\\Parser\\Expression\\Repeater\\RepeaterExpression

```
new RepeaterExpression(ExpressionInterface $inner_expression, bool $is_lazy = false, int $minimum = 0, int|null $maximum = null)

```

Repeats the inner expression with the specified minimum and maximum.

```
$result = ParserHelper::compile(new RepeaterExpression(new ConstantExpression("a"))->parse("aaabc");

$result->getString(); // "aaa"
$result->getResults()[0]->getString(); // "a"

```

### Joined

[](#joined)

PeterVanDommelen\\Parser\\Expression\\Joined\\JoinedExpression

```
new JoinedExpression(ExpressionInterface $inner_expression, ExpressionInterface $seperator_expression, bool $is_lazy = false, int $minimum = 0, int|null $maximum = null)

```

A variation of the RepeaterExpression but with a seperator between elements

```
$result->getResults();
$result->getSeperators(); //will have a size of count($result->getResults) - 1

```

### Not

[](#not)

PeterVanDommelen\\Parser\\Expression\\Not\\NotExpression

```
new NotExpression(ExpressionInterface $inner_expression)

```

Matches a single character only if the inner expression does not match. The example below would match any character but "a" or "b":

```
new NotExpression(new AlternativeExpression(array(
    new ConstantExpression("a"),
    new ConstantExpression("b")
))

```

### Any

[](#any)

PeterVanDommelen\\Parser\\Expression\\Any\\AnyExpression

```
new AnyExpression()

```

Matches any single character.

### Named

[](#named)

use PeterVanDommelen\\Parser\\Expression\\Named\\NamedExpression

```
new NamedExpression(string $name)

```

See grammar below

Grammar
-------

[](#grammar)

The compiler supports using a grammar where entries can be referenced by using a NamedExpression.

For example, if we want to find the string not enclosed within pairs of matching brackets:

```
$no_opening_brace = new RepeaterExpression(new NotExpression(new AlternativeExpression(array(
    new ConstantExpression("(")
))));
$grammar = new Grammar(array(
    "expression" => new AlternativeExpression(array(
        new ConcatenatedExpression(array(
            $no_opening_brace,
            new ConstantExpression("("),
            new NamedExpression("expression"),
            new ConstantExpression(")"),
            $no_opening_brace,
        )),
        $no_opening_brace,
    )),
));
$parser = ParserHelper::compileWithGrammar(new NamedExpression("expression"), $grammar);

$result = $parser->parse("ab(c(d)ef)g");

$result->getString(); // "ab(c(d)ef)g"
switch ($result->getKey()) {
    case 0:
        return $result->getResult()->getPart(0)->getString() . $result->getResult()->getPart(4)->getString(); // "abg"
    case 1:
        // this branch is not reached
        return $result->getResult()->getString(); //
}

```

Performance
-----------

[](#performance)

Ignoring compilation, you should expect this parser to be roughly 100x slower than the native preg\_match.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1426441?v=4)[pvandommelen](/maintainers/pvandommelen)[@pvandommelen](https://github.com/pvandommelen)

---

Top Contributors

[![pvandommelen](https://avatars.githubusercontent.com/u/1426441?v=4)](https://github.com/pvandommelen "pvandommelen (19 commits)")

### Embed Badge

![Health badge](/badges/pvandommelen-parser/health.svg)

```
[![Health](https://phpackages.com/badges/pvandommelen-parser/health.svg)](https://phpackages.com/packages/pvandommelen-parser)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M42](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
