using System; using System.Collections.Generic; using System.Linq; using System.Text; using OfficeOpenXml.FormulaParsing.ExcelUtilities; namespace OfficeOpenXml.FormulaParsing { /// /// This class implements a stack on which instances of /// are put. Each ParsingScope represents the parsing of an address in the workbook. /// public class ParsingScopes { private readonly IParsingLifetimeEventHandler _lifetimeEventHandler; public ParsingScopes(IParsingLifetimeEventHandler lifetimeEventHandler) { _lifetimeEventHandler = lifetimeEventHandler; } private Stack _scopes = new Stack(); /// /// Creates a new and puts it on top of the stack. /// /// /// public virtual ParsingScope NewScope(RangeAddress address) { ParsingScope scope; if (_scopes.Count() > 0) { scope = new ParsingScope(this, _scopes.Peek(), address); } else { scope = new ParsingScope(this, address); } _scopes.Push(scope); return scope; } /// /// The current parsing scope. /// public virtual ParsingScope Current { get { return _scopes.Count() > 0 ? _scopes.Peek() : null; } } /// /// Removes the current scope, setting the calling scope to current. /// /// public virtual void KillScope(ParsingScope parsingScope) { _scopes.Pop(); if (_scopes.Count() == 0) { _lifetimeEventHandler.ParsingCompleted(); } } } }