Skip to content

Commit 904527f

Browse files
committed
docs: add missing docs to fsm and fsm_graph
1 parent 07906ff commit 904527f

File tree

3 files changed

+12
-118
lines changed

3 files changed

+12
-118
lines changed

undocumented_dashboard.v

-118
This file was deleted.

vlib/datatypes/fsm/fsm.v

+8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ mut:
3131
current_state string
3232
}
3333

34+
// StateMachine constructor. Returns a new StateMachine instance.
3435
pub fn new() StateMachine {
3536
return StateMachine{}
3637
}
3738

39+
// set_state sets the current state of the state machine to the given `name`.
3840
pub fn (mut s StateMachine) set_state(name string) ! {
3941
if name in s.states {
4042
s.current_state = name
@@ -43,10 +45,13 @@ pub fn (mut s StateMachine) set_state(name string) ! {
4345
}
4446
}
4547

48+
// get_state returns the current state of the state machine.
4649
pub fn (mut s StateMachine) get_state() string {
4750
return s.current_state
4851
}
4952

53+
// add_state adds a new state to the state machine.
54+
// It takes the `name` of the state, and three event handlers: `entry`, `run`, and `exit`.
5055
pub fn (mut s StateMachine) add_state(name string, entry EventHandlerFn, run EventHandlerFn, exit EventHandlerFn) {
5156
s.states[name] = State{
5257
entry_handler: entry
@@ -58,6 +63,8 @@ pub fn (mut s StateMachine) add_state(name string, entry EventHandlerFn, run Eve
5863
}
5964
}
6065

66+
// add_transition adds a new transition to the state machine.
67+
// It takes the `from` and `to` states, and a condition handler.
6168
pub fn (mut s StateMachine) add_transition(from string, to string, condition_handler ConditionFn) {
6269
t := Transition{
6370
to: to
@@ -70,6 +77,7 @@ pub fn (mut s StateMachine) add_transition(from string, to string, condition_han
7077
s.transitions[from] = [t]
7178
}
7279

80+
// run runs the state machine. It takes a `receiver` argument that is passed to the event handlers.
7381
pub fn (mut s StateMachine) run(receiver voidptr) ! {
7482
from_state := s.current_state
7583
mut to_state := s.current_state

vlib/datatypes/fsm/tools/fsm_graph.v

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import flag
33

4+
// read_file reads a file and returns the lines as a list of strings. It takes the file path as an argument.
45
pub fn read_file(file string) ![]string {
56
if os.is_file(file) {
67
text := os.read_lines(file) or {
@@ -12,6 +13,7 @@ pub fn read_file(file string) ![]string {
1213
return ['']
1314
}
1415

16+
// extract_transitions extracts the transitions from a line and returns it as a formatted string.
1517
pub fn extract_transitions(line string) ?string {
1618
mut result := ' '
1719
first_comma := line.index(',')?
@@ -24,12 +26,14 @@ pub fn extract_transitions(line string) ?string {
2426
return result + from + ' -> ' + to + ' [label=' + condition + '];'
2527
}
2628

29+
// get_transitions gets the transitions from a line and returns it as a formatted string using `extract_transitions`.
2730
pub fn get_transitions(line string) ?string {
2831
mut raw_text := line[line.index_any('(') + 1..line.index_any(')')]
2932
raw_text = raw_text.replace("'", '').replace(' ', '')
3033
return extract_transitions(raw_text)
3134
}
3235

36+
// main reads a file and generates a graph from the transitions in the file.
3337
pub fn main() {
3438
mut fp := flag.new_flag_parser(os.args)
3539
file := fp.string('file', `f`, '', 'input V file with transitions to generate graph from.')

0 commit comments

Comments
 (0)