Represents an expression that can be matched against a subject.
示例#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;
        }
示例#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;
        }
示例#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;
                }
            }
        }
示例#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;
        }
示例#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];
            }
示例#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();
        }
示例#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];
            }
示例#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);
     }
 }
示例#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;
        }
示例#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;
        }
示例#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;
        }
示例#13
0
文件: Rule.cs 项目: otac0n/Pegasus
        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();
        }
示例#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;
                }
            }
        }
示例#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);
                }
            }
示例#16
0
 private void Set(Expression expression, object value)
 {
     if (!this.types.ContainsKey(expression))
     {
         this.types[expression] = value;
     }
 }
示例#17
0
 private void WalkExpression(Expression expression, TextWriter writer, string indentation)
 {
     var temp = this.currentIndentation;
     this.currentIndentation = indentation;
     this.WalkExpression(expression);
     this.currentIndentation = temp;
 }
示例#18
0
 public virtual void WalkExpression(Expression expression)
 {
     this.expressionDispatcher(expression);
 }
 public override void WalkExpression(Expression expression)
 {
     this.leftAdjacent[this.currentRule].Add(expression);
     base.WalkExpression(expression);
 }