webgraphe/phlip

Embeddable scripts for PHP

v0.3.0 2018-03-07 22:07 UTC

README

Phlip (pronounced \ˈflip\) is an embeddable scripting language for PHP based on s-expressions. In a nutshell:

« It's JSON with closures. »

A lexer and a parser analyze scripts observing Phlip's syntax rules. A script's behavior originates from named data and code elements resolved from a controlled context. Integration is simpler with the Phlipy dialect.

<?php

use Webgraphe\Phlip\Phlipy;
use Webgraphe\Phlip\Program;

// Tokenize and parse code into a program
$program = Program::parse('(lambda (x) (* x x))');
// Bootstrap a new context with the Phlipy dialect
$context = Phlipy::bootstrap();
// Execute program within said context
$square = $program->execute($context);

// In this case, return value is an anonymous function - a lambda - calculating the square of a number
var_dump($square(M_PI)); // (double)9.8696044010894

Install with composer require webgraphe/phlip

Why use Phlip

  • Easy to use
  • Easy to learn
  • Homoiconic (code as data)
  • Transform existing JSON streams with closures and symbols
  • Build your own dialect!
  • Create test suites with phlipunit (built on top of PHPUnit)
  • Ships with a literal REPL