<commit_before>--
-- Test & demonstration file for "fsm.lua"
--

FSM = require "fsm"


function action1() print("Performing action 1") end
function action2() print("Performing action 2") end

-- Define your state transitions here
local myStateTransitionTable = {
    {"state1", "event1", "state2", action1},
    {"state2", "event2", "state3", action2},
    {"*",      "event3", "state2", action1},  -- for any state
    {"*",      "*",      "state2", action2}   -- exception handler
}

-- Create your finite state machine
fsm = FSM.new(myStateTransitionTable)

-- Use your finite state machine
-- which starts by default with the first defined state
print("Current FSM state: " .. fsm:get())

-- Or you can set another state
fsm:set("state2")
print("Current FSM state: " .. fsm:get())

-- Resond on "event" and last set "state"
fsm:fire("event3")
print("Current FSM state: " .. fsm:get())



function action1() print("Performing action 1") end

function action2() print("Performing action 2") end

function action3() print("Action 3: Exception raised") end

function action4() print("Wildcard in action !!!") end

-- Define your state transitions here
local myStateTransitionTable = {
	{"state1", "event1", "state2", action1},
	{"state2", "event2", "state3", action2}
}

-- Create your instance of a finite state machine
fsm = FSM.new(myStateTransitionTable)

-- print( "Constant UNKNOWN = " .. UNKNOWN )
print( "Constant FSM.UNKNOWN = " .. FSM.UNKNOWN )

-- Use your finite state machine
-- which starts by default with the first defined state
print("Current FSM state: " .. fsm:get())

-- Or you can set another state
fsm:set("state2")
print("Current FSM state: " .. fsm:get())

-- Respond on "event" and last set "state"
fsm:fire("event2")
print("Current FSM state: " .. fsm:get())

-- Force exception
print("Force exception by firing unknown event")
fsm:fire("event3")
print("Current FSM state: " .. fsm:get())<commit_msg>work on finite state machine<commit_after>--
-- Test & demonstration file for "fsm.lua"
--

FSM = require "fsm"


-- function playmessage()
--     print("Play Message")
-- end

-- -- Define your state transitions here
-- local myStateTransitionTable = {
--     {"section1", "start", "section1", playmessage},
--     {"section1", "DTMF1", "section2", action1},
--     {"state2", "event2", "state3", action2},
--     {"state3", "event1", "state1", action3},
--     {"*",      "event3", "state3", action3},  -- for any state
--     {"*",      "*",      "unknow", unknow}   -- exception handler
-- }


function action1() print("Performing action 1") end
function action2() print("Performing action 2") end
function action3() print("Performing action 3") end
function unknow()
    print("Performing unknow")
    fsm:fire("event0")
end
function notunknow() print("Performing notunknow") end

-- Define your state transitions here
local myStateTransitionTable = {
    {"state1", "event1", "state2", action1},
    {"state2", "event2", "state3", action2},
    {"state3", "event1", "state1", action3},
    {"*",      "event3", "state3", action3},  -- for any state
    {"*",      "*",      "unknow", unknow},   -- exception handler
    {"unknow", "event0", "state2", notunknow},
    {"unknow", "*",      "state1", notunknow}
}

-- Create your finite state machine
fsm = FSM.new(myStateTransitionTable)

-- Use your finite state machine
-- which starts by default with the first defined state
print("Current FSM state: " .. fsm:get())

-- Or you can set another state
fsm:set("state2")
print("Current FSM state: " .. fsm:get())

-- Resond on "event" and last set "state"
fsm:fire("event3")
print("Current FSM state: " .. fsm:get())

fsm:fire("event1")
print("Current FSM state: " .. fsm:get())

fsm:fire("bloufff")
print("Current FSM state: " .. fsm:get())


-- function action1() print("Performing action 1") end

-- function action2() print("Performing action 2") end

-- function action3() print("Action 3: Exception raised") end

-- function action4() print("Wildcard in action !!!") end

-- -- Define your state transitions here
-- local myStateTransitionTable = {
-- 	{"state1", "event1", "state2", action1},
-- 	{"state2", "event2", "state3", action2}
-- }

-- -- Create your instance of a finite state machine
-- fsm = FSM.new(myStateTransitionTable)

-- -- print( "Constant UNKNOWN = " .. UNKNOWN )
-- print( "Constant FSM.UNKNOWN = " .. FSM.UNKNOWN )

-- -- Use your finite state machine
-- -- which starts by default with the first defined state
-- print("Current FSM state: " .. fsm:get())

-- -- Or you can set another state
-- fsm:set("state2")
-- print("Current FSM state: " .. fsm:get())

-- -- Respond on "event" and last set "state"
-- fsm:fire("event2")
-- print("Current FSM state: " .. fsm:get())

-- -- Force exception
-- print("Force exception by firing unknown event")
-- fsm:fire("event3")
-- print("Current FSM state: " .. fsm:get())
{'fraction_non_alphanumeric': 0.17459991793188345, 'fraction_numerical': 0.02051702913418137, 'mean_word_length': 3.6517175572519083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3583913', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1542, 'n_words': 491}