private BranchedLexer(BranchedLexer parent) { _branches = parent._branches; _branches.Add(this); _buffer = new Queue <Token>(parent._buffer); _lexer = parent._lexer; }
/// <summary> /// Merges the lexer to the state of another specified branch. /// </summary> /// <param name="branch">The specified branch.</param> /// <exception cref="ObjectDisposedException">Methods were called after the object was disposed.</exception> /// <exception cref="InvalidOperationException">The lexer has a different root with the specified branch.</exception> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public void Merge(BranchedLexer branch) { if (branch == null) { throw new ArgumentNullException(); } if (HasSameRoot(branch)) { _buffer = new Queue <Token>(branch._buffer); } else { throw new InvalidOperationException(ExceptionResource.DifferentRoot); } }
/// <summary> /// Returns a value indicating whether the lexer has the same root reader as another specified branch. /// </summary> /// <param name="branch">The specified branch.</param> /// <returns><see langword="true"/> if the lexer has the same root reader as <paramref name="branch"/>; otherwise <see langword="false"/>.</returns> /// <exception cref="ObjectDisposedException">Methods were called after the object was disposed.</exception> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public bool HasSameRoot(BranchedLexer branch) { if (branch == null) { throw new ArgumentNullException(); } if (!_branches.Contains(this)) { throw new ObjectDisposedException(ToString()); } else if (!_branches.Contains(branch)) { throw new ObjectDisposedException(branch.ToString()); } return(this._lexer.Equals(branch._lexer)); }