private Automaton ToAutomaton( IDictionary <string, Automaton> automata, IAutomatonProvider automatonProvider, bool minimize) { IList <Automaton> list; Automaton a = null; switch (this.kind) { case Kind.RegexpUnion: list = new List <Automaton>(); this.FindLeaves(this.exp1, Kind.RegexpUnion, list, automata, automatonProvider, minimize); this.FindLeaves(this.exp2, Kind.RegexpUnion, list, automata, automatonProvider, minimize); a = BasicOperations.Union(list); a.Minimize(); break; case Kind.RegexpConcatenation: list = new List <Automaton>(); this.FindLeaves(this.exp1, Kind.RegexpConcatenation, list, automata, automatonProvider, minimize); this.FindLeaves(this.exp2, Kind.RegexpConcatenation, list, automata, automatonProvider, minimize); a = BasicOperations.Concatenate(list); a.Minimize(); break; case Kind.RegexpIntersection: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize) .Intersection(this.exp2.ToAutomaton(automata, automatonProvider, minimize)); a.Minimize(); break; case Kind.RegexpOptional: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize).Optional(); a.Minimize(); break; case Kind.RegexpRepeat: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat(); a.Minimize(); break; case Kind.RegexpRepeatMin: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat(this.min); a.Minimize(); break; case Kind.RegexpRepeatMinMax: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat(this.min, this.max); a.Minimize(); break; case Kind.RegexpComplement: a = this.exp1.ToAutomaton(automata, automatonProvider, minimize).Complement(); a.Minimize(); break; case Kind.RegexpChar: a = BasicAutomata.MakeChar(this.c); break; case Kind.RegexpCharRange: a = BasicAutomata.MakeCharRange(this.@from, this.to); break; case Kind.RegexpAnyChar: a = BasicAutomata.MakeAnyChar(); break; case Kind.RegexpEmpty: a = BasicAutomata.MakeEmpty(); break; case Kind.RegexpString: a = BasicAutomata.MakeString(this.s); break; case Kind.RegexpAnyString: a = BasicAutomata.MakeAnyString(); break; case Kind.RegexpAutomaton: Automaton aa = null; if (automata != null) { automata.TryGetValue(this.s, out aa); } if (aa == null && automatonProvider != null) { try { aa = automatonProvider.GetAutomaton(this.s); } catch (IOException e) { throw new ArgumentException(string.Empty, e); } } if (aa == null) { throw new ArgumentException("'" + this.s + "' not found"); } a = aa.Clone(); // Always clone here (ignore allowMutate). break; case Kind.RegexpInterval: a = BasicAutomata.MakeInterval(this.min, this.max, this.digits); break; } return(a); }
/// <summary> /// Returns a new (deterministic) automaton that accepts any single character. /// </summary> /// <returns>A new (deterministic) automaton that accepts any single character.</returns> internal static Automaton MakeAnyChar() { return(BasicAutomata.MakeCharRange(char.MinValue, char.MaxValue)); }