From 03adac5d84f171251158f29cfe1ddaeb9862d3ce Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 17 Feb 2016 16:24:31 -0500 Subject: [PATCH] nitcc: Handle case of DFA state with a unique Any transition Signed-off-by: Jean Privat --- contrib/nitcc/src/autom.nit | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/contrib/nitcc/src/autom.nit b/contrib/nitcc/src/autom.nit index 84df722..6971e7c 100644 --- a/contrib/nitcc/src/autom.nit +++ b/contrib/nitcc/src/autom.nit @@ -725,11 +725,9 @@ private class DFAGenerator else add("\tredef fun trans(char) do\n") - add("\t\tvar c = char.code_point\n") - # Collect the sequence of tests in the dispatch sequence # The point here is that for each transition, there is a first and a last - # So holes hare to be identified + # So holes have to be identified var dispatch = new HashMap[Int, nullable State] var haslast: nullable State = null @@ -749,8 +747,15 @@ private class DFAGenerator end end + if dispatch.is_empty and haslast != null then + # Only one transition that accepts everything (quite rare) + else + # We need to check + add("\t\tvar c = char.code_point\n") + end + # Generate a sequence of `if` for the dispatch - if haslast != null then + if haslast != null and last >= 0 then # Special case: handle up-bound first if not an error add("\t\tif c > {last} then return dfastate_{names[haslast]}\n") # previous become the new last case -- 1.7.9.5