Ejemplo n.º 1
0
            private void AddSubBlocks(
                ref bool incrementIndex,
                ref int currentIndex,
                IFortranBlock currentFactory,
                Stack <IFortranBlock> blockStack,
                List <IContained> blockSubObjects)
            {
                foreach (var block in _blockParsers.Values)
                {
                    // If this isn't the start of a new block then check the next block parser.
                    if (!block.BlockStart(blockStack, _lines, currentIndex))
                    {
                        continue;
                    }

                    blockStack.Push(block);

                    // The start index of this block is the current index.
                    var startIndex = currentIndex;

                    // Get any blockParsers that maybe defined within the current block, these will be added later.
                    blockSubObjects.AddRange(this.SearchBlock(startIndex, ref currentIndex, blockStack));

                    // If the block does not have an explicit end, then stay on the same line to check for a block end and go to next line later.
                    incrementIndex = !currentFactory.ExplicitEnd;

                    // If the block has a unique end, then increment the index here so that the same line isn't checked again below.
                    if (currentFactory.ExplicitEnd)
                    {
                        currentIndex++;
                    }

                    return;
                }
            }
Ejemplo n.º 2
0
        public static void ReturnObjectCheck(IFortranBlock block, string linesString, IEnumerable <IContained> subObjects, Action <IEnumerable <IFortranObject> > makeAssertions)
        {
            var lines  = StringUtils.ConvertToFileLineList(linesString);
            var actual = block.ReturnObject(subObjects, lines)
                         .ToList <IFortranObject>();

            makeAssertions(actual);
        }
Ejemplo n.º 3
0
            private bool EndBlock(
                int startIndex,
                int currentIndex,
                Stack <IFortranBlock> blockStack,
                IFortranBlock currentFactory,
                List <IContained> blockObjects,
                IEnumerable <IContained> blockSubObjects)
            {
                // End the block if we are at the end of the source.
                if (!this.ValidLineIndex(currentIndex, blockStack))
                {
                    return(true);
                }

                var blockSubObjectsList = blockSubObjects as List <IContained> ?? blockSubObjects.ToList();

                // If block has not ended yet then return.
                if (!currentFactory.BlockEnd(blockStack.Skip(1), _lines, currentIndex))
                {
                    return(false);
                }

                // At this point we assumn the block has ended and create the object represented by it.
                var blockLines = _lines.GetRange(startIndex, currentIndex - startIndex + 1);
                IEnumerable <IContained> parsingResult = null;

                try
                {
                    parsingResult = currentFactory.ReturnObject(blockSubObjectsList, blockLines);
                }
                catch (BlockParserException e)
                {
                    _errorListener.Error(new ParserException(blockLines.First().Number, blockLines.Last().Number, e.Message));
                }

                // If we have created a valid block then add it to the list and return.
                if (parsingResult != null)
                {
                    blockObjects.AddRange(parsingResult);
                }

                blockStack.Pop();
                return(true);
            }
Ejemplo n.º 4
0
 public static void ReturnObjectCheck(IFortranBlock block, string linesString, Action <IEnumerable <IFortranObject> > makeAssertions)
 {
     ReturnObjectCheck(block, linesString, new List <IContained>(), makeAssertions);
 }
Ejemplo n.º 5
0
        public static void BlockStartCheck(IFortranBlock block, IEnumerable <IFortranBlock> ancestors, string linesString)
        {
            var lines = StringUtils.ConvertToFileLineList(linesString);

            Assert.IsTrue(block.BlockStart(ancestors, lines, 0));
        }