From cb9cedebf2732a774621220ceff8927498c565a9 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Wed, 19 May 2021 20:50:03 +0800 Subject: [PATCH] =?UTF-8?q?pf:=20=E5=87=8F=E5=B0=91=E4=B8=80=E7=82=B9acsTr?= =?UTF-8?q?ee=E4=BB=A3=E7=A0=81=E5=8A=A0=E8=BD=BD=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eAcs.erl | 28 +++++++++++++++++++--------- src/genAcs.erl | 23 +++++++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) 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) ->