<commit_before># CoffeeScript PHP

A port of the [CoffeeScript](http://jashkenas.github.com/coffee-script/)
compiler to PHP.

## Status

CoffeeScript version **1.1.1** has been fully ported over (see
[tags](http://github.com/alxlit/coffeescript-php/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](http://getcomposer.org) to install
and autoload CoffeeScript. Alternatively you can load it manually:


```php
<?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
<?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](http://pear.php.net/package/PHP_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.
<commit_msg>updated version number and notes<commit_after># CoffeeScript PHP

A port of the [CoffeeScript](http://jashkenas.github.com/coffee-script/)
compiler to PHP.

## Status

CoffeeScript version **1.3.1** has been fully ported over (see
[tags](http://github.com/alxlit/coffeescript-php/tags)). Compiled code nearly
matches the reference 100%, except for [#11](https://github.com/alxlit/coffeescript-php/issues/11)
(a good thing). 

## Requirements

PHP 5.3+ (uses namespaces, anonymous functions).

## Install

It's recommended that you use [Composer](http://getcomposer.org) to install
and autoload CoffeeScript. Alternatively you can load it manually:

```php
<?php

require 'vendor/CoffeeScript/Init.php';

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

?>
```

## Usage

The API is really basic (single `compile` function). I don't plan on expanding
it further (keep it simple).

```php
<?php

$file = 'path/to/source.coffee';

try
{
  $coffee = file_get_contents($file);

  // See available options below.
  $js = CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
}
catch (Exception $e)
{
  echo $e->getMessage();
}

?>
```

Available options:

  * **filename** - The source filename, formatted into error messages
  * **header** - Add a "Generated by..." header
  * **rewrite** - Enable the rewriter (debugging)
  * **tokens** - Reference to token stream (debugging)
  * **trace** - File to write parser trace to (debugging)

## 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

#### What was the motivation for this project?

I was using PHP a lot at the time and wanted to use, learn more about, and
potentially contribute back to the CoffeeScript project. I thought it'd be nice
to have a native version gave it a shot.

#### 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](http://pear.php.net/package/PHP_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.

{'fraction_non_alphanumeric': 0.10070778564206269, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 4.393675027262813, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2026663', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1391, 'n_words': 641}