[][src]Crate winnow_sm

winnow_sm

This module implements a state machine populated from a text file. Library consumer can specify input file, or default to <rootdir>/input.txt.

Input file

This file contains nodes in one of three types: Question, Branching, or Terminating. Note - comments here are for demonstration only and are not (yet) supported. The Question type prompts for a string input, and can accept zero or more responses if prompt left blank:

1 // Node type must be 1
1 // Node to jump to on successful input, 0-indexed
3 // Node to jump to after exhausting fail prompts
NAME // Name of the variable to associate user's input with
What is your name? // First prompt
Please tell me your name // Second prompt
You better tell me your name // Third prompt

The Branching type gives the user a series of options, each with a destination if selected:

2 // Node type must be 2
QUEST // Name of the variable associated with this node
$NAME, what is your quest? // Question prompt
The Holy Grail:2 // Option One text:Option 1 destination
Run and Hide:3 // Option Two text:Option 2 destination

The Terminating type simply displays a message and signals execution should end:

3 // Node type must be 3
You may pass, $NAME who loves $COLOR, on your noble quest for the $QUEST.  // Exit message

Nodes are added and assigned IDs in the order they appear in the input, beginning with 0.

The string prompts perform simple variable expansion. You can refer to any variable previously defined in the file by prefixing it with a $, as in the examples. If a lookup fails, the name of the variable in the template will be used instead, without the leading $.

Structs

Env

User-defined variables

Node

Node type

Nodes

Containing structure for all nodes Nodes are registered in sequential order

NodesParser

Enums

NodeType

Each possible node variant

Rule

Constants

_PEST_GRAMMAR_NodesParser

Statics

DEFAULT_INPUT_FILE

Input file

TERMINATING_NODE

Exit condition

Functions

parse_branch_option_line

helper function to parse branch_option rule

parse_int_line

helper function to parse int_line rule

parse_string_line

helper function to parse string_line rule

trim_whitespace

Trim either \n or \r\n from a String

Type Definitions

BranchOption

A single branch option (prompt, destination)

NodeId

Unique node identifier type