/// <summary> /// Process the interchange version identifier of the interchange file. /// Set internal state based on the version identifier. /// </summary> /// <param name="chunk">Chunk of source code that is supposed to contain the version identifier.</param> /// <returns></returns> private bool ProcessVersionSpecification(InterchangeChunk chunk) { InterchangeFormatParser parser = parser = new InterchangeFormatParser(new StringReader(chunk.SourceChunk)); parser.ErrorSink = chunk; InterchangeVersionIdentifierNode vidNode = parser.ParseVersionId(); // Parser always returns a node. if (vidNode.VersionId != null) { this.Version = vidNode.VersionId.Value; } if ((vidNode.VersionId != null) && !this.SetVersionService()) { if (this.ErrorSink != null) { this.ErrorSink.AddInterchangeError( chunk.TranslateSourcePosition(vidNode.VersionId.StartPosition), chunk.TranslateSourcePosition(vidNode.VersionId.StopPosition), InterchangeFormatErrors.InvalidVersionId); } return(false); // Cannot process this version } return(true); }
/// <summary> /// Create and return a parser capable of parsing interchange nodes / interchange chunks. /// </summary> /// <remarks> /// The parser returned here is capable of parsing interchange chunks that follow the /// interchange version this version service is supporting. /// </remarks> /// <param name="sourceChunk">Interchange chunk to be parsed.</param> /// <returns>Interchange format parser.</returns> protected virtual InterchangeFormatParser GetInterchangeParser(InterchangeChunk sourceChunk) { if (sourceChunk == null) { throw new ArgumentNullException(); } InterchangeFormatParser parser = new InterchangeFormatParser(new StringReader(sourceChunk.SourceChunk)); parser.ErrorSink = sourceChunk; return(parser); }
/// <summary> /// Process a given interchange element (chunk). /// </summary> /// <param name="processor"></param> /// <param name="node">Last node that was parsed. This is used for annotations.</param> /// <param name="chunk">Interchange chunk to be processed.</param> /// <returns>Returns the new interchange parse node (or null in case of error).</returns> protected virtual InterchangeUnitNode ProcessInterchangeElement(InterchangeFormatProcessor processor, InterchangeUnitNode node, InterchangeChunk chunk) { InterchangeFormatParser parser = this.GetInterchangeParser(chunk); InterchangeElementNode nodeForAnnotation = (node == null) ? null : node.GetAnnotatedNode(); node = parser.ParseInterchangeElement(nodeForAnnotation); if (node == null) { return(null); } return(node.FileIn(processor, chunk, chunk)); }