Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/jubianchi/ppc

A parser combinator library for PHP
https://github.com/jubianchi/ppc

parser-combinators php

Last synced: 3 months ago
JSON representation

A parser combinator library for PHP

Lists

README

        

# PPC

> A parser combinator library for PHP

Simple to use & extend • Fast & lightweight • Reliable

## Introduction

PPC stands for **P**HP **P**arser **C**ombinator. What an obvious name for such a library!

As its name tells us, PPC is just another parser combinator library with a clear goal: make writing efficient parsers a
breeze. Writing parser with PPC does not require you to know how parser combinators works internally nor it requires you
to learn a complex object-oriented API.

PPC is a set of functions which you will love to compose to build complex parsers!

## Installation

PPC requires you to have at least PHP `7.4.0` and the [Multibyte String](https://www.php.net/manual/en/book.mbstring.php)
(`mbstring`) extension enabled. You may want to check if your setup is correct using the following script:

```bash
#!/usr/bin/env bash

echo "PHP version: $(php -v | head -n1 | grep -qE '7.([4-9]|1[0-9]).(0|[1-9][0-9]*)' && echo '✅' || echo '❌')"
echo "Multibyte String extension: $(php -m | grep -qE 'mbstring' && echo '✅' || echo '❌')"
```

Once everything is correct, choose the installation method that best feets your needs:

### Composer (CLI)

```bash
composer require "jubianchi/ppc" "dev-master"
```

### Composer (JSON)

```json
{
"require": {
"jubianchi/ppc": "dev-master"
}
}
```

### Git

```bash
git clone "https://github.com/jubianchi/ppc.git"
git checkout "master"
```

## Example parser

Here is a quick example demonstrating how easy it is to write a parser:

```php