Skip to content

fnogatz/babel-plugin-chr

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

babel-plugin-chr

Babel plugin that precompiles CHR.js source code.

Install

npm install babel-plugin-chr

Usage

Run:

babel --plugins chr script.js

Or add the plugin to your .babelrc configuration:

{
  "plugins": [ "chr" ]
}

Example

The plugin will compile the following code:

var CHR = require('chr')
var chr = new CHR()

chr('some @ a ==> b')

into:

var _Runtime = require('chr/runtime');
var chr = {
  Store: new _Runtime.Store(),
  History: new _Runtime.History(),
  Constraints: {},
  Replacements: []
};

chr = (function (chr) {
  chr.a = _Runtime.Helper.dynamicCaller('a');
  chr.Constraints['a/0'] = [];
  chr.b = _Runtime.Helper.dynamicCaller('b');
  chr.Constraints['b/0'] = [];

  chr.Constraints['a/0'][0] = function (constraint) {
    var self = this;
    var ids = [constraint.id];

    if (ids.every(function (id) {
      return self.Store.alive(id);
    })) {
      if (_Runtime.Helper.allDifferent(ids)) {
        if (self.History.notIn('some', ids)) {
          self.History.add('some', ids);
          self.b();
        }
      }
    }
  };

  return chr;
})(chr);

It supports the normal CHR.js syntax as specified here: fnogatz/CHR.js

About

Babel plugin that precompiles CHR.js source code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published