All Projects → jubianchi → ppc

jubianchi / ppc

Licence: MIT License
A parser combinator library for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to ppc

XParsec
extensible, type-and-source-polymorphic, non-linear applicative parser combinator library for F# 3.0 and 4.0
Stars: ✭ 40 (+17.65%)
Mutual labels:  parser-combinators
Ramble
A R parser based on combinatory parsers.
Stars: ✭ 19 (-44.12%)
Mutual labels:  parser-combinators
maxpc
Max’s Parser Combinators: a simple and pragmatic library for writing parsers and lexers based on combinatory parsing.
Stars: ✭ 42 (+23.53%)
Mutual labels:  parser-combinators
Kt2Dart
🔦 [Deprecated] Transpile Kotlin codes into Dart, Make Flutter Great Again
Stars: ✭ 84 (+147.06%)
Mutual labels:  parser-combinators
metal
A Java library for parsing binary data formats, using declarative descriptions.
Stars: ✭ 13 (-61.76%)
Mutual labels:  parser-combinators
CombinedParsers.jl
Compiled parser combinators and regular expressions in pure julia
Stars: ✭ 76 (+123.53%)
Mutual labels:  parser-combinators
Funcparserlib
Recursive descent parsing library for Python based on functional combinators
Stars: ✭ 250 (+635.29%)
Mutual labels:  parser-combinators
loquat
Monadic parser combinators for JavaScript / TypeScript
Stars: ✭ 47 (+38.24%)
Mutual labels:  parser-combinators
ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (-32.35%)
Mutual labels:  parser-combinators
parserz
A purely-functional library for creating both parsers, pretty-printers, and grammar definitions from a single, type-safe specification of a grammar
Stars: ✭ 68 (+100%)
Mutual labels:  parser-combinators
mecha
A parser combinator library for Zig
Stars: ✭ 220 (+547.06%)
Mutual labels:  parser-combinators
SuperCombinators
[Deprecated] A Swift parser combinator framework
Stars: ✭ 19 (-44.12%)
Mutual labels:  parser-combinators
parsekt
Parser Combinator library for Kotlin
Stars: ✭ 27 (-20.59%)
Mutual labels:  parser-combinators
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+294.12%)
Mutual labels:  parser-combinators
Parsey
Swift Parser Combinators
Stars: ✭ 56 (+64.71%)
Mutual labels:  parser-combinators
autumn
A Java parser combinator library written with an unmatched feature set.
Stars: ✭ 112 (+229.41%)
Mutual labels:  parser-combinators
parser-lang
A parser combinator library with declarative superpowers
Stars: ✭ 25 (-26.47%)
Mutual labels:  parser-combinators
leftry
Leftry - A left-recursion enabled recursive-descent parser combinator library for Lua.
Stars: ✭ 32 (-5.88%)
Mutual labels:  parser-combinators
ex spirit
No description or website provided.
Stars: ✭ 26 (-23.53%)
Mutual labels:  parser-combinators
FLexer
Simple Lexer and Parser in F#
Stars: ✭ 22 (-35.29%)
Mutual labels:  parser-combinators

PPC

A parser combinator library for PHP

Simple to use & extend • Fast & lightweight • Reliable

Introduction

PPC stands for PHP Parser Combinator. 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 (mbstring) extension enabled. You may want to check if your setup is correct using the following script:

#!/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)

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

Composer (JSON)

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

Git

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

use jubianchi\PPC\Parser\Result;
use jubianchi\PPC\CharStream;
use function jubianchi\PPC\Combinators\{opt, separated, seq};
use function jubianchi\PPC\Parsers\{char, eos, regex};

$separator = seq(char(','), opt(char(' ')));
$list = seq(
    char('['),
    seq(
        separated(
            $separator,
            opt(regex('/[0-9]/'))
        ),
        opt($separator)
    ),
    char(']'),
    eos()
);

$stream = new CharStream('[0, 1, 2, , 4, 5,, 7, 8, 9,]');
$result = $list($stream);

assert($result instanceof Result\Success);

Easy, right? Be sure to read the documentation to understand how it works.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].