piff
A language that compiles down to PHP.
Last updated a year ago by allain .
ISC · Original npm · Tarball · package.json
$ cnpm install piff 
SYNC missed versions from official npm registry.

piff

A language that compiles down to PHP.

Warning: piff is a work in progress. Its syntax might change until version 1.0

Why?

PHP has warts; It's also the foundation of many Legacy Systems (including one I have to maintain). This tool is my attempt to maintain my sanity in this light.

It has had a good number of language features bolted on over the years (Closures, OO, Traits, Namespaces, etc...) but, because of its syntax, it's hard to appreciate them.

For example, when defining a closure you must explicitly declare all variables is uses, even if it's obvious from the code what the programmer had in mind.

I'm aware that there are tools for compiling JavaScript to PHP, but I didn't want to make promises about the conceptual model that are not true. PHP is not just an Uglier JavaScript.

Why the idiotic name?

If you sound out PHP, it kinda sounds like Piff. In the same way that piff kinda feels like PHP.

Features / Opinions

  1. Semicolons are optional
  2. Use clauses are automatically inferred
  3. Functions can be composed using a special pipe syntax
  4. Defining classes is less verbose
  5. Defining arrays is less verbose
  6. Formatting should be part of the language (like in go)
  7. ...

A Quick Piff Example

// Calling Overriden methods with parent
class A {
  say(m) {
    print(m)
  }
}

class B extends A {
  say(m) {
    parent(m + '!')
  }
}

// @a expands to $this->a
class A {
  prefix = 'Hello: '
  say(m) { print(@prefix + m) }
}

// @@field expands to self::$field, @@m() expands to self::m()
class B {
  static prefix = 'Hello: '
  static say(m) { print(@@prefix + m) }
}

// named functions
fn add(a, b) { return a + b }

// Anonymous functions (with expression as block)
mult = fn (a, b) a * b

// Automatically figures out "use" clause
ticks = []
tick = fn() { ticks[] = mktime() }

// function composition alternate syntax
a() |> b(_) |> c(_) // is the same as: c(b(a()))

Installation

npm install -g piff

Usage

Command line usage is available using piff-cli

Programmatic usage can be performed like so:

const piff = require('piff')
let php = piff.transpile("fn add(a, b) { return a + b }\n echo(add(1,2))")
console.log(php) // <?php echo("hello" . "\n")?>

console.log(piff.format("fn add(a,b){return a+b}")
// outputs a nicely formatted version of the piff code

Command line usage

Current Tags

  • 0.8.7                                ...           latest (a year ago)

54 Versions

  • 0.8.7                                ...           a year ago
  • 0.8.6                                ...           2 years ago
  • 0.8.5                                ...           2 years ago
  • 0.8.4                                ...           2 years ago
  • 0.8.3                                ...           2 years ago
  • 0.8.2                                ...           2 years ago
  • 0.8.1                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.2                                ...           2 years ago
  • 0.7.1                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.18                                ...           3 years ago
  • 0.5.17                                ...           3 years ago
  • 0.5.16                                ...           3 years ago
  • 0.5.15                                ...           3 years ago
  • 0.5.14                                ...           3 years ago
  • 0.5.13                                ...           3 years ago
  • 0.5.12                                ...           3 years ago
  • 0.5.11                                ...           3 years ago
  • 0.5.10                                ...           3 years ago
  • 0.5.9                                ...           3 years ago
  • 0.5.8                                ...           3 years ago
  • 0.5.7                                ...           3 years ago
  • 0.5.6                                ...           3 years ago
  • 0.5.5                                ...           3 years ago
  • 0.5.4                                ...           3 years ago
  • 0.5.3                                ...           3 years ago
  • 0.5.2                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.11                                ...           3 years ago
  • 0.4.10                                ...           3 years ago
  • 0.4.9                                ...           3 years ago
  • 0.4.8                                ...           3 years ago
  • 0.4.7                                ...           3 years ago
  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           3 years ago
  • 0.4.4                                ...           3 years ago
  • 0.4.3                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (2)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |