GithubHelp home page GithubHelp logo

chiehwen / sweet.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sweet-js/sweet-core

0.0 2.0 0.0 909 KB

Sweeten your JavaScript.

Home Page: http://sweetjs.org

License: BSD 2-Clause "Simplified" License

sweet.js's Introduction

sweet.js

Hygienic Macros for JavaScript!

  • Documentation at sweetjs.org.
  • Overview and motivation in this talk.
  • Example macros on the wiki.
  • Mailing list for discussion
  • IRC channel #sweet.js on irc.mozilla.org

Use

Using Node

Install with npm:

$ npm install sweet.js

To try it out make a file test_macros.sjs:

// functions can now be spelled def!
macro def {
  case $name:ident $params $body => {
    function $name $params $body
  }
}
def add (a, b) {
  return a + b;
}

console.log( add(3, 7) );

And compile it with sjs:

$ sjs -o output.js test_macros.sjs
$ node output.js
10

Alternately you can require an sjs file from node. For example, in main.js add:

var sjs = require('sweet.js'),
    example = require('./example');

example.one;

Where ./example.sjs contains:

macro A {
    case ($a + $b) => {
        $a
    }
}

exports.one = A(1 + 2);

And just run main.js in node.

Using AMD in the browser

An AMD loader is provided at require-sweet.

define(['sweeten!a/javascript/dep-with-macros'], function(dep) {
  // dep is compiled to JS at this point.
});

Hacking

Install the dev dependencies:

$ npm install --dev

And run the tests:

$ npm test

Changelog

  • 0.1.2
    • :expr parse class working #28
    • hygiene fixes #15 #17
    • allowing macros to override keywords #33
    • major refactoring of expander
  • 0.1.1
    • node autoloading, AMD support
    • fixes to issues #18, #24, #26, #40
  • 0.1.0 (initial release)

sweet.js's People

Contributors

disnet avatar puffnfresh avatar carlqlange avatar int3 avatar magnetised avatar iammerrick avatar parndt avatar tuchida avatar

Watchers

Chuck Yang avatar James Cloos 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.