diff --git a/benchmark/results/general.chart.html b/benchmark/results/general.chart.html index a38cd7ff..9465a5b0 100644 --- a/benchmark/results/general.chart.html +++ b/benchmark/results/general.chart.html @@ -28,7 +28,7 @@
- +
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Machine<mDT>

Type parameters

  • mDT

Hierarchy

  • Machine

Index

Constructors

Properties

Methods

Constructors

  • new Machine<mDT>(__namedParameters: JssmGenericConfig<mDT>): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • __namedParameters: JssmGenericConfig<mDT>

    Returns Machine<mDT>

Properties

_actions: Map<string, Map<string, number>>
_any_action_hook: Function
_any_transition_hook: Function
_arrange_declaration: string[][]
_arrange_end_declaration: string[][]
_arrange_start_declaration: string[][]
_dot_preamble: string
_edge_map: Map<string, Map<string, number>>
_edges: JssmTransition<mDT>[]
_entry_hooks: Map<string, Function>
_exit_hooks: Map<string, Function>
_flow: FslDirection
_forced_transition_hook: Function
_fsl_version?: string
_global_action_hooks: Map<string, Function>
_graph_layout: JssmLayout
_has_basic_hooks: boolean
_has_entry_hooks: boolean
_has_exit_hooks: boolean
_has_global_action_hooks: boolean
_has_hooks: boolean
_has_named_hooks: boolean
_has_transition_hooks: boolean
_hooks: Map<string, Function>
_instance_name: string
_machine_author?: string[]
_machine_comment?: string
_machine_contributor?: string[]
_machine_definition?: string
_machine_language?: string
_machine_license?: string
_machine_name?: string
_machine_version?: string
_main_transition_hook: Function
_named_hooks: Map<string, Function>
_named_transitions: Map<string, number>
_raw_state_declaration?: Object[]
_reverse_action_targets: Map<string, Map<string, number>>
_reverse_actions: Map<string, Map<string, number>>
_standard_transition_hook: Function
_state: string
_state_declarations: Map<string, JssmStateDeclaration>
_states: Map<string, JssmGenericState>
_theme: FslTheme

