From 22230f02097b344f15301e68f1384a4351a2a1a5 Mon Sep 17 00:00:00 2001 From: John Haugeland Date: Sun, 22 May 2022 08:15:13 -0700 Subject: [PATCH] Document .from and sm, fixes StoneCypher/fsl#784, fixes StoneCypher/fsl#785 --- benchmark/results/general.chart.html | 14 +-- benchmark/results/general.json | 130 +++++++++++++-------------- dist/es6/jssm.d.ts | 41 ++++++++- dist/es6/jssm.js | 41 ++++++++- dist/es6/version.js | 2 +- dist/jssm.es5.cjs.js | 2 +- dist/jssm.es5.cjs.nonmin.js | 43 ++++++++- dist/jssm.es5.iife.js | 2 +- dist/jssm.es5.iife.nonmin.js | 43 ++++++++- docs/docs/classes/Machine.html | 2 +- docs/docs/modules.html | 36 ++++++-- jssm.d.ts | 41 ++++++++- package.json | 2 +- src/ts/jssm.ts | 43 ++++++++- src/ts/version.ts | 2 +- 15 files changed, 343 insertions(+), 101 deletions(-) diff --git a/benchmark/results/general.chart.html b/benchmark/results/general.chart.html index 9465a5b0..0e9d5439 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[]
  • 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 97d0e3bc..79e1767f 100644 --- a/docs/docs/modules.html +++ b/docs/docs/modules.html @@ -1,16 +1,16 @@ -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
  • +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.4"
    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>
    • +

      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 @@ -27,16 +27,25 @@

      Hey!

      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.

      +

      Operator sm:

      import { sm } from './jssm';

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

      … or …

      +

      Method {@link from}:

      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>
    • +

      Type parameters

      • mDT

      Parameters

      • tree: JssmParseTree

      Returns JssmGenericConfig<mDT>

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

      Create a state machine from an implementation string. This is one of the + two main paths for working with JSSM, alongside sm.

      +

      Use this method when you want to conveniently pull a state machine from a + string dynamically. Use operator sm when you just want to work with a + template expression.

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

      const switch = jssm.from('on <=> off;'); +
      +

      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
    • +

      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.

      @@ -55,14 +64,23 @@

      Hey!

      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.

      +

      Operator sm:

      import { sm } from './jssm';

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

      … or …

      +

      Method {@link from}:

      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
    • +

      Parameters

      • input: string
      • Optional options: Object

      Returns any

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

      Create a state machine from a template string. This is one of the two main + paths for working with JSSM, alongside {@link from}.

      +

      Use this method when you want to work directly and conveniently with a + constant template expression. Use .from when you want to pull from + dynamic strings.

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

      const switch = jssm.from('on <=> off;'); +
      +

      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.

      diff --git a/jssm.d.ts b/jssm.d.ts index 645affa4..a8a81d5c 100644 --- a/jssm.d.ts +++ b/jssm.d.ts @@ -82,13 +82,15 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind; * operator `sm`, and mostly falls back to `.from` when needing to parse * strings dynamically instead of from template literals. * + * Operator {@link sm}: + * * ```typescript * import { sm } from './jssm'; * * const switch = sm`on <=> off;`; * ``` * - * … or … + * Method {@link from}: * * ```typescript * import * as jssm from './jssm'; @@ -131,13 +133,15 @@ declare function wrap_parse(input: string, options?: Object): any; * operator `sm`, and mostly falls back to `.from` when needing to parse * strings dynamically instead of from template literals. * + * Operator {@link sm}: + * * ```typescript * import { sm } from './jssm'; * * const switch = sm`on <=> off;`; * ``` * - * … or … + * Method {@link from}: * * ```typescript * import * as jssm from './jssm'; @@ -281,6 +285,39 @@ declare class Machine { instance_name(): string | undefined; sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine; } +/********* + * + * Create a state machine from a template string. This is one of the two main + * paths for working with JSSM, alongside {@link from}. + * + * Use this method when you want to work directly and conveniently with a + * constant template expression. Use `.from` when you want to pull from + * dynamic strings. + * + * + * ```typescript + * import * as jssm from './jssm'; + * + * const switch = jssm.from('on <=> off;'); + * ``` + * + */ declare function sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine; +/********* + * + * Create a state machine from an implementation string. This is one of the + * two main paths for working with JSSM, alongside {@link sm}. + * + * Use this method when you want to conveniently pull a state machine from a + * string dynamically. Use operator `sm` when you just want to work with a + * template expression. + * + * ```typescript + * import * as jssm from './jssm'; + * + * const switch = jssm.from('on <=> off;'); + * ``` + * + */ declare function from(MachineAsString: string, ExtraConstructorFields?: Partial> | undefined): Machine; export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors }; diff --git a/package.json b/package.json index 9a9c5792..1c2b323f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jssm", - "version": "5.65.3", + "version": "5.65.4", "engines": { "node": ">=10.0.0" }, diff --git a/src/ts/jssm.ts b/src/ts/jssm.ts index f476b1ec..f582a175 100644 --- a/src/ts/jssm.ts +++ b/src/ts/jssm.ts @@ -309,13 +309,15 @@ function makeTransition( * operator `sm`, and mostly falls back to `.from` when needing to parse * strings dynamically instead of from template literals. * + * Operator {@link sm}: + * * ```typescript * import { sm } from './jssm'; * * const switch = sm`on <=> off;`; * ``` * - * … or … + * Method {@link from}: * * ```typescript * import * as jssm from './jssm'; @@ -471,13 +473,15 @@ function compile_rule_handler(rule: JssmCompileSeStart): JssmCompileR * operator `sm`, and mostly falls back to `.from` when needing to parse * strings dynamically instead of from template literals. * + * Operator {@link sm}: + * * ```typescript * import { sm } from './jssm'; * * const switch = sm`on <=> off;`; * ``` * - * … or … + * Method {@link from}: * * ```typescript * import * as jssm from './jssm'; @@ -1653,6 +1657,24 @@ class Machine { +/********* + * + * Create a state machine from a template string. This is one of the two main + * paths for working with JSSM, alongside {@link from}. + * + * Use this method when you want to work directly and conveniently with a + * constant template expression. Use `.from` when you want to pull from + * dynamic strings. + * + * + * ```typescript + * import * as jssm from './jssm'; + * + * const switch = jssm.from('on <=> off;'); + * ``` + * + */ + function sm(template_strings: TemplateStringsArray, ...remainder /* , arguments */): Machine { // foo`a${1}b${2}c` will come in as (['a','b','c'],1,2) @@ -1678,6 +1700,23 @@ function sm(template_strings: TemplateStringsArray, ...remainder /* , argum +/********* + * + * Create a state machine from an implementation string. This is one of the + * two main paths for working with JSSM, alongside {@link sm}. + * + * Use this method when you want to conveniently pull a state machine from a + * string dynamically. Use operator `sm` when you just want to work with a + * template expression. + * + * ```typescript + * import * as jssm from './jssm'; + * + * const switch = jssm.from('on <=> off;'); + * ``` + * + */ + function from(MachineAsString: string, ExtraConstructorFields?: Partial< JssmGenericConfig > | undefined): Machine { const to_decorate = make( MachineAsString ); diff --git a/src/ts/version.ts b/src/ts/version.ts index 8c29d8bc..f0857ae2 100644 --- a/src/ts/version.ts +++ b/src/ts/version.ts @@ -1,3 +1,3 @@ -const version: string = "5.65.3"; +const version: string = "5.65.4"; export { version };