public void Dfab_StartsWith() { var dfab = new DfaBuilder("BB][CC"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Debug.WriteLine(dfab.ParseTree.ToString()); Assert.IsTrue(dfab.States[2].Starts); }
public void Dfab_Simple() { var dfab = new DfaBuilder("af"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Assert.AreEqual(2, dfab.States.Length, "Should have 2 states."); Assert.AreEqual(1, dfab.Transitions[0, 0xAF]); }
public void Dfab_MatchAny() { var dfab = new DfaBuilder("??"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Assert.AreEqual(2, dfab.States.Length, "Should have 2 states"); Assert.AreEqual(1, dfab.Transitions[0, 0xAF]); }
public void Dfab_StartsWith() { var dfab = new DfaBuilder("BB][CC"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); //Debug.WriteLine(dfab.ParseTree.ToString()); Assert.IsTrue(dfab.States[2].Starts); }
public void Dfab_MatchAny() { var dfab = new DfaBuilder("??"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Debug.WriteLine(dfab.ParseTree.ToString()); Assert.AreEqual(2, dfab.States.Length, "Should have 2 states"); Assert.AreEqual(1, dfab.Transitions[0, 0xAF]); }
public void Dfab_PlusCat() { var dfab = new DfaBuilder("CC+55"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Debug.WriteLine(dfab.ParseTree.ToString()); Assert.AreEqual(3, dfab.States.Length, "Should have 3 states."); Assert.AreEqual(1, dfab.Transitions[0, 0xCC]); Assert.AreEqual(1, dfab.Transitions[1, 0xCC]); Assert.AreEqual(2, dfab.Transitions[1, 0x55]); }
public void Dfab_Plus() { var dfab = new DfaBuilder("CC+"); dfab.ExtendWithEos(); dfab.BuildNodeSets(); dfab.BuildAutomaton(); Debug.WriteLine(dfab.ParseTree.ToString()); Assert.AreEqual(2, dfab.States.Length, "Should have 2 states."); Assert.AreEqual(1, dfab.Transitions[0, 0xCC]); Assert.AreEqual(1, dfab.Transitions[1, 0xCC]); }
public static Automaton CreateFromPattern(string pattern) { try { var parser = new PatternParser(pattern); var tree = parser.Parse(); var builder = new DfaBuilder(tree); builder.ExtendWithEos(); builder.BuildNodeSets(); builder.BuildAutomaton(tree); return new Automaton(builder.States, builder.Transitions); } catch { return null; } }