Represents an expression that can be matched against a subject.
Ejemplo n.º 1
1
        /// <summary>
        /// Initializes a new instance of the <see cref="TypedExpression"/> class.
        /// </summary>
        /// <param name="type">The specific type of the wrapped expression.</param>
        /// <param name="expression">The wrapped expression.</param>
        public TypedExpression(CodeSpan type, Expression expression)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            this.Type = type;
            this.Expression = expression;
        }
Ejemplo n.º 2
1
        /// <summary>
        /// Initializes a new instance of the <see cref="TypedExpression"/> class.
        /// </summary>
        /// <param name="type">The specific type of the wrapped expression.</param>
        /// <param name="expression">The wrapped expression.</param>
        public TypedExpression(CodeSpan type, Expression expression)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            this.type = type;

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.expression = expression;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Quantifier"/> class.
        /// </summary>
        /// <param name="start">The cursor just before the <see cref="Quantifier"/>.</param>
        /// <param name="end">The cursor just after the <see cref="Quantifier"/>.</param>
        /// <param name="min">The minimum number of times to match.</param>
        /// <param name="max">The maximum number of times to match, if limited; or null, otherwise.</param>
        /// <param name="delimiter">The expression to use as a delimiter.</param>
        public Quantifier(Cursor start, Cursor end, int min, int? max = null, Expression delimiter = null)
        {
            if (start == null)
            {
                throw new ArgumentNullException(nameof(start));
            }

            if (end == null)
            {
                throw new ArgumentNullException(nameof(end));
            }

            this.Start = start;
            this.End = end;
            this.Min = min;
            this.Max = max;

            if (delimiter != null)
            {
                SequenceExpression sequenceExpression;
                if ((sequenceExpression = delimiter as SequenceExpression) == null || sequenceExpression.Sequence.Count != 0)
                {
                    this.Delimiter = delimiter;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotExpression"/> class.
        /// </summary>
        /// <param name="expression">An expression that must not match at a location for this expression to match at that location.</param>
        public NotExpression(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.expression = expression;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AndExpression"/> class.
        /// </summary>
        /// <param name="expression">An expression that must match at a location for this expression to match at that location.</param>
        public AndExpression(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            this.Expression = expression;
        }
            public override void WalkExpression(Expression expression)
            {
                bool? starting;
                if (!this.containsAssertions.TryGetValue(expression, out starting))
                {
                    this.containsAssertions[expression] = starting;
                }

                base.WalkExpression(expression);
                this.changed = this.changed || starting != this.containsAssertions[expression];
            }
Ejemplo n.º 7
0
        public Rule(Identifier identifier, Expression expression, IEnumerable<Identifier> flags)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.identifier = identifier;
            this.expression = expression;
            this.flags = flags.ToList().AsReadOnly();
        }
Ejemplo n.º 8
0
            public override void WalkExpression(Expression expression)
            {
                bool? starting;
                if (!this.zeroWidth.TryGetValue(expression, out starting))
                {
                    this.zeroWidth[expression] = starting;
                }

                base.WalkExpression(expression);
                this.changed = this.changed || starting != this.zeroWidth[expression];
            }
Ejemplo n.º 9
0
 public override void WalkExpression(Expression expression)
 {
     if (!this.types.ContainsKey(expression))
     {
         base.WalkExpression(expression);
         this.changed = this.changed || this.types.ContainsKey(expression);
     }
     else
     {
         base.WalkExpression(expression);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrefixedExpression"/> class.
        /// </summary>
        /// <param name="prefix">The name given to this expression as a prefix.</param>
        /// <param name="expression">The expression that has been prefixed.</param>
        public PrefixedExpression(Identifier prefix, Expression expression)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            this.Prefix = prefix;
            this.Expression = expression;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RepetitionExpression"/> class.
        /// </summary>
        /// <param name="expression">The expression to be repeatedly matched.</param>
        /// <param name="quantifier">The quantifier that specifies how many times to match and the delimiter of the matches.</param>
        public RepetitionExpression(Expression expression, Quantifier quantifier)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            if (quantifier == null)
            {
                throw new ArgumentNullException(nameof(quantifier));
            }

            this.Expression = expression;
            this.Quantifier = quantifier;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RepetitionExpression"/> class.
        /// </summary>
        /// <param name="expression">The expression to be repeatedly matched.</param>
        /// <param name="quantifier">The quantifier that specifies how many times to match and the delimiter of the matches.</param>
        public RepetitionExpression(Expression expression, Quantifier quantifier)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (quantifier == null)
            {
                throw new ArgumentNullException("quantifier");
            }

            this.expression = expression;
            this.quantifier = quantifier;
        }
Ejemplo n.º 13
0
        public Rule(Identifier identifier, Expression expression, IEnumerable<Identifier> flags)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            this.Identifier = identifier;
            this.Expression = expression;
            this.Flags = (flags ?? Enumerable.Empty<Identifier>()).ToList().AsReadOnly();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Quantifier"/> class.
        /// </summary>
        /// <param name="start">The cursor just before the <see cref="Quantifier"/>.</param>
        /// <param name="end">The cursor just after the <see cref="Quantifier"/>.</param>
        /// <param name="min">The minimum number of times to match.</param>
        /// <param name="max">The maximum number of times to match, if limited; or null, otherwise.</param>
        /// <param name="delimiter">The expression to use as a delimiter.</param>
        public Quantifier(Cursor start, Cursor end, int min, int? max = null, Expression delimiter = null)
        {
            this.start = start;
            this.end = end;
            this.min = min;
            this.max = max;

            if (delimiter != null)
            {
                SequenceExpression sequenceExpression;
                if ((sequenceExpression = delimiter as SequenceExpression) == null || sequenceExpression.Sequence.Count != 0)
                {
                    this.delimiter = delimiter;
                }
            }
        }
Ejemplo n.º 15
0
            private void Set(Expression expression, Expression toCopy, Func<object, object> map = null)
            {
                map = map ?? (t => t);

                object type;
                if (!this.types.ContainsKey(expression) && this.types.TryGetValue(toCopy, out type))
                {
                    this.types[expression] = map(type);
                }
            }
Ejemplo n.º 16
0
 private void Set(Expression expression, object value)
 {
     if (!this.types.ContainsKey(expression))
     {
         this.types[expression] = value;
     }
 }
Ejemplo n.º 17
0
 private void WalkExpression(Expression expression, TextWriter writer, string indentation)
 {
     var temp = this.currentIndentation;
     this.currentIndentation = indentation;
     this.WalkExpression(expression);
     this.currentIndentation = temp;
 }
Ejemplo n.º 18
0
 public virtual void WalkExpression(Expression expression)
 {
     this.expressionDispatcher(expression);
 }
Ejemplo n.º 19
0
 public override void WalkExpression(Expression expression)
 {
     this.leftAdjacent[this.currentRule].Add(expression);
     base.WalkExpression(expression);
 }