void GenerateGraphs() { var typeLookup = new Dictionary <string, int>(); _graphs = FATools.SplitDistinctGraphs(BuildDFA(typeLookup)); _config.TokenTypes.AddRange(AssembleTokenTypeList(typeLookup)); }
public void SplitDistinctGraphs_MultiStart() { var chars = "012345678"; var graphBuilder = new Graph.Builder(); var states = new Graph.State[12]; for (var i = 0; i < 12; i++) { int?startState; int?endState; if (i < 3) { startState = i; endState = null; } else if (i > 8) { startState = null; endState = i - 9; } else { startState = null; endState = null; } states[i] = graphBuilder.NewState(startState.HasValue, new NodeData(startState, endState)); if (i >= 3) { graphBuilder.AddTransition(states[i - 3], states[i], CharSet.New(chars[i - 3])); } } graphBuilder.AddTransition(states[3], states[7], CharSet.New('X')); var expected1 = "0 (S:S2) -- [2] --> 1\r\n" + "1 -- [5] --> 2\r\n" + "2 -- [8] --> 3 (L:E2)\r\n"; var expected2 = "0 (S:S1) -- [1] --> 1\r\n" + "2 (S:S0) -- [0] --> 3\r\n" + "1 -- [4] --> 4\r\n" + "3 -- [3] --> 5\r\n" + "3 -- [X] --> 4\r\n" + "4 -- [7] --> 6 (L:E1)\r\n" + "5 -- [6] --> 7 (L:E0)\r\n"; var results = FATools.SplitDistinctGraphs(graphBuilder.Graph); Assert.AreEqual(2, results.Length); Assert.AreEqual(expected1, FARenderer.Render(results[0])); Assert.AreEqual(expected2, FARenderer.Render(results[1])); }
public void SplitDistinctGraphs_SingleStart() { var chars = "012345678"; var graphBuilder = new Graph.Builder(); var startState = graphBuilder.NewState(true, new NodeData(0, null)); var states = new Graph.State[chars.Length]; for (var i = 0; i < states.Length; i++) { states[i] = graphBuilder.NewState(false, new NodeData(null, i)); graphBuilder.AddTransition(startState, states[i]); } var inGraph = graphBuilder.Graph; var results = FATools.SplitDistinctGraphs(inGraph); Assert.That(results.Length, Is.EqualTo(1)); Assert.That(results[0], Is.SameAs(inGraph)); }