public static void AssertParseException(string message, string expressionString, string expectedExceptionMessage) { try { ReParser.Parse(expressionString); Assert.Fail(message + ": expected an exception to be thrown"); } catch (ReParseException ex) { Assert.That(ex.Message, Is.EqualTo(expectedExceptionMessage), message); } }
Graph BuildDFA(Dictionary <string, int> typeLookup) { var nfa = new Graph <NodeData, CharSet> .Builder(); for (var i = 0; i < _config.States.Count; i++) { var state = _config.States[i]; if (state.Rules.Count == 0) { ReporterHelper.AddError(_reporter, state.Label, "The state '{0}' does not define any rules.", state.Label.Text); continue; } var startState = nfa.NewState(true, new NodeData(i, null)); for (var j = 0; j < state.Rules.Count; j++) { var rule = state.Rules[j]; ReElement element; if (!typeLookup.TryGetValue(rule.Token.Text, out var endStateID)) { endStateID = typeLookup.Count; typeLookup.Add(rule.Token.Text, endStateID); } try { element = ReParser.Parse(rule.Regex.Text); } catch (ReParseException ex) { ReporterHelper.AddError(_reporter, rule.Regex, ex.Message); continue; } if (element.MatchesEmptyString) { ReporterHelper.AddWarning( _reporter, rule.Regex, "This regular expression claims to match the empty string, " + "this is not supported and usually indicates a typeo in the regular expression"); } element.GenerateNFA(nfa, startState, nfa.NewState(false, new NodeData(null, endStateID, j))); } } return(FATools.CreateDfa(nfa.Graph)); }
static object GenerateScanGraph(string text) { var errorReporter = new Mock <IErrorReporter>(MockBehavior.Strict); var parser = new ConfigParser(errorReporter.Object); var config = parser.Parse(new ConfigScanner(text)); var state = config.States[0]; var nfa = new Graph.Builder(); var start = nfa.NewState(true, new NodeData(0, null)); for (var i = 0; i < state.Rules.Count; i++) { var rule = state.Rules[i]; var element = ReParser.Parse(rule.Regex.Text); element.GenerateNFA(nfa, start, nfa.NewState(false, new NodeData(null, i))); } return(FATools.CreateDfa(nfa.Graph)); }
public static void AssertParse(string message, string expressionString, string expectedParseTree) { Assert.That(Renderer.Render(ReParser.Parse(expressionString)), Is.EqualTo(expectedParseTree), message); }