README
======

This is the repository for the RestyScript compiler for OpenResty
written in Haskell. Support for both OpenResty Views and Actions
is provided.

To build this program, you should first install GHC 6.8.2 (or better),
its Parsec, bytestring, and json libraries. On Ubuntu/Debian, the
following commands would install the first two prerequisites.

    $ sudo apt-get install ghc6 libghc6-parsec-dev

The last two dependencies, the json library and bytestring 0.9.1.0 (or
better), require a few more commands to install:

    $ wget http://hackage.haskell.org/packages/archive/json/0.3.3/json-0.3.3.tar.gz
    $ tar -xzf json-0.3.3.tar.gz
    $ cd json-0.3.3
    $ runghc Setup.hs configure --with-compiler=ghc-6.8.2
    $ runghc Setup.hs build
    $ sudo runghc Setup.hs install

And similarly

    $ wget http://hackage.haskell.org/packages/archive/bytestring/0.9.1.0/bytestring-0.9.1.0.tar.gz
    $ tar -xzf bytestring-0.9.1.0.tar.gz
    $ cd bytestring-0.9.1.0/
    $ runghc Setup.lhs configure
    $ runghc Setup.lhs build
    $ sudo runghc Setup.lhs install

After that, you can build this compiler by the following command:

    $ make

The resulting binary executable will be bin/restyscript.

To build an optimized version (with -O2 set) of the compilers, you
can use

    $ make optimized

instead.

Also, a "clean" target is provided to remove the stuff generated by the
default make target.

    $ make clean

You can play with it on the command line. For instance,

    $ echo 'select 3.14' | bin/restyscript view ast rs
    Query [Select [Float 3.14]]
    select 3.14

The first line of output is the internal AST (Abstract Syntax Tree)
used by the compiler while the second line is the (canonicalized)
RestyScript emtted from the AST. In the sample above, the resulting
RestyScript output is exactly the same as the input.

The compiler also comes with a test suite driven by Perl. The scaffold
requires the CPAN modules Test::Base and IPC::Run3. Typically you can
install these two by the following commands:

    $ sudo cpan IPC::Run3 Test::Base

To run the test suite, simply issue

    $ make test

The test cases in the test suite (e.g. t/emit-frags.t and
t/action/emit-frags.t) tell you what these two compilers are currently
able to do.

