Skip to content

Commit

Permalink
support for array targets and array destinations in transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Aug 13, 2017
1 parent 305e9a0 commit c8ac664
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 35 deletions.
43 changes: 30 additions & 13 deletions dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 4.1.17 | Documentation</title>
<title>jssm 4.1.18 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>4.1.17</code></div>
<div class='mb1'><code>4.1.18</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "4.1.17",
"version": "4.1.18",
"engines": {
"node": ">=6.0.0"
},
Expand Down
43 changes: 26 additions & 17 deletions src/js/jssm.js
Expand Up @@ -116,25 +116,34 @@ function compile_rule_transition_step<mNT, mDT>(
next_se : JssmCompileSe<mNT>
) : Array< JssmTransition<mNT, mDT> > { // todo flow describe the parser representation of a transition step extension

const right : JssmTransition<mNT, mDT> = {
from,
to,
kind: arrow_right_kind(this_se.kind)
};
const edges : Array< JssmTransition<mNT, mDT> > = [];

const left : JssmTransition<mNT, mDT> = {
from : to,
to : from,
kind : arrow_left_kind(this_se.kind)
};
const uFrom : Array< mNT > = (Array.isArray(from)? from : [from]),
uTo : Array< mNT > = (Array.isArray(to)? to : [to] );

uFrom.map( (f:mNT) => {
uTo.map( (t:mNT) => {

const right : JssmTransition<mNT, mDT> = {
from : f,
to : t,
kind : arrow_right_kind(this_se.kind)
};

if (right.kind !== 'none') { edges.push(right); }

const left : JssmTransition<mNT, mDT> = {
from : t,
to : f,
kind : arrow_left_kind(this_se.kind)
};

if (left.kind !== 'none') { edges.push(right); }

});
});

const new_acc : Array< JssmTransition<mNT, mDT> > = acc.concat( // todo whargarbl can do better than array mixed
(left.kind === 'none')? right : (
(right.kind === 'none')? left : (
[left, right]
)
)
);
const new_acc : Array< JssmTransition<mNT, mDT> > = acc.concat(edges);

// const new_acc : Array<mixed> = acc.concat({ from, to }); // todo whargarbl can do better than array mixed

Expand Down
42 changes: 42 additions & 0 deletions src/js/tests/array_transitions.js
@@ -0,0 +1,42 @@

/* eslint-disable max-len */

import {describe} from 'ava-spec';

const jssm = require('../../../build/jssm.es5.js');





describe('array on left', async it => {

const aLeft = [{"from":"a","to":"d","kind":"legal"},{"from":"b","to":"d","kind":"legal"},{"from":"c","to":"d","kind":"legal"}];

it('[a b c]->d;', t => t.deepEqual(aLeft, jssm.compile(jssm.parse('[a b c]->d;')).transitions ));

});





describe('array on right', async it => {

const aRight = [{"from":"a","to":"b","kind":"legal"},{"from":"a","to":"c","kind":"legal"},{"from":"a","to":"d","kind":"legal"}];

it('a->[b c d];', t => t.deepEqual(aRight, jssm.compile(jssm.parse('a->[b c d];')).transitions ));

});





describe('array on both sides', async it => {

const aBoth = [{"from":"a","to":"x","kind":"legal"},{"from":"a","to":"y","kind":"legal"},{"from":"a","to":"z","kind":"legal"},{"from":"b","to":"x","kind":"legal"},{"from":"b","to":"y","kind":"legal"},{"from":"b","to":"z","kind":"legal"},{"from":"c","to":"x","kind":"legal"},{"from":"c","to":"y","kind":"legal"},{"from":"c","to":"z","kind":"legal"}];

it('[a b c]->[x y z];', t => t.deepEqual(aBoth, jssm.compile(jssm.parse('[a b c]->[x y z];')).transitions ));

});

0 comments on commit c8ac664

Please sign in to comment.