Giter VIP home page Giter VIP logo

coffeescript-php's Introduction

CoffeeScript PHP

A port of the CoffeeScript compiler to PHP.

Status

CoffeeScript version 1.1.1 has been fully ported over (see tags). Compiled code nearly matches the reference 100%, except for the occasional extra newline. Tons of E_STRICT problems.

Work towards porting version 1.3.1 and making it E_STRICT is taking place on the master branch.

Requirements

PHP 5.3+ (uses namespaces, anonymous functions).

Install

It's recommended that you use Composer to install and autoload CoffeeScript. Alternatively you can load it manually:

<?php

require 'vendor/CoffeeScript/Init.php';

// Load manually
CoffeeScript\Init::load();

?>

Usage

At the moment the API is pretty basic. It'll probably be expanded a bit in the future.

<?php

$coffee = file_get_contents('path/to/source.coffee');

try
{
  $js = CoffeeScript\Compiler::compile($coffee);
}
catch (Exception $e)
{
  echo $e->getMessage();
}

?>

Development

To rebuild the parser run php make.php. Tests are run in the browser; simply clone the repository somewhere Apache can see it and navigate to tests/.

FAQ

Why not modify the original compiler to emit PHP?

The compiler itself depends on Jison, which is written in JavaScript, so you'd have to do something about that... More generally speaking, it'd be much more work to try and sort out all the differences between JavaScript and PHP (object model, core classes/libraries, etc), I imagine. There's also much less incentive to do all that work server side, where the choice to not use one language is, if not easy, at least available.

What parser generator are you using?

Since there's no PHP port of Bison (which the reference compiler uses), we're using a port of Lemon called ParserGenerator.

It's included locally since the PEAR package is unmaintained and seems to be broken. In addition, some minor changes have been made to the parser template (Lempar.php) and the actual generator.

coffeescript-php's People

Contributors

alxlit avatar briannesbitt avatar cschramm avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.