jssm 5.104.2 → 5.112.4

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 (84) hide show
  1. package/MIGRATING-jssm-viz.md +67 -0
  2. package/README.md +179 -882
  3. package/dist/deno/README.md +347 -0
  4. package/dist/{es6 → deno}/jssm.d.ts +773 -39
  5. package/dist/deno/jssm.js +1 -0
  6. package/{jssm_compiler.d.ts → dist/deno/jssm_compiler.d.ts} +17 -2
  7. package/dist/deno/jssm_constants.d.ts +37 -0
  8. package/dist/deno/jssm_error.d.ts +27 -0
  9. package/dist/deno/jssm_theme.d.ts +15 -0
  10. package/dist/{es6 → deno}/jssm_types.d.ts +327 -8
  11. package/dist/deno/jssm_util.d.ts +258 -0
  12. package/dist/deno/jssm_viz.d.ts +175 -0
  13. package/dist/deno/jssm_viz_colors.d.ts +63 -0
  14. package/dist/jssm.es5.cjs +1 -1
  15. package/dist/jssm.es5.iife.js +1 -0
  16. package/dist/jssm.es6.mjs +1 -1
  17. package/dist/jssm_viz.cjs +1 -0
  18. package/dist/jssm_viz.iife.cjs +1 -0
  19. package/dist/jssm_viz.mjs +1 -0
  20. package/jssm.es5.d.cts +1191 -43
  21. package/jssm.es6.d.ts +1191 -43
  22. package/jssm_viz.es5.d.cts +2341 -0
  23. package/jssm_viz.es6.d.ts +2341 -0
  24. package/package.json +73 -24
  25. package/.clocignore +0 -1
  26. package/.codeclimate.yml +0 -22
  27. package/.editorconfig +0 -12
  28. package/.eslintrc +0 -20
  29. package/.gitattributes +0 -6
  30. package/.nycrc +0 -6
  31. package/.travis.yml +0 -9
  32. package/CHANGELOG.md +0 -178
  33. package/dist/es6/fsl_parser.js +0 -1
  34. package/dist/es6/jssm.js +0 -2488
  35. package/dist/es6/jssm_arrow.js +0 -187
  36. package/dist/es6/jssm_compiler.d.ts +0 -135
  37. package/dist/es6/jssm_compiler.js +0 -366
  38. package/dist/es6/jssm_constants.d.ts +0 -5
  39. package/dist/es6/jssm_constants.js +0 -94
  40. package/dist/es6/jssm_error.d.ts +0 -8
  41. package/dist/es6/jssm_error.js +0 -28
  42. package/dist/es6/jssm_theme.d.ts +0 -4
  43. package/dist/es6/jssm_theme.js +0 -13
  44. package/dist/es6/jssm_types.js +0 -3
  45. package/dist/es6/jssm_util.d.ts +0 -106
  46. package/dist/es6/jssm_util.js +0 -180
  47. package/dist/es6/themes/jssm_base_stylesheet.d.ts +0 -11
  48. package/dist/es6/themes/jssm_base_stylesheet.js +0 -58
  49. package/dist/es6/themes/jssm_theme_bold.d.ts +0 -11
  50. package/dist/es6/themes/jssm_theme_bold.js +0 -58
  51. package/dist/es6/themes/jssm_theme_default.d.ts +0 -11
  52. package/dist/es6/themes/jssm_theme_default.js +0 -58
  53. package/dist/es6/themes/jssm_theme_modern.d.ts +0 -11
  54. package/dist/es6/themes/jssm_theme_modern.js +0 -58
  55. package/dist/es6/themes/jssm_theme_ocean.d.ts +0 -11
  56. package/dist/es6/themes/jssm_theme_ocean.js +0 -56
  57. package/dist/es6/themes/jssm_theme_plain.d.ts +0 -11
  58. package/dist/es6/themes/jssm_theme_plain.js +0 -70
  59. package/dist/es6/version.js +0 -2
  60. package/dist/jssm.es5.iife.cjs +0 -1
  61. package/dist/jssm.es5.iife.nonmin.cjs +0 -23180
  62. package/dist/jssm.es5.nonmin.cjs +0 -23175
  63. package/dist/jssm.es6.nonmin.cjs +0 -23144
  64. package/fsl_parser.d.ts +0 -6
  65. package/jest-dragon.config.cjs +0 -33
  66. package/jest-spec.config.cjs +0 -33
  67. package/jest-stoch.config.cjs +0 -33
  68. package/jest-unicode.config.cjs +0 -33
  69. package/jssm.d.ts +0 -1141
  70. package/jssm_arrow.d.ts +0 -53
  71. package/jssm_constants.d.ts +0 -5
  72. package/jssm_error.d.ts +0 -8
  73. package/jssm_theme.d.ts +0 -4
  74. package/jssm_types.d.ts +0 -378
  75. package/jssm_util.d.ts +0 -106
  76. package/rollup.config.deno.js +0 -44
  77. package/rollup.config.es5.js +0 -52
  78. package/rollup.config.es6.js +0 -55
  79. package/tutorial_learn_testing.md +0 -168
  80. package/typedoc-options.cjs +0 -68
  81. package/version.d.ts +0 -2
  82. /package/dist/{es6 → deno}/fsl_parser.d.ts +0 -0
  83. /package/dist/{es6 → deno}/jssm_arrow.d.ts +0 -0
  84. /package/dist/{es6 → deno}/version.d.ts +0 -0
