/// <summary> /// Create a new incremental symbolic regex builder. /// </summary> /// <param name="solver">Effective Boolean algebra over S.</param> public SymbolicRegexBuilder(ICharAlgebra <S> solver) { this.solver = solver; this.epsilon = SymbolicRegex <S> .MkEpsilon(this); this.nothing = SymbolicRegex <S> .MkFalse(this); singletonCache[solver.False] = this.nothing; this.dot = SymbolicRegex <S> .MkTrue(this); singletonCache[solver.True] = this.dot; this.dotStar = SymbolicRegex <S> .MkDotStar(this, this.dot); this.startAnchor = SymbolicRegex <S> .MkStartAnchor(this); this.endAnchor = SymbolicRegex <S> .MkEndAnchor(this); this.eolAnchor = SymbolicRegex <S> .MkEolAnchor(this); this.bolAnchor = SymbolicRegex <S> .MkBolAnchor(this); this.newLine = SymbolicRegex <S> .MkNewline(this); singletonCache[this.newLine.set] = this.newLine; this.bolRegex = SymbolicRegex <S> .MkLoop(this, SymbolicRegex <S> .MkConcat(this, this.dotStar, this.newLine), 0, 1); this.eolRegex = SymbolicRegex <S> .MkLoop(this, SymbolicRegex <S> .MkConcat(this, this.newLine, this.dotStar), 0, 1); }
/// <summary> /// Make a concatenation of given regexes, if any regex is nothing then return nothing, eliminate /// intermediate epsilons /// </summary> public SymbolicRegex <S> MkConcat(params SymbolicRegex <S>[] regexes) { if (regexes.Length == 0) { return(this.epsilon); } var sr = regexes[regexes.Length - 1]; if (sr.IsNothing) { return(this.nothing); } else { //exclude epsilons from the concatenation for (int i = regexes.Length - 2; i >= 0; i--) { if (regexes[i].IsNothing) { return(this.nothing); } else if (sr.IsEpsilon) { sr = regexes[i]; } else if (!regexes[i].IsEpsilon) { sr = SymbolicRegex <S> .MkConcat(this, regexes[i], sr); } } return(sr); } }