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); }
public static void BlockEndCheck(IFortranBlock block, IEnumerable <IFortranBlock> ancestors, string linesString) { var lines = StringUtils.ConvertToFileLineList(linesString); Assert.IsTrue(block.BlockEnd(ancestors, lines, lines.Count - 1)); }