Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/honza/inertia
A Lisp to Javascript compiler
https://github.com/honza/inertia
compiler javascript lisp
Last synced: about 3 hours ago
JSON representation
A Lisp to Javascript compiler
- Host: GitHub
- URL: https://github.com/honza/inertia
- Owner: honza
- License: bsd-2-clause
- Created: 2013-05-12T23:20:48.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-08-09T10:22:35.000Z (about 8 years ago)
- Last Synced: 2024-04-16T01:44:54.646Z (7 months ago)
- Topics: compiler, javascript, lisp
- Language: JavaScript
- Size: 57.6 KB
- Stars: 79
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
inertia
=======[![Build Status](https://travis-ci.org/honza/inertia.svg?branch=master)](https://travis-ci.org/honza/inertia)
A LISP to Javascript compiler.
*work in progress*
*a learning exercise*
Read the [accompanying blog post][4].
How it works
------------It uses [PEG.js][1] to parse the source to a [Parser API][2] compatible AST.
The AST is then transformed to Javascript via [escodegen][3].It can optionally compress the output via Uglify.
Example
-------Source:
```clojure
(def name "honza")(def greet
(fn [name]
(console.log "hey" name)))(greet name)
```Output:
```js
var name = 'honza';
var greet = function (name) {
return console.log('hey', name);
};
greet(name);
```Usage
-----Usage: inertia [options]
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 uglifyYou 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
```clojure
(expose "name" name)
```will compile to
```js
module.exports['name'] = name;
```TODO
----* Macro support
License
-------BSD, short and sweet
Feedback
--------All feedback is most welcome. Open an issue for any purpose.
[1]: http://pegjs.majda.cz/
[2]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
[3]: https://github.com/Constellation/escodegen
[4]: http://honza.ca/2013/05/building-a-lisp-to-javascript-compiler