Polygen-PHP

Project Name: Polygen-PHP
Years: 2016-2020
Language: PHP
Status: Released
Sources: https://github.com/RBastianini/polygen-php
Address: https://packagist.org/packages/rb/polygen-php

When I was in high school I somehow discovered the existence of Polygen. I really don't remember how that happened. Polygen is a tool that can process files with "phrase structures" in them called grammars and it is then able to follow the rules described in these grammars to assemble sentences in a more or less random way.

We can think about it as a random sentence generator, although it could also be oversimplifying. Obviously when I learned about Polygen, I could not understand a tenth of what was written in the guide, but I was fascinated about it. Generally speaking, interpreters and compilers always mesmerized me, and this was so frivolous that it could even be used by someone that really didn't know almost anything about compilers and programming.

Many years after, I found myself with a few spare weekends, so I decided to try and write a PHP version of Polygen, so that I could finally use it on my website, something that I often dreamed about doing in the years since I first discovered it.

There already was a similarly named PHP library, but what it really did was just make HTTP requests to the official Polygen website, to get a generated phrase from one of the grammars available for download there, so it was not really doing what I wanted.

Writing an interpreter is not easy, but I decided to do it anyways, reading the guides I could find and learning how other libraries written by more expert people than me were solving certain problems (although, not before having tried for a few afternoons on my own, sometimes actually finding a solution by myself).

I decided to apply some of the good PHP programming practices I learned over the years on how to write reasonably good code, commenting it where needed, adding a lot of tests, having a build pipeline checking my commits. I was happy to reach all these goals.

The lockdown of spring 2020 should be thanked for a good part of these accomplishments: I had much more free time to kill and I did around 60%-70% of the work in this final stretch to get Polygen-PHP compatible with the original Polygen grammar files (with some small additions, like unicode support). The package is available to be installed through composer and I can finally fulfill my dream of having it running on my website. :)

Salutations young myself of past times, I can guarantee you: you will reach enlightenment, by realizing a porting of Polygen in PHP.

S ::= ">"\ Greeting QualifierBefore Myself QualifierAfter
    ^ "," ReassuringBit ^ ":" Prophecy ^","
    by realizing a porting of \polygen in "PHP.";

Greeting ::= hi | greeting | salutations;

QualifierBefore ::= my dear [^est] [old]
    | "well-known"
    | young;

Myself ::= [my ^] self
    | \riccardo
    | author;

QualifierAfter ::= from the [distant] past
    | of (past | ancient | old) times;

ReassuringBit ::= fear not
    | do not fear
    | rest assured
    | \i can (assure | guarantee) you;

Prophecy ::= you will be succesful
    | you will find happyness
    | you will fulfill your destiny
    | you will reach your goal
    | you will reach enlightenment;