Skip to content

Commit

Permalink
Adds support for rounding (fixes StoneCypher/fsl#362) and diagonals (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jan 27, 2020
1 parent 4b42bd5 commit de75a04
Show file tree
Hide file tree
Showing 15 changed files with 9,122 additions and 8,272 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,5 @@
* [[`4b42bd5493`](https://github.com/StoneCypher/jssm/commit/4b42bd5493)] - Merge pull request #394 from StoneCypher/FixOctothorpeBug (John Haugeland)
* [[`c0456fefed`](https://github.com/StoneCypher/jssm/commit/c0456fefed)] - fixes StoneCypher/fsl#354 octothorpe bug on direct colors; fixes StoneCypher/fsl/issues/359 rgb order decl (John Haugeland)
* [[`e4e3c25697`](https://github.com/StoneCypher/jssm/commit/e4e3c25697)] - improve error message for directions. much better testing on named colors (John Haugeland)
* [[`28d9b1022a`](https://github.com/StoneCypher/jssm/commit/28d9b1022a)] - Merge branch 'master' of github.com:StoneCypher/jssm (John Haugeland)
* [[`0c05c76100`](https://github.com/StoneCypher/jssm/commit/0c05c76100)] - version bump; parser does colors and shapes on node now, fixes #339, fixes #340, fixes #341 (John Haugeland)
Expand Down
5,760 changes: 3,014 additions & 2,746 deletions dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

5,760 changes: 3,014 additions & 2,746 deletions dist/jssm.es6.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jssm.es6.js.map

Large diffs are not rendered by default.

5,760 changes: 3,014 additions & 2,746 deletions dist/jssm.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jssm.iife.js.map

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 5.25.1 | Documentation</title>
<title>jssm 5.26.0 | Documentation</title>
<meta name='description' content='A Javascript finite state machine (FSM) with a terse DSL and a simple API. Well tested, and typed with Flowtype. MIT License.'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>5.25.1</code></div>
<div class='mb1'><code>5.26.0</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": "5.25.1",
"version": "5.26.0",
"engines": {
"node": ">=6.0.0"
},
Expand Down
14 changes: 13 additions & 1 deletion src/js/jssm-dot.peg
Expand Up @@ -157,6 +157,10 @@ Arrow "arrow"



Boolean
= "true" { return true; }
/ "false" { return false; }

HexDigit
= [0-9a-fA-F]

Expand Down Expand Up @@ -490,8 +494,8 @@ Rgba8
Color "color" // hoboy
= SvgColor
/ Rgba8
/ Rgba4
/ Rgb6
/ Rgba4
/ Rgb3


Expand Down Expand Up @@ -798,12 +802,20 @@ SdStateBorderColor "border color"
SdStateShape "shape"
= WS? "shape" WS? ":" WS? value:GvizShape WS? ";" WS? { return { key:'shape', value }; }

SdStateDiagonals "diagonals"
= WS? "diagonals" WS? ":" WS? value:Boolean WS? ";" WS? { return { key:'diagonals', value }; }

SdStateRounding "shape"
= WS? "rounding" WS? ":" WS? value:Boolean WS? ";" WS? { return { key:'rounding', value }; }

StateDeclarationItems
= SdStateColor
/ SdStateTextColor
/ SdStateBackgroundColor
/ SdStateBorderColor
/ SdStateShape
/ SdStateDiagonals
/ SdStateRounding

StateDeclarationDesc
= "{" WS? items:StateDeclarationItems* WS? "}" { return items; }
Expand Down
2 changes: 2 additions & 0 deletions src/js/jssm.ts
Expand Up @@ -397,6 +397,8 @@ function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateD

case 'shape' : state_decl.shape = d.value; break;
case 'color' : state_decl.color = d.value; break;
case 'rounding' : state_decl.rounding = d.value; break;
case 'diagonals' : state_decl.diagonals = d.value; break;

case 'text-color' : state_decl.textColor = d.value; break;
case 'background-color' : state_decl.backgroundColor = d.value; break;
Expand Down
3 changes: 3 additions & 0 deletions src/js/jssm_types.ts
Expand Up @@ -171,6 +171,9 @@ type JssmStateDeclaration = {

shape? : JssmShape,
color? : JssmColor,
rounding? : boolean,
diagonals? : boolean,

textColor? : JssmColor,
backgroundColor? : JssmColor,
borderColor? : JssmColor,
Expand Down
45 changes: 24 additions & 21 deletions src/js/tests/colors.js
Expand Up @@ -13,34 +13,37 @@ const jssm = require('../../../build/jssm.es5.cjs.js'),



describe('Named colors', async it => {
describe('Colors', async it => {

/* eslint-disable max-nested-callbacks */

// edge things
['edge_color'].map(prop =>
const ColorSets = [
{ label: "Named colors", dataset: NamedColors },
{ label: "Direct colors", dataset: [ '#ABC', '#ABCF', '#AABBCC', '#AABBCCFF' ] }
];

NamedColors.map(col =>
[col, col.toLowerCase()].map(repres =>
it(`Color "${repres}" parses as ${prop}`, t =>
t.notThrows( () => { const _foo = sm`machine_name: bob; a-> { ${prop}: ${repres}; } b;`; })
)
)
)

);
ColorSets.map( ({label, dataset}) =>
dataset.map(col => {

// state things
['color', 'background-color', 'text-color', 'border-color'].map(prop =>

NamedColors.map(col =>
[col, col.toLowerCase()].map(repres =>
it(`Color "${repres}" parses as ${prop}`, t =>
t.notThrows( () => { const _foo = sm`machine_name: bob; state a: { ${prop}: ${repres}; }; a -> b;`; })
// edge things
['edge_color'].map(prop =>
[col, col.toLowerCase()].map(repres =>
it(`${label} - Color "${repres}" parses as ${prop}`, t =>
t.notThrows( () => { const _foo = sm`machine_name: bob; a-> { ${prop}: ${repres}; } b;`; })
)
)
);

// state things
['color', 'background-color', 'text-color', 'border-color'].map(prop =>
[col, col.toLowerCase()].map(repres =>
it(`${label} - Color "${repres}" parses as ${prop}`, t =>
t.notThrows( () => { const _foo = sm`machine_name: bob; state a: { ${prop}: ${repres}; }; a -> b;`; })
)
)
)
)
);

})
);

/* eslint-enable max-nested-callbacks */
Expand Down
3 changes: 1 addition & 2 deletions src/js/tests/dot_preamble.js
@@ -1,6 +1,5 @@

import { describe } from 'ava-spec';
import { FlowDirections } from './constants';
import { describe } from 'ava-spec';



Expand Down
33 changes: 29 additions & 4 deletions src/js/tests/shapes.js
Expand Up @@ -15,12 +15,37 @@ const jssm = require('../../../build/jssm.es5.cjs.js'),

describe('GraphViz Shapes', async it => {

Shapes.map(shape =>
Shapes.map(shape => {
let mach = undefined;
it(`Shape "${shape}" parses as a shape`, t =>
t.notThrows( () => { const _foo = sm`state c: { shape: ${shape}; }; a -> b;`; }) ) );
t.notThrows( () => { mach = sm`state c: { shape: ${shape}; }; a -> b;`; }) );
it(`Result shape ${shape} is what it's supposed to be`, t =>
t.is( mach.state_declaration("c").shape, shape ));
});

// misspelling the last character of restrictionsite gets parser coverage
it('handles parse end', t =>
t.throws( () => { const _foo = sm`state c: { shape: restrictionsitz; }; a -> b;`; }) );
t.throws( () => { const _foo = sm`state c: { shape: thisIsNotAShapeSoItShouldThrow; }; a -> b;`; }) );

});





describe('Rounding', async it =>
it('rounds', t => {
t.is(sm`state a: { rounding: true; }; a->b;`.state_declaration("a").rounding, true);
t.is(sm`state a: { rounding: false; }; a->b;`.state_declaration("a").rounding, false);
})
);





describe('Diagonals', async it =>
it('cuts', t =>{
t.is(sm`state a: { diagonals: true; }; a->b;`.state_declaration("a").diagonals, true);
t.is(sm`state a: { diagonals: false; }; a->b;`.state_declaration("a").diagonals, false);
})
);

0 comments on commit de75a04

Please sign in to comment.