state-machine-cat 10.1.6 → 10.1.7

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.
Files changed (79) hide show
  1. package/bin/smcat.mjs +5 -4
  2. package/dist/commonjs/bundle.js +67 -67
  3. package/{src → dist/esm}/cli/actions.mjs +24 -40
  4. package/dist/esm/cli/attributes-parser.mjs +981 -0
  5. package/dist/esm/cli/file-name-to-stream.mjs +13 -0
  6. package/dist/esm/cli/make-description.mjs +21 -0
  7. package/dist/esm/cli/normalize.mjs +95 -0
  8. package/dist/esm/cli/validations.mjs +70 -0
  9. package/dist/esm/index-node.mjs +16 -0
  10. package/dist/esm/index.mjs +19 -0
  11. package/dist/esm/options.mjs +61 -0
  12. package/dist/esm/parse/index.mjs +27 -0
  13. package/dist/esm/parse/parser-helpers.mjs +175 -0
  14. package/dist/esm/parse/scxml/index.mjs +136 -0
  15. package/dist/esm/parse/scxml/normalize-machine.mjs +44 -0
  16. package/dist/esm/parse/smcat/smcat-parser.mjs +2924 -0
  17. package/dist/esm/parse/smcat-ast.schema.mjs +170 -0
  18. package/dist/esm/render/dot/attributebuilder.mjs +51 -0
  19. package/dist/esm/render/dot/counter.mjs +16 -0
  20. package/dist/esm/render/dot/dot.states.template.js +26 -0
  21. package/dist/esm/render/dot/dot.template.js +14 -0
  22. package/dist/esm/render/dot/index.mjs +106 -0
  23. package/dist/esm/render/dot/render-dot-from-ast.js +29 -0
  24. package/dist/esm/render/dot/state-transformers.mjs +113 -0
  25. package/dist/esm/render/dot/transition-transformers.mjs +49 -0
  26. package/dist/esm/render/dot/utl.mjs +29 -0
  27. package/dist/esm/render/index-node.mjs +28 -0
  28. package/dist/esm/render/index.mjs +20 -0
  29. package/dist/esm/render/scjson/index.mjs +121 -0
  30. package/dist/esm/render/scjson/make-valid-event-names.mjs +27 -0
  31. package/dist/esm/render/scjson/make-valid-xml-name.mjs +19 -0
  32. package/dist/esm/render/scxml/index.mjs +4 -0
  33. package/dist/esm/render/scxml/render-from-scjson.js +9 -0
  34. package/dist/esm/render/scxml/scxml.states.template.js +14 -0
  35. package/dist/esm/render/scxml/scxml.template.js +6 -0
  36. package/dist/esm/render/smcat/index.js +63 -0
  37. package/dist/esm/render/smcat/smcat.template.js +13 -0
  38. package/dist/esm/render/vector/dot-to-vector-native.mjs +35 -0
  39. package/dist/esm/render/vector/vector-native-dot-with-fallback.mjs +37 -0
  40. package/dist/esm/render/vector/vector-with-viz-js.mjs +13 -0
  41. package/dist/esm/state-machine-model.mjs +58 -0
  42. package/dist/esm/transform/desugar.mjs +77 -0
  43. package/dist/esm/transform/utl.mjs +16 -0
  44. package/dist/esm/version.mjs +1 -0
  45. package/package.json +32 -41
  46. package/src/render/dot/dot.states.template.js +1 -1
  47. package/src/render/dot/index.mjs +14 -14
  48. package/types/state-machine-cat.d.ts +4 -4
  49. package/src/cli/file-name-to-stream.mjs +0 -25
  50. package/src/cli/make-description.mjs +0 -45
  51. package/src/cli/normalize.mjs +0 -204
  52. package/src/cli/validations.mjs +0 -140
  53. package/src/index-node.mjs +0 -55
  54. package/src/index.mjs +0 -58
  55. package/src/options.mjs +0 -78
  56. package/src/parse/index.mjs +0 -47
  57. package/src/parse/parser-helpers.mjs +0 -297
  58. package/src/parse/scxml/normalize-machine.mjs +0 -73
  59. package/src/parse/smcat-ast.schema.mjs +0 -187
  60. package/src/render/dot/attributebuilder.mjs +0 -68
  61. package/src/render/dot/counter.mjs +0 -33
  62. package/src/render/dot/render-dot-from-ast.js +0 -70
  63. package/src/render/dot/state-transformers.mjs +0 -128
  64. package/src/render/dot/transition-transformers.mjs +0 -52
  65. package/src/render/dot/utl.mjs +0 -56
  66. package/src/render/index-node.mjs +0 -36
  67. package/src/render/index.mjs +0 -22
  68. package/src/render/scjson/index.mjs +0 -175
  69. package/src/render/scjson/make-valid-event-names.mjs +0 -71
  70. package/src/render/scjson/make-valid-xml-name.mjs +0 -70
  71. package/src/render/scxml/index.mjs +0 -8
  72. package/src/render/smcat/index.js +0 -129
  73. package/src/render/vector/dot-to-vector-native.mjs +0 -60
  74. package/src/render/vector/vector-native-dot-with-fallback.mjs +0 -55
  75. package/src/render/vector/vector-with-viz-js.mjs +0 -18
  76. package/src/state-machine-model.mjs +0 -124
  77. package/src/transform/desugar.mjs +0 -222
  78. package/src/transform/utl.mjs +0 -26
  79. package/src/version.mjs +0 -2
