GithubHelp home page GithubHelp logo

jdrew1303 / inertia Goto Github PK

View Code? Open in Web Editor NEW

This project forked from honza/inertia

0.0 1.0 0.0 59 KB

A Lisp to Javascript compiler

License: BSD 2-Clause "Simplified" License

Makefile 1.16% JavaScript 98.52% Shell 0.32%

inertia's Introduction

inertia

Build Status

A LISP to Javascript compiler.

work in progress

a learning exercise

Read the accompanying blog post.

How it works

It uses PEG.js to parse the source to a Parser API compatible AST. The AST is then transformed to Javascript via escodegen.

It can optionally compress the output via Uglify.

Example

Source:

(def name "honza")

(def greet
  (fn [name]
    (console.log "hey" name)))

(greet name)

Output:

var name = 'honza';
var greet = function (name) {
    return console.log('hey', name);
};
greet(name);

Usage

Usage: inertia [options] <file...>

Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -t, --ast            Print the AST
    -o, --output [file]  Redirect output to file
    -c, --compress       Minify with uglify

You can use the Makefile to install the dependencies:

$ make install

Or to build the compiler:

$ make

Or to build all the examples:

$ make example

What works

  • def
  • list
  • +, -, *, /, =, !=, <, >, <=, >=
  • if
  • (fn [] ...)
  • {}, {"name" "honza"}
  • comments ;;
  • let

Standard library

  • nth
  • first
  • rest
  • second
  • last
  • partition
  • cons
  • conj
  • get
  • map
  • filter
  • update (update a key in a map (update obj key value))

Note: The standard library functions are modelled after Clojure.

join

join two strings

expose

export a name in a module

(expose "name" name)

will compile to

module.exports['name'] = name;

TODO

  • Macro support

License

BSD, short and sweet

Feedback

All feedback is most welcome. Open an issue for any purpose.

inertia's People

Contributors

honza avatar

Watchers

James Drew 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.