@@ -1,187 +0,0 @@
1
- import { JssmError } from './jssm_error';
2
- /* eslint-disable complexity */
3
- /*********
4
- *
5
- * Return the direction of an arrow - `right`, `left`, or `both`.
6
- *
7
- * ```typescript
8
- * import { arrow_direction } from 'jssm';
9
- *
10
- * arrow_direction('->'); // 'right'
11
- * arrow_direction('<~=>'); // 'both'
12
- * ```
13
- *
14
- * @param arrow The arrow to be evaluated
15
- *
16
- */
17
- function arrow_direction(arrow) {
18
- switch (String(arrow)) {
19
- case '->':
20
- case '→':
21
- case '=>':
22
- case '⇒':
23
- case '~>':
24
- case '↛':
25
- return 'right';
26
- case '<-':
27
- case '←':
28
- case '<=':
29
- case '⇐':
30
- case '<~':
31
- case '↚':
32
- return 'left';
33
- case '<->':
34
- case '↔':
35
- case '<-=>':
36
- case '←⇒':
37
- case '←=>':
38
- case '<-⇒':
39
- case '<-~>':
40
- case '←↛':
41
- case '←~>':
42
- case '<-↛':
43
- case '<=>':
44
- case '⇔':
45
- case '<=->':
46
- case '⇐→':
47
- case '⇐->':
48
- case '<=→':
49
- case '<=~>':
50
- case '⇐↛':
51
- case '⇐~>':
52
- case '<=↛':
53
- case '<~>':
54
- case '↮':
55
- case '<~->':
56
- case '↚→':
57
- case '↚->':
58
- case '<~→':
59
- case '<~=>':
60
- case '↚⇒':
61
- case '↚=>':
62
- case '<~⇒':
63
- return 'both';
64
- default:
65
- throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
66
- }
67
- }
68
- /* eslint-enable complexity */
69
- /* eslint-disable complexity */
70
- /*********
71
- *
72
- * Return the direction of an arrow - `right`, `left`, or `both`.
73
- *
74
- * ```typescript
75
- * import { arrow_left_kind } from 'jssm';
76
- *
77
- * arrow_left_kind('<-'); // 'legal'
78
- * arrow_left_kind('<='); // 'main'
79
- * arrow_left_kind('<~'); // 'forced'
80
- * arrow_left_kind('<->'); // 'legal'
81
- * arrow_left_kind('->'); // 'none'
82
- * ```
83
- *
84
- * @param arrow The arrow to be evaluated
85
- *
86
- */
87
- function arrow_left_kind(arrow) {
88
- switch (String(arrow)) {
89
- case '->':
90
- case '→':
91
- case '=>':
92
- case '⇒':
93
- case '~>':
94
- case '↛':
95
- return 'none';
96
- case '<-':
97
- case '←':
98
- case '<->':
99
- case '↔':
100
- case '<-=>':
101
- case '←⇒':
102
- case '<-~>':
103
- case '←↛':
104
- return 'legal';
105
- case '<=':
106
- case '⇐':
107
- case '<=>':
108
- case '⇔':
109
- case '<=->':
110
- case '⇐→':
111
- case '<=~>':
112
- case '⇐↛':
113
- return 'main';
114
- case '<~':
115
- case '↚':
116
- case '<~>':
117
- case '↮':
118
- case '<~->':
119
- case '↚→':
120
- case '<~=>':
121
- case '↚⇒':
122
- return 'forced';
123
- default:
124
- throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
125
- }
126
- }
127
- /* eslint-enable complexity */
128
- /* eslint-disable complexity */
129
- /*********
130
- *
131
- * Return the direction of an arrow - `right`, `left`, or `both`.
132
- *
133
- * ```typescript
134
- * import { arrow_left_kind } from 'jssm';
135
- *
136
- * arrow_left_kind('->'); // 'legal'
137
- * arrow_left_kind('=>'); // 'main'
138
- * arrow_left_kind('~>'); // 'forced'
139
- * arrow_left_kind('<->'); // 'legal'
140
- * arrow_left_kind('<-'); // 'none'
141
- * ```
142
- *
143
- * @param arrow The arrow to be evaluated
144
- *
145
- */
146
- function arrow_right_kind(arrow) {
147
- switch (String(arrow)) {
148
- case '<-':
149
- case '←':
150
- case '<=':
151
- case '⇐':
152
- case '<~':
153
- case '↚':
154
- return 'none';
155
- case '->':
156
- case '→':
157
- case '<->':
158
- case '↔':
159
- case '<=->':
160
- case '⇐→':
161
- case '<~->':
162
- case '↚→':
163
- return 'legal';
164
- case '=>':
165
- case '⇒':
166
- case '<=>':
167
- case '⇔':
168
- case '<-=>':
169
- case '←⇒':
170
- case '<~=>':
171
- case '↚⇒':
172
- return 'main';
173
- case '~>':
174
- case '↛':
175
- case '<~>':
176
- case '↮':
177
- case '<-~>':
178
- case '←↛':
179
- case '<=~>':
180
- case '⇐↛':
181
- return 'forced';
182
- default:
183
- throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
184
- }
185
- }
186
- /* eslint-enable complexity */
187
- export { arrow_direction, arrow_left_kind, arrow_right_kind };
@@ -1,135 +0,0 @@
1
- import { JssmTransition, JssmCompileSe, JssmParseTree, JssmGenericConfig } from './jssm_types';
2
- /*********
3
- *
4
- * Internal method meant to perform factory assembly of an edge. Not meant for
5
- * external use.
6
- *
7
- * @internal
8
- *
9
- * @typeparam mDT The type of the machine data member; usually omitted
10
- *
11
- */
12
- declare function makeTransition<StateType, mDT>(this_se: JssmCompileSe<StateType, mDT>, from: StateType, to: StateType, isRight: boolean, _wasList?: Array<StateType>, _wasIndex?: number): JssmTransition<StateType, mDT>;
13
- /*********
14
- *
15
- * This method wraps the parser call that comes from the peg grammar,
16
- * {@link parse}. Generally neither this nor that should be used directly
17
- * unless you mean to develop plugins or extensions for the machine.
18
- *
19
- * Parses the intermediate representation of a compiled string down to a
20
- * machine configuration object. If you're using this (probably don't,) you're
21
- * probably also using {@link compile} and {@link Machine.constructor}.
22
- *
23
- * ```typescript
24
- * import { parse, compile, Machine } from 'jssm';
25
- *
26
- * const intermediate = wrap_parse('a -> b;', {});
27
- * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
28
- *
29
- * const cfg = compile(intermediate);
30
- * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
31
- *
32
- * const machine = new Machine(cfg);
33
- * // Machine { _instance_name: undefined, _state: 'a', ...
34
- * ```
35
- *
36
- * This method is mostly for plugin and intermediate tool authors, or people
37
- * who need to work with the machine's intermediate representation.
38
- *
39
- * # Hey!
40
- *
41
- * Most people looking at this want either the `sm` operator or method `from`,
42
- * which perform all the steps in the chain. The library's author mostly uses
43
- * operator `sm`, and mostly falls back to `.from` when needing to parse
44
- * strings dynamically instead of from template literals.
45
- *
46
- * Operator {@link sm}:
47
- *
48
- * ```typescript
49
- * import { sm } from 'jssm';
50
- *
51
- * const lswitch = sm`on <=> off;`;
52
- * ```
53
- *
54
- * Method {@link from}:
55
- *
56
- * ```typescript
57
- * import * as jssm from 'jssm';
58
- *
59
- * const toggle = jssm.from('up <=> down;');
60
- * ```
61
- *
62
- * `wrap_parse` itself is an internal convenience method for alting out an
63
- * object as the options call. Not generally meant for external use.
64
- *
65
- * @param input The FSL code to be evaluated
66
- *
67
- * @param options Things to control about the instance
68
- *
69
- */
70
- declare function wrap_parse(input: string, options?: Object): any;
71
- /*********
72
- *
73
- * Compile a machine's JSON intermediate representation to a config object. If
74
- * you're using this (probably don't,) you're probably also using
75
- * {@link parse} to get the IR, and the object constructor
76
- * {@link Machine.construct} to turn the config object into a workable machine.
77
- *
78
- * ```typescript
79
- * import { parse, compile, Machine } from 'jssm';
80
- *
81
- * const intermediate = parse('a -> b;');
82
- * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
83
- *
84
- * const cfg = compile(intermediate);
85
- * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
86
- *
87
- * const machine = new Machine(cfg);
88
- * // Machine { _instance_name: undefined, _state: 'a', ...
89
- * ```
90
- *
91
- * This method is mostly for plugin and intermediate tool authors, or people
92
- * who need to work with the machine's intermediate representation.
93
- *
94
- * # Hey!
95
- *
96
- * Most people looking at this want either the `sm` operator or method `from`,
97
- * which perform all the steps in the chain. The library's author mostly uses
98
- * operator `sm`, and mostly falls back to `.from` when needing to parse
99
- * strings dynamically instead of from template literals.
100
- *
101
- * Operator {@link sm}:
102
- *
103
- * ```typescript
104
- * import { sm } from 'jssm';
105
- *
106
- * const lswitch = sm`on <=> off;`;
107
- * ```
108
- *
109
- * Method {@link from}:
110
- *
111
- * ```typescript
112
- * import * as jssm from 'jssm';
113
- *
114
- * const toggle = jssm.from('up <=> down;');
115
- * ```
116
- *
117
- * @typeparam mDT The type of the machine data member; usually omitted
118
- *
119
- * @param tree The parse tree to be boiled down into a machine config
120
- *
121
- */
122
- declare function compile<StateType, mDT>(tree: JssmParseTree<StateType, mDT>): JssmGenericConfig<StateType, mDT>;
123
- /*********
124
- *
125
- * An internal convenience wrapper for parsing then compiling a machine string.
126
- * Not generally meant for external use. Please see {@link compile} or
127
- * {@link sm}.
128
- *
129
- * @typeparam mDT The type of the machine data member; usually omitted
130
- *
131
- * @param plan The FSL code to be evaluated and built into a machine config
132
- *
133
- */
134
- declare function make<StateType, mDT>(plan: string): JssmGenericConfig<StateType, mDT>;
135
- export { compile, make, makeTransition, wrap_parse };
@@ -1,366 +0,0 @@
1
- import { JssmError } from './jssm_error';
2
- import { parse } from './fsl_parser';
3
- import { arrow_left_kind, arrow_right_kind } from './jssm_arrow';
4
- import { find_repeated, name_bind_prop_and_state } from './jssm_util';
5
- import { reduce as reduce_to_639 } from 'reduce-to-639-1';
6
- /*********
7
- *
8
- * Internal method meant to perform factory assembly of an edge. Not meant for
9
- * external use.
10
- *
11
- * @internal
12
- *
13
- * @typeparam mDT The type of the machine data member; usually omitted
14
- *
15
- */
16
- // TODO add at-param to docblock
17
- function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
18
- const kind = isRight
19
- ? arrow_right_kind(this_se.kind)
20
- : arrow_left_kind(this_se.kind), edge = {
21
- from,
22
- to,
23
- kind,
24
- after_time: isRight ? this_se.r_after : this_se.l_after,
25
- forced_only: kind === 'forced',
26
- main_path: kind === 'main'
27
- };
28
- // if ((wasList !== undefined) && (wasIndex === undefined)) { throw new JssmError(undefined, `Must have an index if transition was in a list"); }
29
- // if ((wasIndex !== undefined) && (wasList === undefined)) { throw new JssmError(undefined, `Must be in a list if transition has an index"); }
30
- /*
31
- if (typeof edge.to === 'object') {
32
-
33
- if (edge.to.key === 'cycle') {
34
- if (wasList === undefined) { throw new JssmError(undefined, "Must have a waslist if a to is type cycle"); }
35
- const nextIndex = wrapBy(wasIndex, edge.to.value, wasList.length);
36
- edge.to = wasList[nextIndex];
37
- }
38
-
39
- }
40
- */
41
- const action = isRight ? 'r_action' : 'l_action', probability = isRight ? 'r_probability' : 'l_probability';
42
- if (this_se[action]) {
43
- edge.action = this_se[action];
44
- }
45
- if (this_se[probability]) {
46
- edge.probability = this_se[probability];
47
- }
48
- return edge;
49
- }
50
- /*********
51
- *
52
- * This method wraps the parser call that comes from the peg grammar,
53
- * {@link parse}. Generally neither this nor that should be used directly
54
- * unless you mean to develop plugins or extensions for the machine.
55
- *
56
- * Parses the intermediate representation of a compiled string down to a
57
- * machine configuration object. If you're using this (probably don't,) you're
58
- * probably also using {@link compile} and {@link Machine.constructor}.
59
- *
60
- * ```typescript
61
- * import { parse, compile, Machine } from 'jssm';
62
- *
63
- * const intermediate = wrap_parse('a -> b;', {});
64
- * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
65
- *
66
- * const cfg = compile(intermediate);
67
- * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
68
- *
69
- * const machine = new Machine(cfg);
70
- * // Machine { _instance_name: undefined, _state: 'a', ...
71
- * ```
72
- *
73
- * This method is mostly for plugin and intermediate tool authors, or people
74
- * who need to work with the machine's intermediate representation.
75
- *
76
- * # Hey!
77
- *
78
- * Most people looking at this want either the `sm` operator or method `from`,
79
- * which perform all the steps in the chain. The library's author mostly uses
80
- * operator `sm`, and mostly falls back to `.from` when needing to parse
81
- * strings dynamically instead of from template literals.
82
- *
83
- * Operator {@link sm}:
84
- *
85
- * ```typescript
86
- * import { sm } from 'jssm';
87
- *
88
- * const lswitch = sm`on <=> off;`;
89
- * ```
90
- *
91
- * Method {@link from}:
92
- *
93
- * ```typescript
94
- * import * as jssm from 'jssm';
95
- *
96
- * const toggle = jssm.from('up <=> down;');
97
- * ```
98
- *
99
- * `wrap_parse` itself is an internal convenience method for alting out an
100
- * object as the options call. Not generally meant for external use.
101
- *
102
- * @param input The FSL code to be evaluated
103
- *
104
- * @param options Things to control about the instance
105
- *
106
- */
107
- function wrap_parse(input, options) {
108
- return parse(input, options || {});
109
- }
110
- /*********
111
- *
112
- * Internal method performing one step in compiling rules for transitions. Not
113
- * generally meant for external use.
114
- *
115
- * @internal
116
- *
117
- * @typeparam mDT The type of the machine data member; usually omitted
118
- *
119
- */
120
- function compile_rule_transition_step(acc, from, to, this_se, next_se) {
121
- const edges = [];
122
- const uFrom = (Array.isArray(from) ? from : [from]), uTo = (Array.isArray(to) ? to : [to]);
123
- uFrom.map((f) => {
124
- uTo.map((t) => {
125
- const right = makeTransition(this_se, f, t, true);
126
- if (right.kind !== 'none') {
127
- edges.push(right);
128
- }
129
- const left = makeTransition(this_se, t, f, false);
130
- if (left.kind !== 'none') {
131
- edges.push(left);
132
- }
133
- });
134
- });
135
- const new_acc = acc.concat(edges);
136
- if (next_se) {
137
- return compile_rule_transition_step(new_acc, to, next_se.to, next_se, next_se.se);
138
- }
139
- else {
140
- return new_acc;
141
- }
142
- }
143
- /*********
144
- *
145
- * Internal method performing one step in compiling rules for transitions. Not
146
- * generally meant for external use.
147
- *
148
- * @internal
149
- *
150
- */
151
- function compile_rule_handle_transition(rule) {
152
- return compile_rule_transition_step([], rule.from, rule.se.to, rule.se, rule.se.se);
153
- }
154
- /*********
155
- *
156
- * Internal method performing one step in compiling rules for transitions. Not
157
- * generally meant for external use.
158
- *
159
- * @internal
160
- *
161
- */
162
- function compile_rule_handler(rule) {
163
- if (rule.key === 'transition') {
164
- return { agg_as: 'transition', val: compile_rule_handle_transition(rule) };
165
- }
166
- if (rule.key === 'machine_language') {
167
- return { agg_as: 'machine_language', val: reduce_to_639(rule.value) };
168
- }
169
- // manually rehandled to make `undefined` as a property safe
170
- if (rule.key === 'property_definition') {
171
- const ret = { agg_as: 'property_definition', val: { name: rule.name } };
172
- if (rule.hasOwnProperty('default_value')) {
173
- ret.val.default_value = rule.default_value;
174
- }
175
- if (rule.hasOwnProperty('required')) {
176
- ret.val.required = rule.required;
177
- }
178
- return ret;
179
- }
180
- // state properties are in here
181
- if (rule.key === 'state_declaration') {
182
- if (!rule.name) {
183
- throw new JssmError(undefined, 'State declarations must have a name');
184
- }
185
- return { agg_as: 'state_declaration', val: { state: rule.name, declarations: rule.value } };
186
- }
187
- if (['arrange_declaration', 'arrange_start_declaration',
188
- 'arrange_end_declaration'].includes(rule.key)) {
189
- return { agg_as: rule.key, val: [rule.value] };
190
- }
191
- // things that can only exist once and are just a value under their own name
192
- const tautologies = [
193
- 'graph_layout', 'start_states', 'end_states', 'machine_name', 'machine_version',
194
- 'machine_comment', 'machine_author', 'machine_contributor', 'machine_definition',
195
- 'machine_reference', 'machine_license', 'fsl_version', 'state_config', 'theme',
196
- 'flow', 'dot_preamble', 'allows_override', 'default_state_config',
197
- 'default_start_state_config', 'default_end_state_config',
198
- 'default_hooked_state_config', 'default_active_state_config',
199
- 'default_terminal_state_config'
200
- ];
201
- if (tautologies.includes(rule.key)) {
202
- return { agg_as: rule.key, val: rule.value };
203
- }
204
- throw new JssmError(undefined, `compile_rule_handler: Unknown rule: ${JSON.stringify(rule)}`);
205
- }
206
- /*********
207
- *
208
- * Compile a machine's JSON intermediate representation to a config object. If
209
- * you're using this (probably don't,) you're probably also using
210
- * {@link parse} to get the IR, and the object constructor
211
- * {@link Machine.construct} to turn the config object into a workable machine.
212
- *
213
- * ```typescript
214
- * import { parse, compile, Machine } from 'jssm';
215
- *
216
- * const intermediate = parse('a -> b;');
217
- * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
218
- *
219
- * const cfg = compile(intermediate);
220
- * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
221
- *
222
- * const machine = new Machine(cfg);
223
- * // Machine { _instance_name: undefined, _state: 'a', ...
224
- * ```
225
- *
226
- * This method is mostly for plugin and intermediate tool authors, or people
227
- * who need to work with the machine's intermediate representation.
228
- *
229
- * # Hey!
230
- *
231
- * Most people looking at this want either the `sm` operator or method `from`,
232
- * which perform all the steps in the chain. The library's author mostly uses
233
- * operator `sm`, and mostly falls back to `.from` when needing to parse
234
- * strings dynamically instead of from template literals.
235
- *
236
- * Operator {@link sm}:
237
- *
238
- * ```typescript
239
- * import { sm } from 'jssm';
240
- *
241
- * const lswitch = sm`on <=> off;`;
242
- * ```
243
- *
244
- * Method {@link from}:
245
- *
246
- * ```typescript
247
- * import * as jssm from 'jssm';
248
- *
249
- * const toggle = jssm.from('up <=> down;');
250
- * ```
251
- *
252
- * @typeparam mDT The type of the machine data member; usually omitted
253
- *
254
- * @param tree The parse tree to be boiled down into a machine config
255
- *
256
- */
257
- function compile(tree) {
258
- const results = {
259
- graph_layout: [],
260
- transition: [],
261
- start_states: [],
262
- end_states: [],
263
- state_config: [],
264
- state_declaration: [],
265
- fsl_version: [],
266
- machine_author: [],
267
- machine_comment: [],
268
- machine_contributor: [],
269
- machine_definition: [],
270
- machine_language: [],
271
- machine_license: [],
272
- machine_name: [],
273
- machine_reference: [],
274
- property_definition: [],
275
- state_property: {},
276
- theme: [],
277
- flow: [],
278
- dot_preamble: [],
279
- arrange_declaration: [],
280
- arrange_start_declaration: [],
281
- arrange_end_declaration: [],
282
- machine_version: [],
283
- default_state_config: [],
284
- default_active_state_config: [],
285
- default_hooked_state_config: [],
286
- default_terminal_state_config: [],
287
- default_start_state_config: [],
288
- default_end_state_config: [],
289
- allows_override: []
290
- };
291
- tree.map((tr) => {
292
- const rule = compile_rule_handler(tr), agg_as = rule.agg_as, val = rule.val; // TODO FIXME no any
293
- results[agg_as] = results[agg_as].concat(val);
294
- });
295
- const property_keys = results['property_definition'].map(pd => pd.name), repeat_props = find_repeated(property_keys);
296
- if (repeat_props.length) {
297
- throw new JssmError(undefined, `Cannot repeat property definitions. Saw ${JSON.stringify(repeat_props)}`);
298
- }
299
- const assembled_transitions = [].concat(...results['transition']);
300
- const result_cfg = {
301
- start_states: results.start_states.length ? results.start_states : [assembled_transitions[0].from],
302
- end_states: results.end_states,
303
- transitions: assembled_transitions,
304
- state_property: [],
305
- };
306
- const oneOnlyKeys = [
307
- 'graph_layout', 'machine_name', 'machine_version', 'machine_comment',
308
- 'fsl_version', 'machine_license', 'machine_definition', 'machine_language',
309
- 'flow', 'dot_preamble', 'allows_override'
310
- ];
311
- oneOnlyKeys.map((oneOnlyKey) => {
312
- if (results[oneOnlyKey].length > 1) {
313
- throw new JssmError(undefined, `May only have one ${oneOnlyKey} statement maximum: ${JSON.stringify(results[oneOnlyKey])}`);
314
- }
315
- else {
316
- if (results[oneOnlyKey].length) {
317
- result_cfg[oneOnlyKey] = results[oneOnlyKey][0];
318
- }
319
- }
320
- });
321
- ['arrange_declaration', 'arrange_start_declaration', 'arrange_end_declaration',
322
- 'machine_author', 'machine_contributor', 'machine_reference', 'theme',
323
- 'state_declaration', 'property_definition', 'default_state_config',
324
- 'default_start_state_config', 'default_end_state_config',
325
- 'default_hooked_state_config', 'default_terminal_state_config',
326
- 'default_active_state_config'].map((multiKey) => {
327
- if (results[multiKey].length) {
328
- result_cfg[multiKey] = results[multiKey];
329
- }
330
- });
331
- // re-walk state declarations, already wrapped up, to get state properties,
332
- // which go out in a different datastructure
333
- results.state_declaration.forEach(sd => {
334
- sd.declarations.forEach(decl => {
335
- if (decl.key === 'state_property') {
336
- const label = name_bind_prop_and_state(decl.name, sd.state);
337
- if (result_cfg.state_property.findIndex(c => c.name === label) !== -1) {
338
- throw new JssmError(undefined, `A state may only bind a property once (${sd.state} re-binds ${decl.name})`);
339
- }
340
- else {
341
- result_cfg.state_property.push({ name: label, default_value: decl.value });
342
- }
343
- }
344
- });
345
- });
346
- return result_cfg;
347
- }
348
- /*********
349
- *
350
- * An internal convenience wrapper for parsing then compiling a machine string.
351
- * Not generally meant for external use. Please see {@link compile} or
352
- * {@link sm}.
353
- *
354
- * @typeparam mDT The type of the machine data member; usually omitted
355
- *
356
- * @param plan The FSL code to be evaluated and built into a machine config
357
- *
358
- */
359
- function make(plan) {
360
- return compile(wrap_parse(plan));
361
- }
362
- export { compile,
363
- // compile_rule_handler,
364
- // compile_rule_transition_step,
365
- // compile_rule_handle_transition,
366
- make, makeTransition, wrap_parse };
@@ -1,5 +0,0 @@
1
- export declare const NegInfinity: number, PosInfinity: number, Epsilon: number, Pi: number, E: number, Root2: number, RootHalf: number, Ln2: number, Ln10: number, Log2E: number, Log10E: number, MaxSafeInt: number, MinSafeInt: number, MaxPosNum: number, MinPosNum: number, Phi = 1.618033988749895, EulerC = 0.5772156649015329;
2
- declare const gviz_shapes: string[];
3
- declare const shapes: string[];
4
- declare const named_colors: string[];
5
- export { gviz_shapes, shapes, named_colors, };