コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 protected UnaryRegexSpec(RegexSpec expression)
 {
     Expression = expression;
 }
コード例 #5
0
 protected abstract RegexSpec Simplify(LexerSpec lexerSpec, RegexSpec exp, bool changed);
コード例 #6
0
 public RepetitionSpec(RegexSpec exp, int minRepititions, int?maxRepititions)
     : base(exp)
 {
     MinRepititions = minRepititions;
     MaxRepititions = maxRepititions;
 }
コード例 #7
0
 public UptoSpec(RegexSpec expression)
     : base(expression)
 {
 }
コード例 #8
0
 public ComplementSpec(RegexSpec expression)
     : base(expression)
 {
 }