Methods

  • _new_state(state_config: JssmGenericState): string
  • Parameters

    • state_config: JssmGenericState

    Returns string

  • action(actionName: string, newData?: mDT): boolean
  • Parameters

    • actionName: string
    • Optional newData: mDT

    Returns boolean

  • actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • current_action_edge_for(action: string): JssmTransition<mDT>
  • Parameters

    • action: string

    Returns JssmTransition<mDT>

  • current_action_for(action: string): number
  • Parameters

    • action: string

    Returns number

  • dot_preamble(): string
  • edges_between(from: string, to: string): JssmTransition<mDT>[]
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>[]

  • flow(): FslDirection
  • force_transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • fsl_version(): string
  • get_transition_by_state_names(from: string, to: string): number
  • Parameters

    • from: string
    • to: string

    Returns number

  • graph_layout(): string
  • has_completes(): boolean
  • has_state(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • has_terminals(): boolean
  • has_unenterables(): boolean
  • hook(from: string, to: string, handler: Function): Machine<mDT>
  • hook_action(from: string, to: string, action: string, handler: Function): Machine<mDT>
  • Parameters

    • from: string
    • to: string
    • action: string
    • handler: Function

    Returns Machine<mDT>

  • hook_any_action(handler: Function): Machine<mDT>
  • hook_any_transition(handler: Function): Machine<mDT>
  • hook_entry(to: string, handler: Function): Machine<mDT>
  • hook_exit(from: string, handler: Function): Machine<mDT>
  • hook_forced_transition(handler: Function): Machine<mDT>
  • hook_global_action(action: string, handler: Function): Machine<mDT>
  • hook_main_transition(handler: Function): Machine<mDT>
  • hook_standard_transition(handler: Function): Machine<mDT>
  • instance_name(): string
  • is_complete(): boolean
  • is_final(): boolean
  • is_terminal(): boolean
  • is_unenterable(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • list_actions(): string[]
  • list_edges(): JssmTransition<mDT>[]
  • list_entrances(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exit_actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exits(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_named_transitions(): Map<string, number>
  • list_states_having_action(whichState: string): string[]
  • Parameters

    • whichState: string

    Returns string[]

  • list_transitions(whichState?: string): JssmTransitionList
  • Parameters

    • whichState: string = ...

    Returns JssmTransitionList

  • lookup_transition_for(from: string, to: string): JssmTransition<mDT>
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>

  • machine_author(): string[]
  • machine_comment(): string
  • machine_contributor(): string[]
  • machine_definition(): string
  • machine_language(): string
  • machine_license(): string
  • machine_name(): string
  • machine_state(): JssmMachineInternalState<mDT>
  • Returns JssmMachineInternalState<mDT>

  • machine_version(): string
  • probabilistic_histo_walk(n: number): Map<string, number>
  • Parameters

    • n: number

    Returns Map<string, number>

  • probabilistic_transition(): boolean
  • probabilistic_walk(n: number): string[]
  • Parameters

    • n: number

    Returns string[]

  • probable_action_exits(whichState?: string): any[]
  • Parameters

    • whichState: string = ...

    Returns any[]

  • probable_exits_for(whichState: string): JssmTransition<mDT>[]
  • Parameters

    • whichState: string

    Returns JssmTransition<mDT>[]

  • raw_state_declarations(): Object[]
  • set_hook(HookDesc: HookDescription): void
  • Parameters

    • HookDesc: HookDescription

    Returns void

  • sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • state(): string
  • state_declaration(which: string): JssmStateDeclaration
  • Parameters

    • which: string

    Returns JssmStateDeclaration

  • state_declarations(): Map<string, JssmStateDeclaration>
  • Returns Map<string, JssmStateDeclaration>

  • state_for(whichState: string): JssmGenericState
  • Parameters

    • whichState: string

    Returns JssmGenericState

  • state_is_complete(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_final(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_terminal(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • states(): string[]
  • theme(): FslTheme
  • transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • transition_impl(newStateOrAction: string, newData: mDT, wasForced: boolean, wasAction: boolean): boolean
  • Parameters

    • newStateOrAction: string
    • newData: mDT
    • wasForced: boolean
    • wasAction: boolean

    Returns boolean

  • valid_action(action: string, _newData?: mDT): boolean
  • Parameters

    • action: string
    • Optional _newData: mDT

    Returns boolean

  • valid_force_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

  • valid_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

Generated using TypeDoc

\ No newline at end of file +Machine | jssm
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Machine<mDT>

Type parameters

  • mDT

Hierarchy

  • Machine

Index

Constructors

Properties

Methods

Constructors

  • new Machine<mDT>(__namedParameters: JssmGenericConfig<mDT>): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • __namedParameters: JssmGenericConfig<mDT>

    Returns Machine<mDT>

Properties

_actions: Map<string, Map<string, number>>
_any_action_hook: Function
_any_transition_hook: Function
_arrange_declaration: string[][]
_arrange_end_declaration: string[][]
_arrange_start_declaration: string[][]
_dot_preamble: string
_edge_map: Map<string, Map<string, number>>
_edges: JssmTransition<mDT>[]
_entry_hooks: Map<string, Function>
_exit_hooks: Map<string, Function>
_flow: FslDirection
_forced_transition_hook: Function
_fsl_version?: string
_global_action_hooks: Map<string, Function>
_graph_layout: JssmLayout
_has_basic_hooks: boolean
_has_entry_hooks: boolean
_has_exit_hooks: boolean
_has_global_action_hooks: boolean
_has_hooks: boolean
_has_named_hooks: boolean
_has_transition_hooks: boolean
_hooks: Map<string, Function>
_instance_name: string
_machine_author?: string[]
_machine_comment?: string
_machine_contributor?: string[]
_machine_definition?: string
_machine_language?: string
_machine_license?: string
_machine_name?: string
_machine_version?: string
_main_transition_hook: Function
_named_hooks: Map<string, Function>
_named_transitions: Map<string, number>
_raw_state_declaration?: Object[]
_reverse_action_targets: Map<string, Map<string, number>>
_reverse_actions: Map<string, Map<string, number>>
_standard_transition_hook: Function
_state: string
_state_declarations: Map<string, JssmStateDeclaration>
_states: Map<string, JssmGenericState>
_theme: FslTheme

Methods

  • _new_state(state_config: JssmGenericState): string
  • Parameters

    • state_config: JssmGenericState

    Returns string

  • action(actionName: string, newData?: mDT): boolean
  • Parameters

    • actionName: string
    • Optional newData: mDT

    Returns boolean

  • actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • current_action_edge_for(action: string): JssmTransition<mDT>
  • Parameters

    • action: string

    Returns JssmTransition<mDT>

  • current_action_for(action: string): number
  • Parameters

    • action: string

    Returns number

  • dot_preamble(): string
  • edges_between(from: string, to: string): JssmTransition<mDT>[]
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>[]

  • flow(): FslDirection
  • force_transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • fsl_version(): string
  • get_transition_by_state_names(from: string, to: string): number
  • Parameters

    • from: string
    • to: string

    Returns number

  • graph_layout(): string
  • has_completes(): boolean
  • has_state(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • has_terminals(): boolean
  • has_unenterables(): boolean
  • hook(from: string, to: string, handler: Function): Machine<mDT>
  • hook_action(from: string, to: string, action: string, handler: Function): Machine<mDT>
  • Parameters

    • from: string
    • to: string
    • action: string
    • handler: Function

    Returns Machine<mDT>

  • hook_any_action(handler: Function): Machine<mDT>
  • hook_any_transition(handler: Function): Machine<mDT>
  • hook_entry(to: string, handler: Function): Machine<mDT>
  • hook_exit(from: string, handler: Function): Machine<mDT>
  • hook_forced_transition(handler: Function): Machine<mDT>
  • hook_global_action(action: string, handler: Function): Machine<mDT>
  • hook_main_transition(handler: Function): Machine<mDT>
  • hook_standard_transition(handler: Function): Machine<mDT>
  • instance_name(): string
  • is_complete(): boolean
  • is_final(): boolean
  • is_terminal(): boolean
  • is_unenterable(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • list_actions(): string[]
  • list_edges(): JssmTransition<mDT>[]
  • list_entrances(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exit_actions(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_exits(whichState?: string): string[]
  • Parameters

    • whichState: string = ...

    Returns string[]

  • list_named_transitions(): Map<string, number>
  • list_states_having_action(whichState: string): string[]
  • Parameters

    • whichState: string

    Returns string[]

  • list_transitions(whichState?: string): JssmTransitionList
  • Parameters

    • whichState: string = ...

    Returns JssmTransitionList

  • lookup_transition_for(from: string, to: string): JssmTransition<mDT>
  • Parameters

    • from: string
    • to: string

    Returns JssmTransition<mDT>

  • machine_author(): string[]
  • machine_comment(): string
  • machine_contributor(): string[]
  • machine_definition(): string
  • machine_language(): string
  • machine_license(): string
  • machine_name(): string
  • machine_state(): JssmMachineInternalState<mDT>
  • Returns JssmMachineInternalState<mDT>

  • machine_version(): string
  • probabilistic_histo_walk(n: number): Map<string, number>
  • Parameters

    • n: number

    Returns Map<string, number>

  • probabilistic_transition(): boolean
  • probabilistic_walk(n: number): string[]
  • probable_action_exits(whichState?: string): any[]
  • Parameters

    • whichState: string = ...

    Returns any[]

  • probable_exits_for(whichState: string): JssmTransition<mDT>[]
  • Parameters

    • whichState: string

    Returns JssmTransition<mDT>[]

  • raw_state_declarations(): Object[]
  • set_hook(HookDesc: HookDescription): void
  • Parameters

    • HookDesc: HookDescription

    Returns void

  • sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • state(): string
  • state_declaration(which: string): JssmStateDeclaration
  • Parameters

    • which: string

    Returns JssmStateDeclaration

  • state_declarations(): Map<string, JssmStateDeclaration>
  • Returns Map<string, JssmStateDeclaration>

  • state_for(whichState: string): JssmGenericState
  • Parameters

    • whichState: string

    Returns JssmGenericState

  • state_is_complete(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_final(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • state_is_terminal(whichState: string): boolean
  • Parameters

    • whichState: string

    Returns boolean

  • states(): string[]
  • theme(): FslTheme
  • transition(newState: string, newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional newData: mDT

    Returns boolean

  • transition_impl(newStateOrAction: string, newData: mDT, wasForced: boolean, wasAction: boolean): boolean
  • Parameters

    • newStateOrAction: string
    • newData: mDT
    • wasForced: boolean
    • wasAction: boolean

    Returns boolean

  • valid_action(action: string, _newData?: mDT): boolean
  • Parameters

    • action: string
    • Optional _newData: mDT

    Returns boolean

  • valid_force_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

  • valid_transition(newState: string, _newData?: mDT): boolean
  • Parameters

    • newState: string
    • Optional _newData: mDT

    Returns boolean

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/docs/modules.html b/docs/docs/modules.html index 2dd65769..97d0e3bc 100644 --- a/docs/docs/modules.html +++ b/docs/docs/modules.html @@ -1,16 +1,69 @@ -jssm
Options
All
  • Public
  • Public/Protected
  • All
Menu

jssm

Index

Variables

gviz_shapes: string[] = ...
histograph: Function = ...
named_colors: string[] = ...
seq: Function = ...
shapes: string[] = gviz_shapes
version: string = "5.65.2"
weighted_histo_key: Function = ...
weighted_rand_select: Function = ...
weighted_sample_select: Function = ...

Functions

  • arrow_direction(arrow: JssmArrow): JssmArrowDirection
  • +jssm
    Options
    All
    • Public
    • Public/Protected
    • All
    Menu

    jssm

    Index

    Variables

    gviz_shapes: string[] = ...
    histograph: Function = ...
    named_colors: string[] = ...
    seq: Function = ...
    shapes: string[] = gviz_shapes
    version: string = "5.65.3"
    weighted_histo_key: Function = ...
    weighted_rand_select: Function = ...
    weighted_sample_select: Function = ...

    Functions

    • arrow_direction(arrow: JssmArrow): JssmArrowDirection
    • Return the direction of an arrow - right, left, or both.

      import { arrow_direction } from './jssm';

      arrow_direction('->'); // 'right'
      arrow_direction('<~=>'); // 'both'
      -

      Parameters

      • arrow: JssmArrow

      Returns JssmArrowDirection

    • arrow_left_kind(arrow: JssmArrow): JssmArrowKind
    • +

      Parameters

      • arrow: JssmArrow

      Returns JssmArrowDirection

    • arrow_left_kind(arrow: JssmArrow): JssmArrowKind
    • Return the direction of an arrow - right, left, or both.

      import { arrow_left_kind } from './jssm';

      arrow_left_kind('<-'); // 'legal'
      arrow_left_kind('<='); // 'main'
      arrow_left_kind('<~'); // 'forced'
      arrow_left_kind('<->'); // 'legal'
      arrow_left_kind('->'); // 'none'
      -

      Parameters

      • arrow: JssmArrow

      Returns JssmArrowKind

    • arrow_right_kind(arrow: JssmArrow): JssmArrowKind
    • +

      Parameters

      • arrow: JssmArrow

      Returns JssmArrowKind

    • arrow_right_kind(arrow: JssmArrow): JssmArrowKind
    • Return the direction of an arrow - right, left, or both.

      import { arrow_left_kind } from './jssm';

      arrow_left_kind('->'); // 'legal'
      arrow_left_kind('=>'); // 'main'
      arrow_left_kind('~>'); // 'forced'
      arrow_left_kind('<->'); // 'legal'
      arrow_left_kind('<-'); // 'none'
      -

      Parameters

      • arrow: JssmArrow

      Returns JssmArrowKind

    • compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>
    • Type parameters

      • mDT

      Parameters

      • tree: JssmParseTree

      Returns JssmGenericConfig<mDT>

    • from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>>): Machine<mDT>
    • Type parameters

      • mDT

      Parameters

      • MachineAsString: string
      • Optional ExtraConstructorFields: Partial<JssmGenericConfig<mDT>>

      Returns Machine<mDT>

    • make<mDT>(plan: string): JssmGenericConfig<mDT>
    • Type parameters

      • mDT

      Parameters

      • plan: string

      Returns JssmGenericConfig<mDT>

    • parse(input: string, options?: Object): any
    • -

      Internal convenience method for alting out an object as the options call. - Not generally meant for external use.

      -

      Parameters

      • input: string
      • Optional options: Object

      Returns any

    • sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
    • Type parameters

      • mDT

      Parameters

      • template_strings: TemplateStringsArray
      • Rest ...remainder: any[]

      Returns Machine<mDT>

    • transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration
    • Parameters

      • state_decl: JssmStateDeclaration

      Returns JssmStateDeclaration

    Legend

    • Property
    • Method

    Settings

    Theme

    Generated using TypeDoc

    \ No newline at end of file +

    Parameters

    • arrow: JssmArrow

    Returns JssmArrowKind

  • compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>
  • +

    Compile a machine's JSON intermediate representation to a config object. If + you're using this (probably don't,) you're probably also using + parse to get the IR, and the object constructor + {@link Machine.construct} to turn the config object into a workable machine.

    +
    import { parse, compile, Machine } from './jssm';

    const intermediate = parse('a -> b;');
    // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]

    const cfg = compile(intermediate);
    // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }

    const machine = new Machine(cfg);
    // Machine { _instance_name: undefined, _state: 'a', ... +
    +

    This method is mostly for plugin and intermediate tool authors, or people + who need to work with the machine's intermediate representation.

    + + +

    Hey!

    +
    +

    Most people looking at this want either the sm operator or method from, + which perform all the steps in the chain. The library's author mostly uses + operator sm, and mostly falls back to .from when needing to parse + strings dynamically instead of from template literals.

    +
    import { sm } from './jssm';

    const switch = sm`on <=> off;`; +
    +

    … or …

    +
    import * as jssm from './jssm';

    const toggle = jssm.from('up <=> down;'); +
    +

    Type parameters

    • mDT

    Parameters

    • tree: JssmParseTree

    Returns JssmGenericConfig<mDT>

  • from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>>): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • MachineAsString: string
    • Optional ExtraConstructorFields: Partial<JssmGenericConfig<mDT>>

    Returns Machine<mDT>

  • make<mDT>(plan: string): JssmGenericConfig<mDT>
  • +

    An internal convenience wrapper for parsing then compiling a machine string. + Not generally meant for external use. Please see compile or + sm.

    +

    Type parameters

    • mDT

    Parameters

    • plan: string

    Returns JssmGenericConfig<mDT>

  • parse(input: string, options?: Object): any
  • +

    This method wraps the parser call that comes from the peg grammar, + parse. Generally neither this nor that should be used directly + unless you mean to develop plugins or extensions for the machine.

    +

    Parses the intermediate representation of a compiled string down to a + machine configuration object. If you're using this (probably don't,) you're + probably also using compile and Machine.constructor.

    +
    import { parse, compile, Machine } from './jssm';

    const intermediate = wrap_parse('a -> b;', {});
    // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]

    const cfg = compile(intermediate);
    // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }

    const machine = new Machine(cfg);
    // Machine { _instance_name: undefined, _state: 'a', ... +
    +

    This method is mostly for plugin and intermediate tool authors, or people + who need to work with the machine's intermediate representation.

    + + +

    Hey!

    +
    +

    Most people looking at this want either the sm operator or method from, + which perform all the steps in the chain. The library's author mostly uses + operator sm, and mostly falls back to .from when needing to parse + strings dynamically instead of from template literals.

    +
    import { sm } from './jssm';

    const switch = sm`on <=> off;`; +
    +

    … or …

    +
    import * as jssm from './jssm';

    const toggle = jssm.from('up <=> down;'); +
    +

    wrap_parse itself is an internal convenience method for alting out an + object as the options call. Not generally meant for external use.

    +

    Parameters

    • input: string
    • Optional options: Object

    Returns any

  • sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>
  • Type parameters

    • mDT

    Parameters

    • template_strings: TemplateStringsArray
    • Rest ...remainder: any[]

    Returns Machine<mDT>

  • transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration
  • +

    An internal method meant to take a series of declarations and fold them into + a single multi-faceted declaration, in the process of building a state. Not + generally meant for external use.

    +

    Parameters

    • state_decl: JssmStateDeclaration

    Returns JssmStateDeclaration

Generated using TypeDoc

\ No newline at end of file diff --git a/jssm.d.ts b/jssm.d.ts index f3926298..645affa4 100644 --- a/jssm.d.ts +++ b/jssm.d.ts @@ -51,13 +51,117 @@ declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind; declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind; /********* * - * Internal convenience method for alting out an object as the options call. - * Not generally meant for external use. + * This method wraps the parser call that comes from the peg grammar, + * {@link parse}. Generally neither this nor that should be used directly + * unless you mean to develop plugins or extensions for the machine. + * + * Parses the intermediate representation of a compiled string down to a + * machine configuration object. If you're using this (probably don't,) you're + * probably also using {@link compile} and {@link Machine.constructor}. + * + * ```typescript + * import { parse, compile, Machine } from './jssm'; + * + * const intermediate = wrap_parse('a -> b;', {}); + * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ] + * + * const cfg = compile(intermediate); + * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] } + * + * const machine = new Machine(cfg); + * // Machine { _instance_name: undefined, _state: 'a', ... + * ``` + * + * This method is mostly for plugin and intermediate tool authors, or people + * who need to work with the machine's intermediate representation. + * + * # Hey! + * + * Most people looking at this want either the `sm` operator or method `from`, + * which perform all the steps in the chain. The library's author mostly uses + * operator `sm`, and mostly falls back to `.from` when needing to parse + * strings dynamically instead of from template literals. + * + * ```typescript + * import { sm } from './jssm'; + * + * const switch = sm`on <=> off;`; + * ``` + * + * … or … + * + * ```typescript + * import * as jssm from './jssm'; + * + * const toggle = jssm.from('up <=> down;'); + * ``` + * + * `wrap_parse` itself is an internal convenience method for alting out an + * object as the options call. Not generally meant for external use. * */ declare function wrap_parse(input: string, options?: Object): any; +/********* + * + * Compile a machine's JSON intermediate representation to a config object. If + * you're using this (probably don't,) you're probably also using + * {@link parse} to get the IR, and the object constructor + * {@link Machine.construct} to turn the config object into a workable machine. + * + * ```typescript + * import { parse, compile, Machine } from './jssm'; + * + * const intermediate = parse('a -> b;'); + * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ] + * + * const cfg = compile(intermediate); + * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] } + * + * const machine = new Machine(cfg); + * // Machine { _instance_name: undefined, _state: 'a', ... + * ``` + * + * This method is mostly for plugin and intermediate tool authors, or people + * who need to work with the machine's intermediate representation. + * + * # Hey! + * + * Most people looking at this want either the `sm` operator or method `from`, + * which perform all the steps in the chain. The library's author mostly uses + * operator `sm`, and mostly falls back to `.from` when needing to parse + * strings dynamically instead of from template literals. + * + * ```typescript + * import { sm } from './jssm'; + * + * const switch = sm`on <=> off;`; + * ``` + * + * … or … + * + * ```typescript + * import * as jssm from './jssm'; + * + * const toggle = jssm.from('up <=> down;'); + * ``` + * + */ declare function compile(tree: JssmParseTree): JssmGenericConfig; +/********* + * + * An internal convenience wrapper for parsing then compiling a machine string. + * Not generally meant for external use. Please see {@link compile} or + * {@link sm}. + * + */ declare function make(plan: string): JssmGenericConfig; +/********* + * + * An internal method meant to take a series of declarations and fold them into + * a single multi-faceted declaration, in the process of building a state. Not + * generally meant for external use. + * + */ declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration; declare class Machine { _state: StateType; diff --git a/package.json b/package.json index 38f53a47..9a9c5792 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jssm", - "version": "5.65.2", + "version": "5.65.3", "engines": { "node": ">=10.0.0" }, diff --git a/src/ts/jssm.ts b/src/ts/jssm.ts index 2db05aeb..f476b1ec 100644 --- a/src/ts/jssm.ts +++ b/src/ts/jssm.ts @@ -278,8 +278,53 @@ function makeTransition( /********* * - * Internal convenience method for alting out an object as the options call. - * Not generally meant for external use. + * This method wraps the parser call that comes from the peg grammar, + * {@link parse}. Generally neither this nor that should be used directly + * unless you mean to develop plugins or extensions for the machine. + * + * Parses the intermediate representation of a compiled string down to a + * machine configuration object. If you're using this (probably don't,) you're + * probably also using {@link compile} and {@link Machine.constructor}. + * + * ```typescript + * import { parse, compile, Machine } from './jssm'; + * + * const intermediate = wrap_parse('a -> b;', {}); + * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ] + * + * const cfg = compile(intermediate); + * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] } + * + * const machine = new Machine(cfg); + * // Machine { _instance_name: undefined, _state: 'a', ... + * ``` + * + * This method is mostly for plugin and intermediate tool authors, or people + * who need to work with the machine's intermediate representation. + * + * # Hey! + * + * Most people looking at this want either the `sm` operator or method `from`, + * which perform all the steps in the chain. The library's author mostly uses + * operator `sm`, and mostly falls back to `.from` when needing to parse + * strings dynamically instead of from template literals. + * + * ```typescript + * import { sm } from './jssm'; + * + * const switch = sm`on <=> off;`; + * ``` + * + * … or … + * + * ```typescript + * import * as jssm from './jssm'; + * + * const toggle = jssm.from('up <=> down;'); + * ``` + * + * `wrap_parse` itself is an internal convenience method for alting out an + * object as the options call. Not generally meant for external use. * */ @@ -291,6 +336,13 @@ function wrap_parse(input: string, options?: Object) { +/********* + * + * Internal method performing one step in compiling rules for transitions. Not + * generally meant for external use. + * + */ + function compile_rule_transition_step( acc : Array>, @@ -330,12 +382,26 @@ function compile_rule_transition_step( +/********* + * + * Internal method performing one step in compiling rules for transitions. Not + * generally meant for external use. + * + */ + function compile_rule_handle_transition(rule: JssmCompileSeStart): any { // TODO FIXME no any // todo typescript describe the parser representation of a transition return compile_rule_transition_step([], rule.from, rule.se.to, rule.se, rule.se.se); } +/********* + * + * Internal method performing one step in compiling rules for transitions. Not + * generally meant for external use. + * + */ + function compile_rule_handler(rule: JssmCompileSeStart): JssmCompileRule { if (rule.key === 'transition') { @@ -375,6 +441,52 @@ function compile_rule_handler(rule: JssmCompileSeStart): JssmCompileR +/********* + * + * Compile a machine's JSON intermediate representation to a config object. If + * you're using this (probably don't,) you're probably also using + * {@link parse} to get the IR, and the object constructor + * {@link Machine.construct} to turn the config object into a workable machine. + * + * ```typescript + * import { parse, compile, Machine } from './jssm'; + * + * const intermediate = parse('a -> b;'); + * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ] + * + * const cfg = compile(intermediate); + * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] } + * + * const machine = new Machine(cfg); + * // Machine { _instance_name: undefined, _state: 'a', ... + * ``` + * + * This method is mostly for plugin and intermediate tool authors, or people + * who need to work with the machine's intermediate representation. + * + * # Hey! + * + * Most people looking at this want either the `sm` operator or method `from`, + * which perform all the steps in the chain. The library's author mostly uses + * operator `sm`, and mostly falls back to `.from` when needing to parse + * strings dynamically instead of from template literals. + * + * ```typescript + * import { sm } from './jssm'; + * + * const switch = sm`on <=> off;`; + * ``` + * + * … or … + * + * ```typescript + * import * as jssm from './jssm'; + * + * const toggle = jssm.from('up <=> down;'); + * ``` + * + */ + function compile(tree: JssmParseTree): JssmGenericConfig { const results: { @@ -477,6 +589,14 @@ function compile(tree: JssmParseTree): JssmGenericConfig { +/********* + * + * An internal convenience wrapper for parsing then compiling a machine string. + * Not generally meant for external use. Please see {@link compile} or + * {@link sm}. + * + */ + function make(plan: string): JssmGenericConfig { return compile(wrap_parse(plan)); } @@ -485,6 +605,14 @@ function make(plan: string): JssmGenericConfig { +/********* + * + * An internal method meant to take a series of declarations and fold them into + * a single multi-faceted declaration, in the process of building a state. Not + * generally meant for external use. + * + */ + function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration { state_decl.declarations.map( (d: JssmStateDeclarationRule) => { diff --git a/src/ts/version.ts b/src/ts/version.ts index 49a42a70..8c29d8bc 100644 --- a/src/ts/version.ts +++ b/src/ts/version.ts @@ -1,3 +1,3 @@ -const version: string = "5.65.2"; +const version: string = "5.65.3"; export { version };