protected override RegexSpec Simplify(LexerSpec lexerSpec, RegexSpec exp, bool changed) { // x{1,1} -> x if (MinRepititions == 1 && MaxRepititions == 1) { return(exp); } return(changed ? new RepetitionSpec(exp, MinRepititions, MaxRepititions) : this); }
protected override RegexSpec Simplify(LexerSpec lexerSpec, RegexSpec exp, bool changed) { // ~a -> !([^]* a [^]*) var anyChar = new CharClassSpec(InversionListCodePointSet.All); var repetition = new RepetitionSpec(anyChar, 0, null); var concatenation = new ConcatenationSpec(new[] { repetition, exp, repetition }); var expanded = new ComplementSpec(concatenation); return(expanded.Simplify(lexerSpec)); }
protected override RegexSpec Simplify(LexerSpec lexerSpec, RegexSpec exp, bool changed) { // ![x] -> [^x] var charClass = Expression.Simplify(lexerSpec).AsCharClass(); if (charClass != null) { return(new CharClassSpec(charClass.CodePoints.Complement())); } // !!x -> x var complement = exp as ComplementSpec; if (complement != null) { return(complement.Expression); } return(changed ? new ComplementSpec(exp) : this); }
protected UnaryRegexSpec(RegexSpec expression) { Expression = expression; }
protected abstract RegexSpec Simplify(LexerSpec lexerSpec, RegexSpec exp, bool changed);
public RepetitionSpec(RegexSpec exp, int minRepititions, int?maxRepititions) : base(exp) { MinRepititions = minRepititions; MaxRepititions = maxRepititions; }
public UptoSpec(RegexSpec expression) : base(expression) { }
public ComplementSpec(RegexSpec expression) : base(expression) { }