PHPackages                             hiqdev/hoa-compiler - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. hiqdev/hoa-compiler

ActiveLibrary[Testing &amp; Quality](/categories/testing)

hiqdev/hoa-compiler
===================

The Hiqdev Hoa\\Compiler library.

1.0.1(3y ago)18.7k↓22.7%1BSD-3-ClausePHPPHP &gt;=7.4

Since Jul 6Pushed 3y agoCompare

[ Source](https://github.com/hiqdev/hoa-compiler)[ Packagist](https://packagist.org/packages/hiqdev/hoa-compiler)[ RSS](/packages/hiqdev-hoa-compiler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (11)Versions (3)Used By (0)

Reasons to fork
---------------

[](#reasons-to-fork)

The Hoa project was archived, and no upgrades or patches are neither provided nor accepted by merge requests.

HOA Packages include some code that is Deprecated for PHP 8.0 and PHP 8.1, but we needed these packages to run on modern PHP versions.

What's changed in from?
-----------------------

[](#whats-changed-in-from)

The changes mainly affected the return data type hinting in methods declaration, access to uninitialized properties.

How to use
----------

[](#how-to-use)

We've currently forked the following packages, primarily to make hoa/ruler work with PHP 8.1:

Original packageForked packagehoa/rulerhiqdev/hoa-rulerhoa/compilerhiqdev/hoa-compilerhoa/protocolhiqdev/hoa-protocolhoa/iteratorhiqdev/hoa-iteratorYou can simply replace requirements in composer.json from hoa packages to the corresponding forked packages: there is no need to change something in the codebase. If you use someone's package, that requires hoa – simply add forks to your project root composer.json: we have marked forks as a replacement, so composer will install them instead of the original packages.

Versions
--------

[](#versions)

We've forked from the latest hoa package versions and bump own versions starting from 1.0.

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

As a quick overview, we will look at the PP language and the LL(k) compiler compiler.

### The PP language

[](#the-pp-language)

A grammar is constituted by tokens (the units of a word) and rules (please, see the documentation for an introduction to the language theory). The PP language declares tokens with the following construction:

```
%token [source_namespace:]name value [-> destination_namespace]

```

The default namespace is `default`. The value of a token is represented by a [PCRE](http://pcre.org/). We can skip tokens with the `%skip` construction.

As an example, we will take the *simplified* grammar of the [JSON language](http://json.org/). The complete grammar is in the `hoa://Library/Json/Grammar.pp` file. Thus:

```
%skip   space          \s
// Scalars.
%token  true           true
%token  false          false
%token  null           null
// Strings.
%token  quote_         "        -> string
%token  string:string  [^"]+
%token  string:_quote  "        -> default
// Objects.
%token  brace_         {
%token _brace          }
// Arrays.
%token  bracket_       \[
%token _bracket        \]
// Rest.
%token  colon          :
%token  comma          ,
%token  number         \d+

value:
     |  |  | string() | object() | array() | number()

string:
    ::quote_::  ::_quote::

number:

#object:
    ::brace_:: pair() ( ::comma:: pair() )* ::_brace::

#pair:
    string() ::colon:: value()

#array:
    ::bracket_:: value() ( ::comma:: value() )* ::_bracket::

```

We can see the PP constructions:

- `rule()` to call a rule;
- `` and `::token::` to declare a token;
- `|` for a disjunction;
- `(…)` to group multiple declarations;
- `e?` to say that `e` is optional;
- `e+` to say that `e` can appear at least 1 time;
- `e*` to say that `e` can appear 0 or many times;
- `e{x,y}` to say that `e` can appear between `x` and `y` times;
- `#node` to create a node the AST (resulting tree);
- `token[i]` to unify tokens value between them.

Unification is very useful. For example, if we have a token that expresses a quote (simple or double), we could have:

```
%token  quote   "|'
%token  handle  \w+

string:
    ::quote::  ::quote::

```

So, the data `"foo"` and `'foo'` will be valid, but also `"foo'` and `'foo"`! To avoid this, we can add a new constraint on token value by unifying them, thus:

```
string:
    ::quote[0]::  ::quote[0]::

```

All `quote[0]` for the rule instance must have the same value. Another example is the unification of XML tags name.

### LL(k) compiler compiler

[](#llk-compiler-compiler)

The `Hoa\Compiler\Llk\Llk` class provide helpers to manipulate (load or save) a compiler. The following code will use the previous grammar to create a compiler, and we will parse a JSON string. If the parsing succeed, it will produce an AST (stands for Abstract Syntax Tree) we can visit, for example to dump the AST:

```
// 1. Load grammar.
$compiler = Hoa\Compiler\Llk\Llk::load(new Hoa\File\Read('Json.pp'));

// 2. Parse a data.
$ast = $compiler->parse('{"foo": true, "bar": [null, 42]}');

// 3. Dump the AST.
$dump = new Hoa\Compiler\Visitor\Dump();
echo $dump->visit($ast);

/**
 * Will output:
 *     >  #object
 *     >  >  #pair
 *     >  >  >  token(string, foo)
 *     >  >  >  token(true, true)
 *     >  >  #pair
 *     >  >  >  token(string, bar)
 *     >  >  >  #array
 *     >  >  >  >  token(null, null)
 *     >  >  >  >  token(number, 42)
 */
```

Pretty simple.

### Compiler in CLI

[](#compiler-in-cli)

This library proposes a script to parse and apply a visitor on a data with a specific grammar. Very useful. Moreover, we can use pipe (because `Hoa\File\Read` —please, see the [`Hoa\File`library](http://central.hoa-project.net/Resource/Library/File/)— supports `0` as `stdin`), thus:

```
$ echo '[1, [1, [2, 3], 5], 8]' | hoa compiler:pp Json.pp 0 --visitor dump
>  #array
>  >  token(number, 1)
>  >  #array
>  >  >  token(number, 1)
>  >  >  #array
>  >  >  >  token(number, 2)
>  >  >  >  token(number, 3)
>  >  >  token(number, 5)
>  >  token(number, 8)
```

You can apply any visitor classes.

### Errors

[](#errors)

Errors are well-presented:

```
$ echo '{"foo" true}' | hoa compiler:pp Json.pp 0 --visitor dump
Uncaught exception (Hoa\Compiler\Exception\UnexpectedToken):
Hoa\Compiler\Llk\Parser::parse(): (0) Unexpected token "true" (true) at line 1
and column 8:
{"foo" true}
       ↑
in hoa://Library/Compiler/Llk/Parser.php at line 1
```

### Samplers

[](#samplers)

Some algorithms are available to generate data based on a grammar. We will give only one example with the coverage-based generation algorithm that will activate all branches and tokens in the grammar:

```
$sampler = new Hoa\Compiler\Llk\Sampler\Coverage(
    // Grammar.
    Hoa\Compiler\Llk\Llk::load(new Hoa\File\Read('Json.pp')),
    // Token sampler.
    new Hoa\Regex\Visitor\Isotropic(new Hoa\Math\Sampler\Random())
);

foreach ($sampler as $i => $data) {
    echo $i, ' => ', $data, "\n";
}

/**
 * Will output:
 *     0 => true
 *     1 => {" )o?bz " : null , " %3W) " : [false, 130    , " 6"   ]  }
 *     2 => [{" ny  " : true } ]
 *     3 => {" Ne;[3 " :[ true , true ] , " th: " : true," C[8} " :   true }
 */
```

Research papers
---------------

[](#research-papers)

- *Grammar-Based Testing using Realistic Domains in PHP*, presented at [A-MOST 2012](https://sites.google.com/site/amost2012/) (Montréal, Canada) ([article](https://hoa-project.net/En/Literature/Research/Amost12.pdf), [presentation](http://keynote.hoa-project.net/Amost12/EDGB12.pdf), [details](https://hoa-project.net/En/Event/Amost12.html)).

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Compiler`](https://central.hoa-project.net/Documentation/Library/Compiler) contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.1% 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.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

1411d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/790fd24da129907d373559f60c6994f664f06e3f518502c03580cc9f3594615e?d=identicon)[hiqdev](/maintainers/hiqdev)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (366 commits)")[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (7 commits)")[![ValeriyShnurovoy](https://avatars.githubusercontent.com/u/16237008?v=4)](https://github.com/ValeriyShnurovoy "ValeriyShnurovoy (6 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (3 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (2 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (2 commits)")[![SilverFire](https://avatars.githubusercontent.com/u/4499203?v=4)](https://github.com/SilverFire "SilverFire (1 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")[![tafid](https://avatars.githubusercontent.com/u/3338188?v=4)](https://github.com/tafid "tafid (1 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![lovenunu](https://avatars.githubusercontent.com/u/6106094?v=4)](https://github.com/lovenunu "lovenunu (1 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (1 commits)")[![jwage](https://avatars.githubusercontent.com/u/97422?v=4)](https://github.com/jwage "jwage (1 commits)")

---

Tags

randomlanguagecoverageparserlibrarylexertokenregularsyntaxcompilersamplertraceastgrammaralgebraiccontext-freeruleppisotropicuniformexhaustivell1llk

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hiqdev-hoa-compiler/health.svg)

```
[![Health](https://phpackages.com/badges/hiqdev-hoa-compiler/health.svg)](https://phpackages.com/packages/hiqdev-hoa-compiler)
```

###  Alternatives

[unionofrad/li3_quality

This li₃ plugin adds code quality assurance to your toolbelt.

1288.2k](/packages/unionofrad-li3-quality)[yoeunes/regex-parser

A powerful PCRE regex parser with lexer, AST builder, validation, ReDoS analysis, and syntax highlighting. Zero dependencies, blazing fast, and production-ready.

2946.4k5](/packages/yoeunes-regex-parser)

PHPackages © 2026

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