Skip to content

Commit

Permalink
compiler support for bidi, arrow kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Aug 12, 2017
1 parent 79e5f5c commit 729be43
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
27 changes: 21 additions & 6 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.14 | Documentation</title>
<title>jssm 4.1.15 | 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.14</code></div>
<div class='mb1'><code>4.1.15</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "4.1.14",
"version": "4.1.15",
"engines": {
"node": ">=6.0.0"
},
Expand Down
7 changes: 5 additions & 2 deletions src/demo/index.html
Expand Up @@ -16,10 +16,13 @@

<script defer type="text/javascript">
/* eslint-disable */

let jssm, sm;

window.onload = () => {

let jssm = require('jssm'),
sm = jssm.sm;
jssm = require('jssm');
sm = jssm.sm;

document.body.innerHTML = `<h1>Ready</h1><p>JSSM has now been loaded at version ${jssm.version}, and is bound to the global <code>jssm</code> (aka <code>window.jssm</code>.) Also, the state machine template string tag is exposed as <code>sm</code> (aka <code>window.sm</code>).</p><p>Please open a console and type something like</p><p><code>var traffic_light = sm<b>\` off -> red => green => yellow => red; [red yellow green] ~> off; \`</b>;</code></p><p>Now you have a working state machine to play with:</p><pre>&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("green");\nfalse\n\n&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("red");\ntrue\n\n&gt; traffic_light.state();\n"red"</pre><p>Consoles are <kbd>f12</kbd> on Windows and Linux PCs, or <kbd>command-option-j</kbd> on Macs.</p>`;

Expand Down
5 changes: 3 additions & 2 deletions src/js/jssm-types.js
Expand Up @@ -148,8 +148,9 @@ type JssmCompileRule = {

type JssmCompileSe<NT> = {

to : NT,
se : JssmCompileSe<NT>
to : NT,
se : JssmCompileSe<NT>,
kind : JssmArrow

};

Expand Down
36 changes: 31 additions & 5 deletions src/js/jssm.js
Expand Up @@ -102,12 +102,38 @@ function arrow_right_kind(arrow : JssmArrow) : JssmArrowKind {



function compile_rule_transition_step<mNT>(acc : Array<mixed>, from : mNT, to : mNT, se : JssmCompileSe<mNT>) : mixed { // todo flow describe the parser representation of a transition step extension
function compile_rule_transition_step<mNT>(
acc : Array<mixed>,
from : mNT,
to : mNT,
this_se : JssmCompileSe<mNT>,
next_se : JssmCompileSe<mNT>
) : mixed { // todo flow describe the parser representation of a transition step extension

const right : any = {
from,
to,
kind: arrow_right_kind(this_se.kind)
};

const left : any = {
from : to,
to : from,
kind : arrow_left_kind(this_se.kind)
};

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

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

if (se) {
return compile_rule_transition_step(new_acc, to, se.to, se.se);
if (next_se) {
return compile_rule_transition_step(new_acc, to, next_se.to, next_se, next_se.se);
} else {
return new_acc;
}
Expand All @@ -117,7 +143,7 @@ function compile_rule_transition_step<mNT>(acc : Array<mixed>, from : mNT, to :


function compile_rule_handle_transition<mNT>(rule : JssmCompileSeStart<mNT>) : mixed { // todo flow describe the parser representation of a transition
return compile_rule_transition_step([], rule.from, rule.se.to, rule.se.se);
return compile_rule_transition_step([], rule.from, rule.se.to, rule.se, rule.se.se);
}


Expand Down

0 comments on commit 729be43

Please sign in to comment.