state-machine-cat 13.0.1 → 13.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse/index.mjs +6 -8
- package/dist/parse/parser-helpers.mjs +12 -12
- package/dist/parse/smcat/smcat-parser.mjs +10 -10
- package/dist/render/dot/attributebuilder.mjs +14 -5
- package/dist/render/dot/index.mjs +3 -3
- package/dist/state-machine-model.mjs +17 -19
- package/dist/transform/desugar.mjs +17 -13
- package/dist/version.mjs +1 -1
- package/package.json +3 -3
package/dist/parse/index.mjs
CHANGED
|
@@ -4,13 +4,7 @@ import { parse as parseSmCat } from "./smcat/parse.mjs";
|
|
|
4
4
|
import { parse as parseSCXML } from "./scxml/index.mjs";
|
|
5
5
|
import $schema from "./smcat-ast.schema.mjs";
|
|
6
6
|
const ajv = new Ajv();
|
|
7
|
-
|
|
8
|
-
if (!ajv.validate(pSchema, pObject)) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
`The provided JSON is not a valid state-machine-cat AST: ${ajv.errorsText()}.\n`,
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
7
|
+
const validate = ajv.compile($schema);
|
|
14
8
|
export default {
|
|
15
9
|
getAST(pScript, pOptions) {
|
|
16
10
|
let lReturnValue = pScript;
|
|
@@ -21,7 +15,11 @@ export default {
|
|
|
21
15
|
} else if (typeof pScript === "string") {
|
|
22
16
|
lReturnValue = JSON.parse(pScript);
|
|
23
17
|
}
|
|
24
|
-
|
|
18
|
+
if (!validate(lReturnValue)) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`The provided JSON is not a valid state-machine-cat AST: ${ajv.errorsText()}.\n`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
25
23
|
return lReturnValue;
|
|
26
24
|
},
|
|
27
25
|
};
|
|
@@ -64,22 +64,22 @@ function extractUndeclaredStates(pStateMachine, pKnownStateNames) {
|
|
|
64
64
|
pKnownStateNames ?? getAlreadyDeclaredStates(pStateMachine);
|
|
65
65
|
pStateMachine.states = pStateMachine?.states ?? [];
|
|
66
66
|
const lTransitions = pStateMachine?.transitions ?? [];
|
|
67
|
-
pStateMachine.states.filter(isComposite)
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
for (const lState of pStateMachine.states.filter(isComposite)) {
|
|
68
|
+
lState.statemachine.states = extractUndeclaredStates(
|
|
69
|
+
lState.statemachine,
|
|
70
70
|
pKnownStateNames,
|
|
71
71
|
);
|
|
72
|
-
}
|
|
73
|
-
lTransitions
|
|
74
|
-
if (!stateExists(pKnownStateNames,
|
|
75
|
-
pKnownStateNames.push(
|
|
76
|
-
pStateMachine.states.push(initState(
|
|
72
|
+
}
|
|
73
|
+
for (const lTransition of lTransitions) {
|
|
74
|
+
if (!stateExists(pKnownStateNames, lTransition.from)) {
|
|
75
|
+
pKnownStateNames.push(lTransition.from);
|
|
76
|
+
pStateMachine.states.push(initState(lTransition.from));
|
|
77
77
|
}
|
|
78
|
-
if (!stateExists(pKnownStateNames,
|
|
79
|
-
pKnownStateNames.push(
|
|
80
|
-
pStateMachine.states.push(initState(
|
|
78
|
+
if (!stateExists(pKnownStateNames, lTransition.to)) {
|
|
79
|
+
pKnownStateNames.push(lTransition.to);
|
|
80
|
+
pStateMachine.states.push(initState(lTransition.to));
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
83
|
return pStateMachine.states;
|
|
84
84
|
}
|
|
85
85
|
function classifyForkJoin(pInComingCount, pOutGoingCount) {
|
|
@@ -345,13 +345,13 @@ function peg$parse(input, options) {
|
|
|
345
345
|
}
|
|
346
346
|
function peg$f8(notes, id, extended_state_attributes, actions, statemachine) {
|
|
347
347
|
let lState = parserHelpers.initState(id);
|
|
348
|
-
(extended_state_attributes || [])
|
|
348
|
+
for (const lExtendedAttribute of extended_state_attributes || []) {
|
|
349
349
|
parserHelpers.setIf(
|
|
350
350
|
lState,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
)
|
|
354
|
-
|
|
351
|
+
lExtendedAttribute.name,
|
|
352
|
+
lExtendedAttribute.value,
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
355
|
parserHelpers.setIf(
|
|
356
356
|
lState,
|
|
357
357
|
"typeExplicitlySet",
|
|
@@ -408,13 +408,13 @@ function peg$parse(input, options) {
|
|
|
408
408
|
parserHelpers.parseTransitionExpression(label),
|
|
409
409
|
);
|
|
410
410
|
}
|
|
411
|
-
(extended_attributes || [])
|
|
411
|
+
for (const lExtendedAttribute of extended_attributes || []) {
|
|
412
412
|
parserHelpers.setIf(
|
|
413
413
|
trans,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
)
|
|
417
|
-
|
|
414
|
+
lExtendedAttribute.name,
|
|
415
|
+
lExtendedAttribute.value,
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
418
|
parserHelpers.setIfNotEmpty(trans, "note", notes);
|
|
419
419
|
trans.id = options.counter.next();
|
|
420
420
|
return trans;
|
|
@@ -37,11 +37,20 @@ function toNameValueString(pAttribute) {
|
|
|
37
37
|
return `${pAttribute.name}=${pAttribute.value}`;
|
|
38
38
|
}
|
|
39
39
|
export function buildGraphAttributes(pEngine, pDirection, pDotGraphAttributes) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const lParts = [];
|
|
41
|
+
for (const lAttribute of GENERIC_GRAPH_ATTRIBUTES) {
|
|
42
|
+
lParts.push(lAttribute);
|
|
43
|
+
}
|
|
44
|
+
for (const lAttribute of GRAPH_ATTRIBUTES[pEngine] || []) {
|
|
45
|
+
lParts.push(lAttribute);
|
|
46
|
+
}
|
|
47
|
+
for (const lAttribute of DIRECTION_ATTRIBUTES[pDirection] || []) {
|
|
48
|
+
lParts.push(lAttribute);
|
|
49
|
+
}
|
|
50
|
+
for (const lAttribute of pDotGraphAttributes || []) {
|
|
51
|
+
lParts.push(lAttribute);
|
|
52
|
+
}
|
|
53
|
+
return lParts.map(toNameValueString).join(" ");
|
|
45
54
|
}
|
|
46
55
|
export function buildNodeAttributes(pDotNodeAttributes) {
|
|
47
56
|
return NODE_ATTRIBUTES.concat(pDotNodeAttributes || [])
|
|
@@ -180,9 +180,9 @@ function state(pState, pIndent, pOptions, pModel, pRenderedTransitions) {
|
|
|
180
180
|
pState.name,
|
|
181
181
|
pRenderedTransitions,
|
|
182
182
|
);
|
|
183
|
-
lCandidateTransitions
|
|
184
|
-
pRenderedTransitions.add(
|
|
185
|
-
}
|
|
183
|
+
for (const lTransition of lCandidateTransitions) {
|
|
184
|
+
pRenderedTransitions.add(lTransition.id);
|
|
185
|
+
}
|
|
186
186
|
const lTransitions = transitions(
|
|
187
187
|
lCandidateTransitions,
|
|
188
188
|
pIndent,
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
function flattenStatesToMap(pStates, pMap, pParent = "") {
|
|
2
|
-
pStates
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type: pState.type,
|
|
13
|
-
statemachine: Boolean(pState.statemachine),
|
|
2
|
+
for (const lState of pStates) {
|
|
3
|
+
if (lState?.statemachine?.states) {
|
|
4
|
+
flattenStatesToMap(lState.statemachine.states, pMap, lState.name);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
for (const lState of pStates) {
|
|
8
|
+
pMap.set(lState.name, {
|
|
9
|
+
name: lState.name,
|
|
10
|
+
type: lState.type,
|
|
11
|
+
statemachine: Boolean(lState.statemachine),
|
|
14
12
|
parent: pParent,
|
|
15
|
-
})
|
|
16
|
-
|
|
13
|
+
});
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
16
|
function flattenTransitions(pStateMachine) {
|
|
19
17
|
let lTransitions = [];
|
|
@@ -21,13 +19,13 @@ function flattenTransitions(pStateMachine) {
|
|
|
21
19
|
lTransitions = structuredClone(pStateMachine.transitions);
|
|
22
20
|
}
|
|
23
21
|
if (Object.hasOwn(pStateMachine, "states")) {
|
|
24
|
-
pStateMachine.states
|
|
25
|
-
|
|
26
|
-
.forEach((pState) => {
|
|
22
|
+
for (const lState of pStateMachine.states) {
|
|
23
|
+
if (lState.statemachine) {
|
|
27
24
|
lTransitions = lTransitions.concat(
|
|
28
|
-
flattenTransitions(
|
|
25
|
+
flattenTransitions(lState.statemachine),
|
|
29
26
|
);
|
|
30
|
-
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
31
29
|
}
|
|
32
30
|
return lTransitions;
|
|
33
31
|
}
|
|
@@ -40,20 +40,24 @@ function fuseTransitions(
|
|
|
40
40
|
pOutgoingTransitionMap,
|
|
41
41
|
pCounter,
|
|
42
42
|
) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const lResult = [];
|
|
44
|
+
for (const lTransition of pTransitions) {
|
|
45
|
+
let lAdded = false;
|
|
46
|
+
for (const lStateName of pPseudoStateNames) {
|
|
47
|
+
if (lStateName === lTransition.to && pOutgoingTransitionMap[lStateName]) {
|
|
48
|
+
for (const lOutgoing of pOutgoingTransitionMap[lStateName]) {
|
|
49
|
+
lResult.push(
|
|
50
|
+
fuseIncomingToOutgoing(lTransition, lOutgoing, pCounter),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
lAdded = true;
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
}
|
|
56
|
+
if (!lAdded) {
|
|
57
|
+
lResult.push(lTransition);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return lResult;
|
|
57
61
|
}
|
|
58
62
|
function deSugarPseudoStates(
|
|
59
63
|
pMachine,
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "13.0.
|
|
1
|
+
export const version = "13.0.3";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-machine-cat",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.3",
|
|
4
4
|
"description": "write beautiful state charts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"state-machine-cat": "dist/cli/main.mjs"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@hpcc-js/wasm-graphviz": "1.
|
|
44
|
+
"@hpcc-js/wasm-graphviz": "1.15.0",
|
|
45
45
|
"ajv": "8.17.1",
|
|
46
|
-
"fast-xml-parser": "5.
|
|
46
|
+
"fast-xml-parser": "5.3.1",
|
|
47
47
|
"he": "1.2.0",
|
|
48
48
|
"neotraverse": "0.6.18"
|
|
49
49
|
},
|