@@ -1,70 +0,0 @@
1
- /** @type {any} - the Handlebars delivered types don't seem to cover everythint in handlebars ...*/
2
- const Handlebars = require("handlebars/dist/handlebars.runtime.js");
3
- // eslint-disable-next-line import/no-unassigned-import
4
- require("./dot.template.js");
5
- // eslint-disable-next-line import/no-unassigned-import
6
- require("./dot.states.template.js");
7
-
8
- Handlebars.registerPartial(
9
- "dot.states.template.hbs",
10
- Handlebars.templates["dot.states.template.hbs"]
11
- );
12
-
13
- Handlebars.registerHelper("stateSection", (pStateMachine) =>
14
- // eslint-disable-next-line no-use-before-define
15
- Handlebars.templates["dot.states.template.hbs"](splitStates(pStateMachine))
16
- );
17
-
18
- // TODO: duplicate from the one in state-transformers.js
19
- /**
20
- *
21
- * @param {string} pString
22
- * @returns {(pState: import("../../../types/state-machine-cat.js").IState) => Boolean}
23
- */
24
- function isType(pString) {
25
- return (pState) => pState.type === pString;
26
- }
27
- /**
28
- *
29
- * @param {string[]} pStringArray
30
- * @returns {(pState: import("../../../types/state-machine-cat.js").IState) => Boolean}
31
- */
32
- // TODO: duplicate from the one in state-transformers.js
33
- function isOneOfTypes(pStringArray) {
34
- return (pState) => pStringArray.includes(pState.type);
35
- }
36
-
37
- // TODO: duplicate from the one in index.js
38
- function splitStates(pStateMachine) {
39
- pStateMachine.initialStates = pStateMachine.states.filter(isType("initial"));
40
- pStateMachine.regularStates = pStateMachine.states.filter(
41
- (pState) => isType("regular")(pState) && !pState.statemachine
42
- );
43
- pStateMachine.historyStates = pStateMachine.states.filter(isType("history"));
44
- pStateMachine.deepHistoryStates = pStateMachine.states.filter(
45
- isType("deephistory")
46
- );
47
- pStateMachine.choiceStates = pStateMachine.states.filter(isType("choice"));
48
- pStateMachine.forkjoinStates = pStateMachine.states.filter(
49
- isOneOfTypes(["fork", "join", "forkjoin"])
50
- );
51
- pStateMachine.junctionStates = pStateMachine.states.filter(
52
- isType("junction")
53
- );
54
- pStateMachine.terminateStates = pStateMachine.states.filter(
55
- isType("terminate")
56
- );
57
- pStateMachine.finalStates = pStateMachine.states.filter(isType("final"));
58
- pStateMachine.compositeStates = pStateMachine.states.filter(
59
- (pState) => pState.statemachine
60
- );
61
-
62
- return pStateMachine;
63
- }
64
- /**
65
- * @param {import("../../../types/state-machine-cat.js").IStateMachine} pStateMachine
66
- * @returns {string}
67
- */
68
- module.exports = function renderDotFromAST(pStateMachine) {
69
- return Handlebars.templates["dot.template.hbs"](pStateMachine);
70
- };
@@ -1,128 +0,0 @@
1
- import cloneDeep from "lodash/cloneDeep.js";
2
- import utl from "./utl.mjs";
3
-
4
- function isType(pString) {
5
- return (pState) => pState.type === pString;
6
- }
7
- function isOneOfTypes(pStringArray) {
8
- return (pState) => pStringArray.includes(pState.type);
9
- }
10
-
11
- function setLabel(pState) {
12
- const lState = cloneDeep(pState);
13
- lState.label = pState.label || pState.name;
14
- return lState;
15
- }
16
-
17
- function nameNote(pState) {
18
- if (Object.prototype.hasOwnProperty.call(pState, "note")) {
19
- pState.noteName = `note_${pState.name}`;
20
- }
21
- return pState;
22
- }
23
-
24
- function classifyState(pState) {
25
- const lClasses = ["state", pState.type];
26
-
27
- if (Object.prototype.hasOwnProperty.call(pState, "class")) {
28
- lClasses.push(pState.class.trim().replace(/[ ]{2,}/g, " "));
29
- }
30
-
31
- pState.class = lClasses.join(" ");
32
- return pState;
33
- }
34
-
35
- function formatActionType(pString) {
36
- return pString === "activity" ? "" : `${pString}/ `;
37
- }
38
-
39
- function flattenActions(pState) {
40
- const lReturnValue = { ...pState };
41
-
42
- if (pState.actions) {
43
- lReturnValue.actions = pState.actions.map(
44
- (pAction) => `${formatActionType(pAction.type)}${pAction.body}`
45
- );
46
- }
47
-
48
- return lReturnValue;
49
- }
50
- function flattenNote(pState) {
51
- if (Object.prototype.hasOwnProperty.call(pState, "note")) {
52
- pState.noteFlattened = pState.note.join("");
53
- }
54
- return pState;
55
- }
56
-
57
- function recolor(pNodeAttributes) {
58
- return (pState) => {
59
- const lNodeColor = (pNodeAttributes || []).find(
60
- (pAttribute) => pAttribute.name === "color"
61
- )?.value;
62
-
63
- if (
64
- lNodeColor &&
65
- !pState.color &&
66
- isOneOfTypes([
67
- "initial",
68
- "fork",
69
- "join",
70
- "junction",
71
- "forkjoin",
72
- "final",
73
- ])(pState)
74
- ) {
75
- pState.color = lNodeColor;
76
- }
77
- return pState;
78
- };
79
- }
80
-
81
- function escapeStateStrings(pState) {
82
- if (pState.note) {
83
- pState.note = pState.note.map(utl.escapeString);
84
- }
85
- return pState;
86
- }
87
-
88
- function tipForkJoinStates(pDirection) {
89
- return (pState) => {
90
- if (isOneOfTypes(["fork", "join", "forkjoin"])(pState)) {
91
- return {
92
- sizingExtras: utl.isVertical(pDirection) ? "height=0.1" : "width=0.1",
93
- ...pState,
94
- };
95
- }
96
- return pState;
97
- };
98
- }
99
-
100
- function flagParallelChildren(pState) {
101
- if (
102
- pState.type === "parallel" &&
103
- pState.statemachine &&
104
- pState.statemachine.states
105
- ) {
106
- pState.statemachine.states = pState.statemachine.states.map((pChildState) =>
107
- isType("regular")(pChildState)
108
- ? { ...pChildState, parentIsParallel: true }
109
- : pChildState
110
- );
111
- }
112
-
113
- return pState;
114
- }
115
-
116
- export default {
117
- isType,
118
- isOneOfTypes,
119
- setLabel,
120
- classifyState,
121
- nameNote,
122
- flattenActions,
123
- flattenNote,
124
- recolor,
125
- escapeStateStrings,
126
- tipForkJoinStates,
127
- flagParallelChildren,
128
- };
@@ -1,52 +0,0 @@
1
- import utl from "./utl.mjs";
2
-
3
- function escapeTransitionStrings(pTransition) {
4
- if (pTransition.note) {
5
- pTransition.note = pTransition.note.map(utl.escapeString);
6
- }
7
- if (pTransition.label) {
8
- pTransition.label = utl.escapeLabelString(pTransition.label);
9
- }
10
- return pTransition;
11
- }
12
-
13
- function addPorts(pDirection) {
14
- return (pTransition) => {
15
- let lAdditionalAttributes = {};
16
-
17
- if (pTransition.isCompositeSelf) {
18
- if (utl.isVertical(pDirection)) {
19
- lAdditionalAttributes = {
20
- tailportflags: `tailport="e" headport="e"`,
21
- headportflags: `tailport="w"`,
22
- };
23
- } else if (pTransition.hasParent) {
24
- lAdditionalAttributes = {
25
- tailportflags: `tailport="n" headport="n"`,
26
- headportflags: `tailport="s"`,
27
- };
28
- } else {
29
- lAdditionalAttributes = {
30
- tailportflags: `tailport="s" headport="s"`,
31
- headportflags: `tailport="n"`,
32
- };
33
- }
34
- }
35
- return { ...pTransition, ...lAdditionalAttributes };
36
- };
37
- }
38
-
39
- function classifyTransition(pTransition) {
40
- let lClasses = ["transition"];
41
- if (pTransition.type) {
42
- lClasses.push(pTransition.type);
43
- }
44
- if (pTransition.class) {
45
- lClasses.push(pTransition.class.trim().replace(/[ ]{2,}/g, " "));
46
- }
47
-
48
- pTransition.class = lClasses.join(" ");
49
- return pTransition;
50
- }
51
-
52
- export default { escapeTransitionStrings, addPorts, classifyTransition };
@@ -1,56 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @param {string} pString
5
- * @returns {string}
6
- */
7
- function escapeString(pString) {
8
- return pString
9
- .replace(/\\/g, "\\\\")
10
- .replace(/\n\s*/g, "\\l")
11
- .replace(/"/g, '\\"')
12
- .concat("\\l");
13
- }
14
-
15
- /**
16
- * @param {string} pString
17
- * @returns {string}
18
- */
19
- function escapeLabelString(pString) {
20
- return pString
21
- .replace(/\\/g, "\\\\")
22
- .replace(/\n\s*/g, " \\l")
23
- .replace(/"/g, '\\"')
24
- .concat(" \\l");
25
- }
26
-
27
- /**
28
- * @param {string} pDirection
29
- * @returns {boolean}
30
- */
31
- function isVertical(pDirection) {
32
- const lDirection = pDirection || "top-down";
33
-
34
- return lDirection === "top-down" || lDirection === "bottom-top";
35
- }
36
-
37
- /**
38
- *
39
- * @param {import("../../state-machine-model.mjs").default} pStateMachineModel
40
- * @param {import("../../../types/state-machine-cat").ITransition} pTransition
41
- * @returns {boolean}
42
- */
43
- function isCompositeSelf(pStateMachineModel, pTransition) {
44
- return (
45
- pTransition.from === pTransition.to &&
46
- pStateMachineModel.findStateByName(pTransition.from).statemachine &&
47
- !(pTransition.type === "internal")
48
- );
49
- }
50
-
51
- export default {
52
- escapeString,
53
- escapeLabelString,
54
- isVertical,
55
- isCompositeSelf,
56
- };
@@ -1,36 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable security/detect-object-injection */
3
- import has from "lodash/has.js";
4
- import smcat from "./smcat/index.js";
5
- import dot from "./dot/index.mjs";
6
- import vector from "./vector/vector-native-dot-with-fallback.mjs";
7
- import oldVector from "./vector/vector-with-viz-js.mjs";
8
- import scjson from "./scjson/index.mjs";
9
- import scxml from "./scxml/index.mjs";
10
-
11
- /**
12
- *
13
- * @param {import("../../types/state-machine-cat.js").OutputType} pOutputType
14
- * @returns {import("../../types/state-machine-cat.js").RenderFunctionType}
15
- */
16
- export default function getRenderFunction(pOutputType) {
17
- const lOutputType2RenderFunction = {
18
- smcat,
19
- dot,
20
- svg: vector,
21
- eps: vector,
22
- ps: vector,
23
- ps2: vector,
24
- oldsvg: oldVector,
25
- oldps2: oldVector,
26
- oldeps: oldVector,
27
- pdf: vector,
28
- png: vector,
29
- scjson,
30
- scxml,
31
- };
32
-
33
- return has(lOutputType2RenderFunction, pOutputType)
34
- ? lOutputType2RenderFunction[pOutputType]
35
- : (pX) => pX;
36
- }
@@ -1,22 +0,0 @@
1
- /* eslint-disable security/detect-object-injection */
2
- import has from "lodash/has.js";
3
- import smcat from "./smcat/index.js";
4
- import dot from "./dot/index.mjs";
5
- import svg from "./vector/vector-with-viz-js.mjs";
6
- import scjson from "./scjson/index.mjs";
7
- import scxml from "./scxml/index.mjs";
8
-
9
- export default function getRenderFunction(pOutputType) {
10
- const lOutputType2RenderFunction = {
11
- smcat,
12
- dot,
13
- svg,
14
- oldsvg: svg,
15
- scjson,
16
- scxml,
17
- };
18
-
19
- return has(lOutputType2RenderFunction, pOutputType)
20
- ? lOutputType2RenderFunction[pOutputType]
21
- : (pX) => pX;
22
- }
@@ -1,175 +0,0 @@
1
- /* eslint-disable security/detect-object-injection */
2
- import StateMachineModel from "../../state-machine-model.mjs";
3
- import makeValidXMLName from "./make-valid-xml-name.mjs";
4
- import makeValidEventNames from "./make-valid-event-names.mjs";
5
-
6
- const STATE_TYPE2SCXML_STATE_KIND = {
7
- regular: "state",
8
- initial: "initial",
9
- final: "final",
10
- terminate: "final",
11
- parallel: "parallel",
12
- history: "history",
13
- deephistory: "history",
14
- };
15
-
16
- function stateType2SCXMLStateKind(pStateType) {
17
- return STATE_TYPE2SCXML_STATE_KIND[pStateType] || "state";
18
- }
19
-
20
- function transformTransition(pTransition) {
21
- const lReturnValue = {
22
- target: makeValidXMLName(pTransition.to),
23
- };
24
-
25
- if (Boolean(pTransition.event)) {
26
- lReturnValue.event = makeValidEventNames(pTransition.event);
27
- }
28
- if (Boolean(pTransition.cond)) {
29
- lReturnValue.cond = pTransition.cond;
30
- }
31
- if (Boolean(pTransition.action)) {
32
- lReturnValue.action = pTransition.action;
33
- }
34
- if (Boolean(pTransition.type)) {
35
- lReturnValue.type = pTransition.type;
36
- }
37
- return lReturnValue;
38
- }
39
-
40
- function extractTriggers(pTriggers, pTriggerType) {
41
- return pTriggers
42
- .filter((pTrigger) => pTrigger.type === pTriggerType)
43
- .map((pTrigger) => pTrigger.body);
44
- }
45
-
46
- function pullOutActionType(pReturnValue, pTriggersType, pActions, pActionType) {
47
- const lTriggerArray = extractTriggers(pActions, pActionType);
48
-
49
- if (lTriggerArray.length > 0) {
50
- pReturnValue[pTriggersType] = (pReturnValue[pTriggersType] || []).concat(
51
- lTriggerArray
52
- );
53
- }
54
- }
55
-
56
- function transformTriggers(pReturnValue, pState) {
57
- if (Boolean(pState.actions)) {
58
- pullOutActionType(pReturnValue, "onentries", pState.actions, "entry");
59
- pullOutActionType(pReturnValue, "onentries", pState.actions, "activity");
60
- pullOutActionType(pReturnValue, "onexits", pState.actions, "exit");
61
- }
62
- }
63
-
64
- function transformTransitions(pReturnValue, pState, pTransitions) {
65
- const lTransitions = pTransitions
66
- .filter((pTransition) => pTransition.from === pState.name)
67
- .map(transformTransition);
68
-
69
- if (lTransitions.length > 0) {
70
- pReturnValue.transitions = lTransitions;
71
- }
72
- }
73
-
74
- function transformCompositeState(pReturnValue, pState, pTransitions) {
75
- if (Boolean(pState.statemachine)) {
76
- // recursion, so ...
77
- // eslint-disable-next-line no-use-before-define
78
- const lRenderedState = render(pState.statemachine, null, pTransitions);
79
-
80
- pReturnValue.states = (pReturnValue.states || []).concat(
81
- lRenderedState.states
82
- );
83
- if (lRenderedState.initial) {
84
- pReturnValue.initial = lRenderedState.initial;
85
- }
86
- }
87
- }
88
-
89
- function transformState(pTransitions) {
90
- pTransitions = pTransitions || [];
91
-
92
- return (pState) => {
93
- const lReturnValue = {
94
- kind: stateType2SCXMLStateKind(pState.type),
95
- id: makeValidXMLName(pState.name),
96
- };
97
-
98
- if (pState.type === "deephistory") {
99
- // as 'shallow' is the default anyway, we leave it out
100
- lReturnValue.type = "deep";
101
- }
102
-
103
- transformTriggers(lReturnValue, pState);
104
-
105
- transformTransitions(lReturnValue, pState, pTransitions);
106
-
107
- transformCompositeState(lReturnValue, pState, pTransitions);
108
- return lReturnValue;
109
- };
110
- }
111
-
112
- function findInitialPseudoStateName(pStateMachine) {
113
- let lReturnValue = null;
114
-
115
- const lInitial = pStateMachine.states.filter(
116
- (pState) => pState.type === "initial"
117
- );
118
-
119
- if (lInitial.length > 0) {
120
- lReturnValue = lInitial[0].name;
121
- }
122
- return lReturnValue;
123
- }
124
-
125
- function findInitialStateName(pStateMachine, pInitialPseudoStateName) {
126
- let lReturnValue = pInitialPseudoStateName;
127
-
128
- if (pInitialPseudoStateName && pStateMachine.transitions) {
129
- const lInitialTransitions = pStateMachine.transitions.filter(
130
- (pTransition) => pTransition.from === pInitialPseudoStateName
131
- );
132
-
133
- if (lInitialTransitions.length > 0 && !lInitialTransitions[0].action) {
134
- lReturnValue = lInitialTransitions[0].to;
135
- }
136
- }
137
- return lReturnValue;
138
- }
139
-
140
- /**
141
- * @param {import("../../..").IStateMachine} pStateMachine
142
- * @param {import("../../..").IRenderOptions} [_pOptions]
143
- * @param {import("../../..").ITransition[]} [pTransitions] (no need to specify - used in recursion)
144
- * @returns {any} TODO: scjson data structure
145
- */
146
- export default function render(pStateMachine, _pOptions, pTransitions) {
147
- const lInitialPseudoStateName = findInitialPseudoStateName(pStateMachine);
148
- const lInitialStateName = findInitialStateName(
149
- pStateMachine,
150
- lInitialPseudoStateName
151
- );
152
- const lReturnValue = {
153
- states: pStateMachine.states
154
- .filter((pState) => {
155
- if (
156
- lInitialStateName &&
157
- lInitialStateName !== lInitialPseudoStateName
158
- ) {
159
- return pState.type !== "initial";
160
- }
161
- return true;
162
- })
163
- .map(
164
- transformState(
165
- pTransitions ||
166
- new StateMachineModel(pStateMachine).flattenedTransitions
167
- )
168
- ),
169
- };
170
-
171
- if (lInitialStateName) {
172
- lReturnValue.initial = makeValidXMLName(lInitialStateName);
173
- }
174
- return lReturnValue;
175
- }
@@ -1,71 +0,0 @@
1
- /*
2
- * In the XML spec we read: https://www.w3.org/TR/xml/#NT-Name:
3
- *
4
- * NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
5
- * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] |
6
- * [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
7
- * NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
8
- * Name ::= NameStartChar (NameChar)*
9
- *
10
- * This means that these characters are forbidden for NameStartChar
11
- * #xD7, #xF7, #x300 - #x36F, #x37E, #x2000 - #x200B, #x200E - #x206F, #x2190 - #x2BFF, #x2FF0 - #x3000,
12
- * #xD800 - #xF8FF, #xFDD0 - #xFDEF, #xFFFE - #xFFFF
13
- */
14
-
15
- /* eslint no-control-regex: 0, max-len: 0, no-misleading-character-class: 0 */
16
- // EVENT_CHAR_FORBIDDEN_RE === forbidden for NameStartChar, except "-" and [0-9]
17
- // The SCXML xsd doesn't seem to mention '*' (\u002A) as an allowed character. But
18
- // they _are_ used in event descriptors in the SCXML spec. So we've excluded
19
- // them from forbidden characters
20
- const EVENT_CHAR_FORBIDDEN_RE =
21
- /[\u00B7|\u0300-\u036F|\u203F-\u2040|\u0000-\u0029|\u002B-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g;
22
- const START_EVENT_CHAR_FORBIDDEN_EXTRA_RE = /[.]/g;
23
-
24
- function makeValidEventChar(pCandidateEventStringTail) {
25
- return pCandidateEventStringTail.replace(EVENT_CHAR_FORBIDDEN_RE, "_");
26
- }
27
-
28
- function makeValidEventStartChar(pCandidateEventStringStart) {
29
- let lReturnValue = makeValidEventChar(pCandidateEventStringStart);
30
-
31
- if (lReturnValue.match(START_EVENT_CHAR_FORBIDDEN_EXTRA_RE)) {
32
- lReturnValue = `_${pCandidateEventStringStart}`;
33
- }
34
- return lReturnValue;
35
- }
36
-
37
- function makeValidEventName(pCandidateEventName) {
38
- pCandidateEventName = pCandidateEventName.replace(/\s+/g, " ").trim();
39
-
40
- return makeValidEventStartChar(pCandidateEventName[0]).concat(
41
- makeValidEventChar(pCandidateEventName.slice(1))
42
- );
43
- }
44
- /**
45
- * Takes any string and returns a valid SCXML events string:
46
- *
47
- * If pCandidateName is not empty:
48
- * For all characters in pCandidateName:
49
- * if it's not a valid NameChar, replace it with '_'
50
- * For the first character:
51
- * If it's a valid NameChar, but not a valid NameStartChar, add an '_' in front of the pCandidateName
52
- *
53
- * If pCandidateName is empty:
54
- * return the strling 'empty'
55
- * *
56
- * @param {string[]} pCandidateEventNames (optional)
57
- * @returns {string} a valid SCXML events string
58
- */
59
- export default (pCandidateEventNames) => {
60
- pCandidateEventNames = pCandidateEventNames || "";
61
-
62
- if (pCandidateEventNames.length === 0) {
63
- return "empty";
64
- }
65
-
66
- return pCandidateEventNames
67
- .split(/[\n\r]+/)
68
- .filter((pCandidateEventName) => pCandidateEventName.length > 0)
69
- .map(makeValidEventName)
70
- .join(" ");
71
- };
@@ -1,70 +0,0 @@
1
- // @ts-check
2
- /*
3
- * In the XML spec we read: https://www.w3.org/TR/xml/#NT-Name:
4
- *
5
- * NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
6
- * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] |
7
- * [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
8
- * NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
9
- * Name ::= NameStartChar (NameChar)*
10
- *
11
- * This means that these characters are forbidden for NameStartChar
12
- * #xD7, #xF7, #x300 - #x36F, #x37E, #x2000 - #x200B, #x200E - #x206F, #x2190 - #x2BFF, #x2FF0 - #x3000,
13
- * #xD800 - #xF8FF, #xFDD0 - #xFDEF, #xFFFE - #xFFFF
14
- */
15
-
16
- /* eslint no-control-regex: 0, max-len: 0, no-misleading-character-class: 0 */
17
- const NAME_CHAR_FORBIDDEN_RE =
18
- /[\u0000-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g;
19
- const START_NAME_CHAR_FORBIDDEN_EXTRA_RE =
20
- /[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;
21
-
22
- /**
23
- *
24
- * @param {string} pCandidateNameTail
25
- * @returns {string}
26
- */
27
- function makeValidNameChars(pCandidateNameTail) {
28
- return pCandidateNameTail.replace(NAME_CHAR_FORBIDDEN_RE, "_");
29
- }
30
-
31
- /**
32
- * if it's an invalid NameStartChar but a valid NameChar smack a '_' in front of it
33
- * if it's an invalid NameChar as well - run it through the makeValidNameChars replacer
34
- * @param {string} pCandidateChar - start char
35
- * @returns {string} valid start string
36
- */
37
- function makeValidNameStartChar(pCandidateChar) {
38
- let lReturnValue = makeValidNameChars(pCandidateChar);
39
-
40
- if (lReturnValue.match(START_NAME_CHAR_FORBIDDEN_EXTRA_RE)) {
41
- lReturnValue = `_${pCandidateChar}`;
42
- }
43
- return lReturnValue;
44
- }
45
-
46
- /**
47
- * Takes any string and returns a valid XMLName using these rules:
48
- *
49
- * If pCandidateName is not empty:
50
- * For all characters in pCandidateName:
51
- * if it's not a valid NameChar, replace it with '_'
52
- * For the first character:
53
- * If it's a valid NameChar, but not a valid NameStartChar, add an '_' in front of the pCandidateName
54
- *
55
- * If pCandidateName is empty:
56
- * return the string '__empty'
57
- * *
58
- * @param {string} pCandidateName (optional)
59
- * @returns {string} a valid XMLName
60
- */
61
- export default (pCandidateName) => {
62
- pCandidateName = pCandidateName || "";
63
-
64
- if (pCandidateName.length === 0) {
65
- return `__empty`;
66
- }
67
- return makeValidNameStartChar(pCandidateName[0]).concat(
68
- makeValidNameChars(pCandidateName.slice(1))
69
- );
70
- };
@@ -1,8 +0,0 @@
1
- // @ts-check
2
- import ast2scjson from "../scjson/index.mjs";
3
- import renderFomSCJSON from "./render-from-scjson.js";
4
-
5
- /** @type {import("../../..").StringRenderFunctionType} */
6
- export default function renderSCXML(pStateMachine) {
7
- return renderFomSCJSON(ast2scjson(pStateMachine));
8
- }