From 914d0612cb479934b894e8ff93d24154c210009c Mon Sep 17 00:00:00 2001 From: masztal Date: Mon, 8 May 2017 20:16:00 +0200 Subject: [PATCH 1/2] Bug #65 fix Added necessary epsilon transitions in 'maybe' and 'kleene' functions --- src/automat/fsm.cljc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/automat/fsm.cljc b/src/automat/fsm.cljc index f72197d..aa4a0dd 100644 --- a/src/automat/fsm.cljc +++ b/src/automat/fsm.cljc @@ -691,24 +691,32 @@ "Accepts zero or more of the given automaton." [fsm] ;; remove epsilons before adding more - (let [fsm (-> fsm ->dfa ->nfa)] + (let [fsm (-> fsm ->dfa ->nfa) + start-state (state)] (nfa - (start fsm) - (conj (accept fsm) (start fsm)) + start-state + (conj (accept fsm) start-state) + (-> (reduce - #(assoc-in %1 [%2 epsilon] #{(start fsm)}) - (zipmap* (states fsm) #(input->state fsm %)) - (accept fsm)) + #(assoc-in %1 [%2 epsilon] #{(start fsm)}) + (zipmap* (states fsm) #(input->state fsm %)) + (accept fsm)) + (assoc-in [start-state epsilon] #{(start fsm)})) (zipmap* (states fsm) #(input->actions fsm %))))) (defn maybe "Accepts one or zero of the given automaton." [fsm] - ((if (deterministic? fsm) dfa nfa) - (start fsm) - (conj (accept fsm) (start fsm)) - (zipmap* (states fsm) #(input->state fsm %)) - (zipmap* (states fsm) #(input->actions fsm %)))) + ;; remove epsilons before adding more + (let [fsm (-> fsm ->dfa ->nfa) + start-state (state)] + (nfa + start-state + (conj (accept fsm) start-state) + (-> + (zipmap* (states fsm) #(input->state fsm %)) + (assoc-in [start-state epsilon] #{(start fsm)})) + (zipmap* (states fsm) #(input->actions fsm %))))) (defn- merge-fsms [a b accept-states actions] (let [a (gensym-states (->dfa a)) From c873c29fd7e3e33ef905bfc8021c51b17312b820 Mon Sep 17 00:00:00 2001 From: masztal Date: Tue, 6 Jun 2017 05:30:45 +0200 Subject: [PATCH 2/2] version 0.2.3 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 5c00f04..129f884 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject automat "0.2.2" +(defproject automat "0.2.3" :description "" :license {:name "MIT License" :url "http://opensource.org/licenses/MIT"}