jssm 5.85.6 → 5.85.9
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/CHANGELOG.md +42 -54
- package/README.md +2 -2
- package/dist/es6/jssm.d.ts +11 -182
- package/dist/es6/jssm.js +5 -540
- package/dist/es6/jssm_arrow.d.ts +53 -0
- package/dist/es6/jssm_arrow.js +187 -0
- package/dist/es6/jssm_compiler.d.ts +135 -0
- package/dist/es6/jssm_compiler.js +363 -0
- package/dist/es6/jssm_types.d.ts +15 -15
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +11 -182
- package/jssm_arrow.d.ts +53 -0
- package/jssm_compiler.d.ts +135 -0
- package/jssm_types.d.ts +15 -15
- package/package.json +4 -2
package/jssm.d.ts
CHANGED
|
@@ -1,183 +1,12 @@
|
|
|
1
1
|
declare type StateType = string;
|
|
2
2
|
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
|
|
3
|
-
JssmMachineInternalState,
|
|
3
|
+
JssmMachineInternalState, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
|
|
4
|
+
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
|
|
5
|
+
import { compile, make, wrap_parse } from './jssm_compiler';
|
|
4
6
|
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
|
|
5
7
|
import * as constants from './jssm_constants';
|
|
6
8
|
declare const shapes: string[], gviz_shapes: string[], named_colors: string[];
|
|
7
9
|
import { version, build_time } from './version';
|
|
8
|
-
/*********
|
|
9
|
-
*
|
|
10
|
-
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { arrow_direction } from 'jssm';
|
|
14
|
-
*
|
|
15
|
-
* arrow_direction('->'); // 'right'
|
|
16
|
-
* arrow_direction('<~=>'); // 'both'
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @param arrow The arrow to be evaluated
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
|
|
23
|
-
/*********
|
|
24
|
-
*
|
|
25
|
-
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
26
|
-
*
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { arrow_left_kind } from 'jssm';
|
|
29
|
-
*
|
|
30
|
-
* arrow_left_kind('<-'); // 'legal'
|
|
31
|
-
* arrow_left_kind('<='); // 'main'
|
|
32
|
-
* arrow_left_kind('<~'); // 'forced'
|
|
33
|
-
* arrow_left_kind('<->'); // 'legal'
|
|
34
|
-
* arrow_left_kind('->'); // 'none'
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param arrow The arrow to be evaluated
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind;
|
|
41
|
-
/*********
|
|
42
|
-
*
|
|
43
|
-
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
44
|
-
*
|
|
45
|
-
* ```typescript
|
|
46
|
-
* import { arrow_left_kind } from 'jssm';
|
|
47
|
-
*
|
|
48
|
-
* arrow_left_kind('->'); // 'legal'
|
|
49
|
-
* arrow_left_kind('=>'); // 'main'
|
|
50
|
-
* arrow_left_kind('~>'); // 'forced'
|
|
51
|
-
* arrow_left_kind('<->'); // 'legal'
|
|
52
|
-
* arrow_left_kind('<-'); // 'none'
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @param arrow The arrow to be evaluated
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
|
|
59
|
-
/*********
|
|
60
|
-
*
|
|
61
|
-
* This method wraps the parser call that comes from the peg grammar,
|
|
62
|
-
* {@link parse}. Generally neither this nor that should be used directly
|
|
63
|
-
* unless you mean to develop plugins or extensions for the machine.
|
|
64
|
-
*
|
|
65
|
-
* Parses the intermediate representation of a compiled string down to a
|
|
66
|
-
* machine configuration object. If you're using this (probably don't,) you're
|
|
67
|
-
* probably also using {@link compile} and {@link Machine.constructor}.
|
|
68
|
-
*
|
|
69
|
-
* ```typescript
|
|
70
|
-
* import { parse, compile, Machine } from 'jssm';
|
|
71
|
-
*
|
|
72
|
-
* const intermediate = wrap_parse('a -> b;', {});
|
|
73
|
-
* // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
|
|
74
|
-
*
|
|
75
|
-
* const cfg = compile(intermediate);
|
|
76
|
-
* // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
|
|
77
|
-
*
|
|
78
|
-
* const machine = new Machine(cfg);
|
|
79
|
-
* // Machine { _instance_name: undefined, _state: 'a', ...
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* This method is mostly for plugin and intermediate tool authors, or people
|
|
83
|
-
* who need to work with the machine's intermediate representation.
|
|
84
|
-
*
|
|
85
|
-
* # Hey!
|
|
86
|
-
*
|
|
87
|
-
* Most people looking at this want either the `sm` operator or method `from`,
|
|
88
|
-
* which perform all the steps in the chain. The library's author mostly uses
|
|
89
|
-
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
90
|
-
* strings dynamically instead of from template literals.
|
|
91
|
-
*
|
|
92
|
-
* Operator {@link sm}:
|
|
93
|
-
*
|
|
94
|
-
* ```typescript
|
|
95
|
-
* import { sm } from 'jssm';
|
|
96
|
-
*
|
|
97
|
-
* const lswitch = sm`on <=> off;`;
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
|
-
* Method {@link from}:
|
|
101
|
-
*
|
|
102
|
-
* ```typescript
|
|
103
|
-
* import * as jssm from 'jssm';
|
|
104
|
-
*
|
|
105
|
-
* const toggle = jssm.from('up <=> down;');
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* `wrap_parse` itself is an internal convenience method for alting out an
|
|
109
|
-
* object as the options call. Not generally meant for external use.
|
|
110
|
-
*
|
|
111
|
-
* @param input The FSL code to be evaluated
|
|
112
|
-
*
|
|
113
|
-
* @param options Things to control about the instance
|
|
114
|
-
*
|
|
115
|
-
*/
|
|
116
|
-
declare function wrap_parse(input: string, options?: Object): any;
|
|
117
|
-
/*********
|
|
118
|
-
*
|
|
119
|
-
* Compile a machine's JSON intermediate representation to a config object. If
|
|
120
|
-
* you're using this (probably don't,) you're probably also using
|
|
121
|
-
* {@link parse} to get the IR, and the object constructor
|
|
122
|
-
* {@link Machine.construct} to turn the config object into a workable machine.
|
|
123
|
-
*
|
|
124
|
-
* ```typescript
|
|
125
|
-
* import { parse, compile, Machine } from 'jssm';
|
|
126
|
-
*
|
|
127
|
-
* const intermediate = parse('a -> b;');
|
|
128
|
-
* // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
|
|
129
|
-
*
|
|
130
|
-
* const cfg = compile(intermediate);
|
|
131
|
-
* // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
|
|
132
|
-
*
|
|
133
|
-
* const machine = new Machine(cfg);
|
|
134
|
-
* // Machine { _instance_name: undefined, _state: 'a', ...
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* This method is mostly for plugin and intermediate tool authors, or people
|
|
138
|
-
* who need to work with the machine's intermediate representation.
|
|
139
|
-
*
|
|
140
|
-
* # Hey!
|
|
141
|
-
*
|
|
142
|
-
* Most people looking at this want either the `sm` operator or method `from`,
|
|
143
|
-
* which perform all the steps in the chain. The library's author mostly uses
|
|
144
|
-
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
145
|
-
* strings dynamically instead of from template literals.
|
|
146
|
-
*
|
|
147
|
-
* Operator {@link sm}:
|
|
148
|
-
*
|
|
149
|
-
* ```typescript
|
|
150
|
-
* import { sm } from 'jssm';
|
|
151
|
-
*
|
|
152
|
-
* const lswitch = sm`on <=> off;`;
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* Method {@link from}:
|
|
156
|
-
*
|
|
157
|
-
* ```typescript
|
|
158
|
-
* import * as jssm from 'jssm';
|
|
159
|
-
*
|
|
160
|
-
* const toggle = jssm.from('up <=> down;');
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @typeparam mDT The type of the machine data member; usually omitted
|
|
164
|
-
*
|
|
165
|
-
* @param tree The parse tree to be boiled down into a machine config
|
|
166
|
-
*
|
|
167
|
-
*/
|
|
168
|
-
declare function compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>;
|
|
169
|
-
/*********
|
|
170
|
-
*
|
|
171
|
-
* An internal convenience wrapper for parsing then compiling a machine string.
|
|
172
|
-
* Not generally meant for external use. Please see {@link compile} or
|
|
173
|
-
* {@link sm}.
|
|
174
|
-
*
|
|
175
|
-
* @typeparam mDT The type of the machine data member; usually omitted
|
|
176
|
-
*
|
|
177
|
-
* @param plan The FSL code to be evaluated and built into a machine config
|
|
178
|
-
*
|
|
179
|
-
*/
|
|
180
|
-
declare function make<mDT>(plan: string): JssmGenericConfig<mDT>;
|
|
181
10
|
/*********
|
|
182
11
|
*
|
|
183
12
|
* An internal method meant to take a series of declarations and fold them into
|
|
@@ -192,7 +21,7 @@ declare function state_style_condense(jssk: JssmStateStyleKeyList): JssmStateCon
|
|
|
192
21
|
declare class Machine<mDT> {
|
|
193
22
|
_state: StateType;
|
|
194
23
|
_states: Map<StateType, JssmGenericState>;
|
|
195
|
-
_edges: Array<JssmTransition<mDT>>;
|
|
24
|
+
_edges: Array<JssmTransition<StateType, mDT>>;
|
|
196
25
|
_edge_map: Map<StateType, Map<StateType, number>>;
|
|
197
26
|
_named_transitions: Map<StateType, number>;
|
|
198
27
|
_actions: Map<StateType, Map<StateType, number>>;
|
|
@@ -267,7 +96,7 @@ declare class Machine<mDT> {
|
|
|
267
96
|
_start_state_style: JssmStateConfig;
|
|
268
97
|
_end_state_style: JssmStateConfig;
|
|
269
98
|
_state_labels: Map<string, string>;
|
|
270
|
-
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config }: JssmGenericConfig<mDT>);
|
|
99
|
+
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config }: JssmGenericConfig<StateType, mDT>);
|
|
271
100
|
/********
|
|
272
101
|
*
|
|
273
102
|
* Internal method for fabricating states. Not meant for external use.
|
|
@@ -648,7 +477,7 @@ declare class Machine<mDT> {
|
|
|
648
477
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
649
478
|
*
|
|
650
479
|
*/
|
|
651
|
-
list_edges(): Array<JssmTransition<mDT>>;
|
|
480
|
+
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
652
481
|
list_named_transitions(): Map<StateType, number>;
|
|
653
482
|
list_actions(): Array<StateType>;
|
|
654
483
|
get uses_actions(): boolean;
|
|
@@ -657,7 +486,7 @@ declare class Machine<mDT> {
|
|
|
657
486
|
set themes(to: FslTheme | FslTheme[]);
|
|
658
487
|
flow(): FslDirection;
|
|
659
488
|
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
660
|
-
lookup_transition_for(from: StateType, to: StateType): JssmTransition<mDT>;
|
|
489
|
+
lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
|
|
661
490
|
/********
|
|
662
491
|
*
|
|
663
492
|
* List all transitions attached to the current state, sorted by entrance and
|
|
@@ -719,7 +548,7 @@ declare class Machine<mDT> {
|
|
|
719
548
|
*
|
|
720
549
|
*/
|
|
721
550
|
list_exits(whichState?: StateType): Array<StateType>;
|
|
722
|
-
probable_exits_for(whichState: StateType): Array<JssmTransition<mDT>>;
|
|
551
|
+
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
723
552
|
probabilistic_transition(): boolean;
|
|
724
553
|
probabilistic_walk(n: number): Array<StateType>;
|
|
725
554
|
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
@@ -812,7 +641,7 @@ declare class Machine<mDT> {
|
|
|
812
641
|
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
813
642
|
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
814
643
|
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
815
|
-
edges_between(from: string, to: string): JssmTransition<mDT>[];
|
|
644
|
+
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
816
645
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
817
646
|
/*********
|
|
818
647
|
*
|
|
@@ -1180,7 +1009,7 @@ declare class Machine<mDT> {
|
|
|
1180
1009
|
*/
|
|
1181
1010
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
1182
1011
|
current_action_for(action: StateType): number;
|
|
1183
|
-
current_action_edge_for(action: StateType): JssmTransition<mDT>;
|
|
1012
|
+
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
1184
1013
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
1185
1014
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
1186
1015
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
@@ -1233,7 +1062,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
1233
1062
|
* @param ExtraConstructorFields Extra non-code configuration to pass at creation time
|
|
1234
1063
|
*
|
|
1235
1064
|
*/
|
|
1236
|
-
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
|
|
1065
|
+
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>> | undefined): Machine<mDT>;
|
|
1237
1066
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
1238
1067
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
1239
1068
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
package/jssm_arrow.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { JssmArrow, JssmArrowDirection, JssmArrowKind } from './jssm_types';
|
|
2
|
+
/*********
|
|
3
|
+
*
|
|
4
|
+
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { arrow_direction } from 'jssm';
|
|
8
|
+
*
|
|
9
|
+
* arrow_direction('->'); // 'right'
|
|
10
|
+
* arrow_direction('<~=>'); // 'both'
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param arrow The arrow to be evaluated
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
|
|
17
|
+
/*********
|
|
18
|
+
*
|
|
19
|
+
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { arrow_left_kind } from 'jssm';
|
|
23
|
+
*
|
|
24
|
+
* arrow_left_kind('<-'); // 'legal'
|
|
25
|
+
* arrow_left_kind('<='); // 'main'
|
|
26
|
+
* arrow_left_kind('<~'); // 'forced'
|
|
27
|
+
* arrow_left_kind('<->'); // 'legal'
|
|
28
|
+
* arrow_left_kind('->'); // 'none'
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param arrow The arrow to be evaluated
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind;
|
|
35
|
+
/*********
|
|
36
|
+
*
|
|
37
|
+
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { arrow_left_kind } from 'jssm';
|
|
41
|
+
*
|
|
42
|
+
* arrow_left_kind('->'); // 'legal'
|
|
43
|
+
* arrow_left_kind('=>'); // 'main'
|
|
44
|
+
* arrow_left_kind('~>'); // 'forced'
|
|
45
|
+
* arrow_left_kind('<->'); // 'legal'
|
|
46
|
+
* arrow_left_kind('<-'); // 'none'
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param arrow The arrow to be evaluated
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
|
|
53
|
+
export { arrow_direction, arrow_left_kind, arrow_right_kind };
|
|
@@ -0,0 +1,135 @@
|
|
|
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 };
|
package/jssm_types.d.ts
CHANGED
|
@@ -44,10 +44,10 @@ declare type JssmPropertyDefinition = {
|
|
|
44
44
|
};
|
|
45
45
|
declare type JssmTransitionPermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
46
46
|
declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
|
|
47
|
-
declare type JssmTransition<DataType> = {
|
|
47
|
+
declare type JssmTransition<StateType, DataType> = {
|
|
48
48
|
from: StateType;
|
|
49
49
|
to: StateType;
|
|
50
|
-
name?:
|
|
50
|
+
name?: StateType;
|
|
51
51
|
action?: StateType;
|
|
52
52
|
check?: JssmTransitionPermitterMaybeArray<DataType>;
|
|
53
53
|
probability?: number;
|
|
@@ -55,7 +55,7 @@ declare type JssmTransition<DataType> = {
|
|
|
55
55
|
forced_only: boolean;
|
|
56
56
|
main_path: boolean;
|
|
57
57
|
};
|
|
58
|
-
declare type JssmTransitions<DataType> = JssmTransition<DataType>[];
|
|
58
|
+
declare type JssmTransitions<StateType, DataType> = JssmTransition<StateType, DataType>[];
|
|
59
59
|
declare type JssmTransitionList = {
|
|
60
60
|
entrances: Array<StateType>;
|
|
61
61
|
exits: Array<StateType>;
|
|
@@ -79,7 +79,7 @@ declare type JssmMachineInternalState<DataType> = {
|
|
|
79
79
|
edge_map: Map<StateType, Map<StateType, number>>;
|
|
80
80
|
actions: Map<StateType, Map<StateType, number>>;
|
|
81
81
|
reverse_actions: Map<StateType, Map<StateType, number>>;
|
|
82
|
-
edges: Array<JssmTransition<DataType>>;
|
|
82
|
+
edges: Array<JssmTransition<StateType, DataType>>;
|
|
83
83
|
};
|
|
84
84
|
declare type JssmStatePermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
85
85
|
declare type JssmStatePermitterMaybeArray<DataType> = JssmStatePermitter<DataType> | Array<JssmStatePermitter<DataType>>;
|
|
@@ -88,7 +88,7 @@ declare type JssmGenericMachine<DataType> = {
|
|
|
88
88
|
state: StateType;
|
|
89
89
|
data?: DataType;
|
|
90
90
|
nodes?: Array<StateType>;
|
|
91
|
-
transitions: JssmTransitions<DataType>;
|
|
91
|
+
transitions: JssmTransitions<StateType, DataType>;
|
|
92
92
|
check?: JssmStatePermitterMaybeArray<DataType>;
|
|
93
93
|
min_transitions?: number;
|
|
94
94
|
max_transitions?: number;
|
|
@@ -173,10 +173,10 @@ declare type JssmBaseTheme = {
|
|
|
173
173
|
title: undefined;
|
|
174
174
|
};
|
|
175
175
|
declare type JssmTheme = Partial<JssmBaseTheme>;
|
|
176
|
-
declare type JssmGenericConfig<DataType> = {
|
|
176
|
+
declare type JssmGenericConfig<StateType, DataType> = {
|
|
177
177
|
graph_layout?: JssmLayout;
|
|
178
178
|
complete?: Array<StateType>;
|
|
179
|
-
transitions: JssmTransitions<DataType>;
|
|
179
|
+
transitions: JssmTransitions<StateType, DataType>;
|
|
180
180
|
theme?: FslTheme[];
|
|
181
181
|
flow?: FslDirection;
|
|
182
182
|
name?: string;
|
|
@@ -217,22 +217,22 @@ declare type JssmGenericConfig<DataType> = {
|
|
|
217
217
|
default_terminal_state_config?: JssmStateStyleKeyList;
|
|
218
218
|
default_active_state_config?: JssmStateStyleKeyList;
|
|
219
219
|
};
|
|
220
|
-
declare type JssmCompileRule = {
|
|
220
|
+
declare type JssmCompileRule<StateType> = {
|
|
221
221
|
agg_as: string;
|
|
222
222
|
val: any;
|
|
223
223
|
};
|
|
224
|
-
declare type JssmCompileSe = {
|
|
224
|
+
declare type JssmCompileSe<StateType, mDT> = {
|
|
225
225
|
to: StateType;
|
|
226
|
-
se: JssmCompileSe
|
|
226
|
+
se: JssmCompileSe<StateType, mDT>;
|
|
227
227
|
kind: JssmArrow;
|
|
228
228
|
l_action?: StateType;
|
|
229
229
|
r_action?: StateType;
|
|
230
230
|
l_probability: number;
|
|
231
231
|
r_probability: number;
|
|
232
232
|
};
|
|
233
|
-
declare type JssmCompileSeStart<DataType> = {
|
|
234
|
-
from:
|
|
235
|
-
se: JssmCompileSe
|
|
233
|
+
declare type JssmCompileSeStart<StateType, DataType> = {
|
|
234
|
+
from: StateType;
|
|
235
|
+
se: JssmCompileSe<StateType, DataType>;
|
|
236
236
|
key: string;
|
|
237
237
|
value?: string | number;
|
|
238
238
|
name?: string;
|
|
@@ -240,8 +240,8 @@ declare type JssmCompileSeStart<DataType> = {
|
|
|
240
240
|
default_value?: any;
|
|
241
241
|
required?: boolean;
|
|
242
242
|
};
|
|
243
|
-
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
|
|
244
|
-
declare type JssmParseFunctionType = (string: any) => JssmParseTree
|
|
243
|
+
declare type JssmParseTree<StateType, mDT> = Array<JssmCompileSeStart<StateType, mDT>>;
|
|
244
|
+
declare type JssmParseFunctionType<StateType, mDT> = (string: any) => JssmParseTree<StateType, mDT>;
|
|
245
245
|
declare type BasicHookDescription<mDT> = {
|
|
246
246
|
kind: 'hook';
|
|
247
247
|
from: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jssm",
|
|
3
|
-
"version": "5.85.
|
|
3
|
+
"version": "5.85.9",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=10.0.0"
|
|
6
6
|
},
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"jest-unicode-action": "jest unicode-actions.uspec.ts -c jest-unicode.config.js --color --verbose",
|
|
32
32
|
"jest-unicode-string": "jest unicode-strings.uspec.ts -c jest-unicode.config.js --color --verbose",
|
|
33
33
|
"jest-unicode-atom": "jest unicode-atoms.uspec.ts -c jest-unicode.config.js --color --verbose",
|
|
34
|
-
"jest-unicode-
|
|
34
|
+
"jest-unicode-string-label": "jest unicode-atoms.uspec.ts -c jest-unicode.config.js --color --verbose",
|
|
35
|
+
"jest-unicode-atom-label": "jest unicode-atoms.uspec.ts -c jest-unicode.config.js --color --verbose",
|
|
36
|
+
"jest-unicode-full-slow": "npm run jest-unicode-atom && npm run jest-unicode-string && npm run jest-unicode-atom-label && npm run jest-unicode-string-label && jest-unicode-action",
|
|
35
37
|
"jest-stoch": "jest -c jest-stoch.config.js --color --verbose",
|
|
36
38
|
"jest-dragon": "jest -c jest-dragon.config.js --color --verbose",
|
|
37
39
|
"jest-spec": "jest -c jest-spec.config.js --color --verbose",
|