diff --git a/src/eAcs.erl b/src/eAcs.erl index 9632fbb..b61bf83 100644 --- a/src/eAcs.erl +++ b/src/eAcs.erl @@ -27,8 +27,7 @@ doMatchMs(<>, State, Index, MatchList) -> end. matchWordMs(Word, State, Index, MatchList) -> - Node = acsTree:goto(State), - case Node of + case acsTree:goto(State) of undefined -> case State of 0 -> @@ -37,8 +36,11 @@ matchWordMs(Word, State, Index, MatchList) -> {NextState, _} = acsTree:failOut(State), matchWordMs(Word, NextState, Index, MatchList) end; - _ -> + Node -> case Node of + {Word, NextState} -> + NewMatchList = getOutputMs(NextState, Index, MatchList), + {NextState, NewMatchList}; #{Word := NextState} -> NewMatchList = getOutputMs(NextState, Index, MatchList), {NextState, NewMatchList}; @@ -87,8 +89,7 @@ doMatchIs(<>, State) -> end. matchWordIs(Word, State) -> - Node = acsTree:goto(State), - case Node of + case acsTree:goto(State) of undefined -> case State of 0 -> @@ -97,8 +98,15 @@ matchWordIs(Word, State) -> {NextState, _} = acsTree:failOut(State), matchWordIs(Word, NextState) end; - _ -> + Node -> case Node of + {Word, NextState} -> + case getOutputIs(NextState) of + false -> + NextState; + _ -> + true + end; #{Word := NextState} -> case getOutputIs(NextState) of false -> @@ -264,8 +272,7 @@ doMatchRs(<>, TotalSize, CurIndex, State, MatchList) -> end. matchWordRs(Word, State, MatchCnt) -> - Node = acsTree:goto(State), - case Node of + case acsTree:goto(State) of undefined -> case State of 0 -> @@ -274,8 +281,11 @@ matchWordRs(Word, State, MatchCnt) -> {NextState, _} = acsTree:failOut(State), matchWordRs(Word, NextState, MatchCnt) end; - _ -> + Node -> case Node of + {Word, NextState} -> + NewMatchCnt = getOutputRs(NextState, MatchCnt), + {NextState, NewMatchCnt}; #{Word := NextState} -> NewMatchCnt = getOutputRs(NextState, MatchCnt), {NextState, NewMatchCnt}; diff --git a/src/genAcs.erl b/src/genAcs.erl index 2937406..85fea6b 100644 --- a/src/genAcs.erl +++ b/src/genAcs.erl @@ -183,19 +183,26 @@ genGoto(Goto, StrAcc) -> doGenGoto([], StrAcc) -> < undefined.\n\n">>; doGenGoto([{K, V}], StrAcc) -> - case maps:size(V) > 0 of - true -> - < ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\ngoto(_) -> undefined.\n\n">>; + case maps:size(V) of + 0 -> + < undefined.\n\n">>; + 1 -> + [TupleKV] = maps:to_list(V), + < ", (iolist_to_binary(io_lib:format(<<"~w">>, [TupleKV])))/binary, ";\ngoto(_) -> undefined.\n\n">>; _ -> - < undefined.\n\n">> + < ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\ngoto(_) -> undefined.\n\n">> end; doGenGoto([{K, V} | SortKvs], StrAcc) -> - case maps:size(V) > 0 of - true -> - NewStrAcc = < ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\n">>, + case maps:size(V) of + 0 -> + doGenGoto(SortKvs, StrAcc); + 1 -> + [TupleKV] = maps:to_list(V), + NewStrAcc = < ", (iolist_to_binary(io_lib:format(<<"~w">>, [TupleKV])))/binary, ";\n">>, doGenGoto(SortKvs, NewStrAcc); _ -> - doGenGoto(SortKvs, StrAcc) + NewStrAcc = < ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\n">>, + doGenGoto(SortKvs, NewStrAcc) end. genFailOut([], _Fail, _Output, StrAcc) ->