Ejemplo n.º 1
0
        protected IList <ValueRange> DecodeRanges(object enumerator)
        {
            Symbol            temp    = null;
            List <ValueRange> _ranges = new List <ValueRange>();

            bool size = false;

            while (temp != Symbol.CloseParentheses)
            {
                Symbol value1 = Next(enumerator);
                Symbol value2 = null;

                if (value1 == Symbol.Size)
                {
                    size = true;
                    Next(enumerator).Expect(Symbol.OpenParentheses);
                    continue;
                }

                temp = Next(enumerator);
                if (temp == Symbol.DoubleDot)
                {
                    value2 = Next(enumerator);
                    temp   = Next(enumerator);
                }

                ValueRange range = new ValueRange(value1, value2);

                if (size)
                {
                    value1.Validate(range.Start < 0, "invalid sub-typing; size must be greater than 0");
                }

                value1.Validate(Contains(range.Start, _ranges), "invalid sub-typing");
                if (value2 != null)
                {
                    value2.Validate(Contains((int)range.End, _ranges), "invalid sub-typing");
                }

                foreach (ValueRange other in _ranges)
                {
                    value1.Validate(range.Contains(other.Start), "invalid sub-typing");
                    if (other.End != null)
                    {
                        value1.Validate(range.Contains((int)other.End), "invalid sub-typing");
                    }
                }

                _ranges.Add(range);
            }

            if (size)
            {
                Next(enumerator).Expect(Symbol.CloseParentheses);
            }
            return(_ranges);
        }
        protected static IList <ValueRange> DecodeRanges(object enumerator)
        {
            Symbol temp   = null;
            var    ranges = new List <ValueRange>();
            bool   size   = false;

            while (temp != Symbol.CloseParentheses)
            {
                Symbol value1 = enumerator.Next();
                Symbol value2 = null;

                if (value1 == Symbol.Size)
                {
                    size = true;
                    enumerator.Next().Expect(Symbol.OpenParentheses);
                    continue;
                }

                temp = enumerator.Next();
                if (temp == Symbol.DoubleDot)
                {
                    value2 = enumerator.Next();
                    temp   = enumerator.Next();
                }

                var range = new ValueRange(value1, value2);
                if (size)
                {
                    value1.Assert(range.Start >= 0, "invalid sub-typing; size must be greater than 0");
                }

                value1.Assert(!Contains(range.Start, ranges), "invalid sub-typing");
                if (value2 != null)
                {
                    value2.Assert(!Contains(range.End, ranges), "invalid sub-typing");
                }

                foreach (ValueRange other in ranges)
                {
                    value1.Assert(!range.Contains(other.Start), "invalid sub-typing");
                    if (other.End != null)
                    {
                        value1.Assert(!range.Contains((int)other.End), "invalid sub-typing");
                    }
                }

                ranges.Add(range);
            }

            if (size)
            {
                enumerator.Next().Expect(Symbol.CloseParentheses);
            }
            return(ranges);
        }
Ejemplo n.º 3
0
        protected static IList<ValueRange> DecodeRanges(object enumerator)
        {
            Symbol temp = null;
            var ranges = new List<ValueRange>();
            bool size = false;
            while (temp != Symbol.CloseParentheses)
            {
                Symbol value1 = enumerator.Next();
                Symbol value2 = null;

                if (value1 == Symbol.Size)
                {
                    size = true;
                    enumerator.Next().Expect(Symbol.OpenParentheses);
                    continue;
                }

                temp = enumerator.Next();
                if (temp == Symbol.DoubleDot)
                {
                    value2 = enumerator.Next();
                    temp = enumerator.Next();
                }

                var range = new ValueRange(value1, value2);
                if (size)
                {
                    value1.Assert(range.Start >= 0, "invalid sub-typing; size must be greater than 0");
                }

                value1.Assert(!Contains(range.Start, ranges), "invalid sub-typing");
                if (value2 != null)
                {
                    value2.Assert(!Contains(range.End, ranges), "invalid sub-typing");
                }

                foreach (ValueRange other in ranges)
                {
                    value1.Assert(!range.Contains(other.Start), "invalid sub-typing");
                    if (other.End != null)
                    {
                        value1.Assert(!range.Contains((int)other.End), "invalid sub-typing");
                    }
                }

                ranges.Add(range);
            }

            if (size)
            {
                enumerator.Next().Expect(Symbol.CloseParentheses);
            }
            return ranges;
        }
Ejemplo n.º 4
0
        public bool IntersectsWith(ValueRange other)
        {
            if (this._end == null)
            {
                return(other.Contains(this._start));
            }
            else if (other._end == null)
            {
                return(this.Contains(other._start));
            }

            return((this._start <= other.End) && (this._end >= other._start));
        }