Exemplo n.º 1
0
        public IntSet Visit(RepeatNode node, int posOffset)
        {
            int innerPosCount = PosCounter.Of(node.Inner);

            var result = SparseIntSetType.Instance.Mutable();

            // Traverse optional + last repetitions
            int compilationCount = node.InnerCompilationCount;
            int minCount         = Math.Max(node.MinCount, 1);

            for (int i = minCount - 1; i != compilationCount; ++i)
            {
                int offset = posOffset + innerPosCount * i;
                result.AddAll(node.Inner.Accept(this, offset));
            }

            bool isInnerNullable = node.Inner.Accept(NullableGetter.Instance);

            if (isInnerNullable)
            {
                // Traverse forced but nullable repetitions
                for (int i = 0; i != node.MinCount; ++i)
                {
                    int offset = posOffset + innerPosCount * i;
                    result.AddAll(node.Inner.Accept(this, offset));
                }
            }

            return(result.CompleteAndDestroy());
        }
Exemplo n.º 2
0
        public void FillFollowPos(
            int posOffset,
            List <RegularPositionInfo> positions,
            IEnumerable <AstNode> children)
        {
            int leftOffset = posOffset;

            for (int i = 1; i < children.Count(); ++i)
            {
                var left = children.ElementAt(i - 1);

                int rightOffset = leftOffset + PosCounter.Of(left);

                foreach (int leftPos in lastPosGetter.LastPos(posOffset, children.Take(i)))
                {
                    IntSet firstPos = firstPosGetter.FirstPos(rightOffset, children.Skip(i));
                    positions[leftPos].FollowPos.AddAll(firstPos);
                }

                leftOffset = rightOffset;
            }

            int offset = posOffset;

            foreach (var node in children)
            {
                node.Accept(this, offset);
                offset += PosCounter.Of(node);
            }
        }
Exemplo n.º 3
0
        public object Visit(OrNode node, int posOffset)
        {
            int offset = posOffset;

            foreach (var child in node.Children)
            {
                child.Accept(this, offset);
                offset += PosCounter.Of(child);
            }

            return(this);
        }
Exemplo n.º 4
0
        public IntSet Visit(OrNode node, int posOffset)
        {
            var result = SparseIntSetType.Instance.Mutable();
            int offset = posOffset;

            foreach (var child in node.Children)
            {
                result.AddAll(child.Accept(this, offset));
                offset += PosCounter.Of(child);
            }

            return(result);
        }
Exemplo n.º 5
0
        public object Visit(RepeatNode node, int posOffset)
        {
            FillFollowPos(
                posOffset,
                positions,
                Enumerable.Repeat(node.Inner, node.InnerCompilationCount));

            if (node.MaxCount == int.MaxValue)
            {
                FillFollowPosClosure(
                    posOffset + node.MinCount * PosCounter.Of(node.Inner),
                    node.Inner);
            }


            return(this);
        }
Exemplo n.º 6
0
        public IntSet LastPos(int posOffset, IEnumerable <AstNode> seq)
        {
            var result = SparseIntSetType.Instance.Mutable();
            int offset = posOffset + seq.Sum(node => PosCounter.Of(node));

            foreach (var node in Enumerable.Reverse(seq))
            {
                offset -= PosCounter.Of(node);

                result.AddAll(node.Accept(this, offset));
                if (!node.Accept(NullableGetter.Instance))
                {
                    break;
                }
            }

            return(result.CompleteAndDestroy());
        }
Exemplo n.º 7
0
        public IntSet FirstPos(int posOffset, IEnumerable <AstNode> seq)
        {
            var result = SparseIntSetType.Instance.Mutable();
            int offset = posOffset;

            foreach (var node in seq)
            {
                result.AddAll(node.Accept(this, offset));
                if (!node.Accept(NullableGetter.Instance))
                {
                    break;
                }

                offset += PosCounter.Of(node);
            }

            return(result.CompleteAndDestroy());
        }