public void Parse <T>(IResultParser <T> parser, T reader) where T : IReader { long offset = reader.Position; IResultNodeBuilder resultNodeBuilder = _createResultNodeBuilder(); IResultNodeState resultState = _createResultNodeReaderState(this, resultNodeBuilder); IState previousState = _activeState.ChangeState(resultState); try { parser.Parse(reader, resultState); } finally { _activeState.ChangeState(previousState); } if (Valid && (reader.Position > offset)) { resultNodeBuilder.DataPacket = reader.GetDataPacket(offset, (reader.Position - offset)); resultNodeBuilder.Metadata = _resultMetadata; if (!resultState.Valid) { resultNodeBuilder.Invalidate(); } _resultNodeCallback.AddNode(_rootResultNode, resultNodeBuilder.Build(), resultState); } }
public void Parse <TReader>(IAttributeParser <TReader> parser, TReader reader) where TReader : IReader { IResultAttributeBuilder attributeBuilder = _createAttributeBuilder(); IAttributeState attributeState = _createAttributeState(this, attributeBuilder); IState previousState = _activeState.ChangeState(attributeState); try { parser.Parse(reader, attributeState); } finally { _activeState.ChangeState(previousState); } // TODO: 'Name' must be set on 'attributeBuilder' !! if (!attributeState.Valid) { attributeBuilder.Invalidate(); } _resultBuilder.AddAttribute(attributeBuilder.Build()); }
public ReaderState(IActiveState activeState, IResultNodeCallback resultNodeCallback, IResultNode rootResultNode, IResultMetadata resultMetadata, IScanContext scanContext, Creator <IResultNodeBuilder> createResultNodeBuilder, Creator <IResultNodeState, IState, IResultNodeBuilder> createResultNodeReaderState) { _activeState = activeState; _resultNodeCallback = resultNodeCallback; _rootResultNode = rootResultNode; _resultMetadata = resultMetadata; _scanContext = scanContext; _createResultNodeBuilder = createResultNodeBuilder; _createResultNodeReaderState = createResultNodeReaderState; _scanContext.Results = rootResultNode; Valid = true; _activeState.ChangeState(this); }