2017 © Pedro PelĂĄez
 

library primi

A scripting language written in PHP & executable within PHP.

image

smuuf/primi

A scripting language written in PHP & executable within PHP.

  • Saturday, June 2, 2018
  • by smuuf
  • Repository
  • 1 Watchers
  • 18 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

Primi , (*1)

Primi

A scripting language written in PHP & interpreted in PHP., (*2)

Primi is meant for PHP developers who want to allow their clients to write their own custom logic. Primi allows you (the developer) to execute untrusted code (provided simply as a string) inside a sandbox, safely separated from its surroundings. , (*3)


Code Climate Packagist
Maintainability Test Coverage Latest Stable Version License Total Downloads

Quick access

Rationale

Primi - as things sometimes go in life - began as an answer to a practical problem: I needed some general-purpose (ie. not too much domain-specific) scripting language that my other app's users could use to write their simple custom logic. I needed some universally usable and primitive scripting thing, with familiar syntax (PHP-like x C-like x JS-like) and one that could be safely executed inside pure PHP environment (no external depedencies on v8js, v8 and whatnot - meaning Javascript is out of the game...)., (*4)

Thus, Primi was (mostly as an experiment) created., (*5)

Installation

You can either use Primi as a standalone package (a) - for its development, making contributions, debugging it, or to just play with it. Or you can use Primi in your own projects (b) by installing it as a Composer dependency., (*6)

You'll want either one of these:

  • git clone https://github.com/smuuf/primi.git (standalone use)
  • composer require smuuf/primi (using Primi as a library in your own project)

a) Standalone installation

  1. Clone this repo.
    • git clone https://github.com/smuuf/primi.git
  2. Install Composer dependencies.
    • composer install
  3. Run something with Primi CLI.
    • chmod +x ./primi && ./primi -s -c "a = 1 + 2 / 3;"

Convenient installation Onelinerℱ:

git clone https://github.com/smuuf/primi.git && cd primi && composer install && chmod +x ./primi && ./primi -s -c "msg = 'Primi works.';"

Extra stuff:

  • Register Primi's CLI executable for current user so typing primi will behave like a binary (otherwise you'd need to write ./primi and would have to be in the right directory):, (*7)

    ./bin/registerbin
    

    Note: This will add an alias in .bashrc for current user., (*8)

  • Run tests (tests are located inside ./tests/ directory): ./bin/test
  • Rebuild parser (when you modify Primi's grammar definitions, you will want to rebuild the parser to reflect the changes): ./bin/buildparser

b) Using Primi as a library

  1. First, install Primi Composer package: composer require smuuf/primi
  2. Then use it like this:
<?php

require __DIR__ . "/vendor/autoload.php";

$context = new \Smuuf\Primi\Context;
$interpreter = new \Smuuf\Primi\Interpreter($context);

try {

    // Let the interpreter run a source code.
    $interpreter->run('a = 1; b = a + 2; c = "some string"; d = c + " extra thing";');

    // Get defined variables from primary context and print them.
    foreach ($context->getVariables() as $name => $value) {
        printf("%s (%s) ... %s\n", $name, $value::TYPE, $value->getCoreValue());
    }

} catch (\Smuuf\Primi\ErrorException $e) {
    die($e->getMessage());
}

Running this code would output:, (*9)

a (number) ... 1
b (number) ... 3
c (string) ... some string
d (string) ... some string extra thing

REPL mode

Primi provides a convenient "sandbox" REPL mode which is launched by executing ./primi without any argument. You can use this for messing around with the language or to test any new stuff you might be trying to implement (e.g. your own Primi extensions written in PHP)., (*10)

REPL example usage, (*11)

In this mode, all statements are executed when entered and the result value of the last expression is returned. REPL commands history is preserved between separate sessions (history is stored in ~/.primi_history file)., (*12)

Language reference

The basics of the language syntax and data types are found here: https://github.com/smuuf/primi/blob/master/docs/language_reference.md, (*13)

The Versions

02/06 2018

dev-master

9999999-dev

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/05 2018

dev-lazy

dev-lazy

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/04 2018

dev-syntax

dev-syntax

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2018

0.0.15.1

0.0.15.1

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2018

0.0.15

0.0.15.0

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2018

dev-arr

dev-arr

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/03 2018

0.0.14

0.0.14.0

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/03 2018

dev-pstl

dev-pstl

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/03 2018

0.0.13

0.0.13.0

A scripting language written in PHP & executable within PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

16/01 2018

0.0.12

0.0.12.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

16/01 2018

0.0.11

0.0.11.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

21/12 2017

0.0.10

0.0.10.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

20/12 2017

0.0.9

0.0.9.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

15/12 2017

0.0.8

0.0.8.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/12 2017

0.0.7

0.0.7.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

0.0.6

0.0.6.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

15/11 2017

0.0.5

0.0.5.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/11 2017

0.0.4

0.0.4.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/11 2017

0.0.3

0.0.3.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

31/10 2017

0.0.2

0.0.2.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

23/10 2017

0.0.1

0.0.1.0

A scripting language written in PHP & embeddable into PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires