Esempio n. 1
0
        /// <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>
        /// Retrieve the next interchange chunk from the processor and parse it as an initializer.
        /// </summary>
        /// <param name="processor">Interchange format processor that can provide the interchange chunk for parsing.</param>
        /// <param name="sourceCodeService"></param>
        /// <remarks>
        /// The parser used here is capable of parsing interchange chunks containing initializers that follow the
        /// interchange version standard that this version service is supporting.
        /// </remarks>
        /// <returns>InitializerNode representing the parsed initializer source.</returns>
        protected internal virtual InitializerNode ParseInitializer(InterchangeFormatProcessor processor, out ISourceCodeReferenceService sourceCodeService)
        {
            InterchangeChunk chunk = this.GetNextChunk(processor);

            sourceCodeService = chunk;
            if (chunk == null)
            {
                // Must have an interchange element that contains <initializer definition>.
                this.ReportError(processor, "Expected initializer definition.");
                return(null);
            }
            Parser parser = this.GetFunctionParser();

            parser.ErrorSink = chunk;
            return(parser.ParseInitializer(new StringReader(chunk.SourceChunk)));
        }
        /// <summary>
        /// Process the interchange elements (chunks) provided by the given interchange format processor.
        /// </summary>
        /// <param name="processor">Interchange format processor that can provide interchange chunks for processing.</param>
        protected internal virtual void ProcessInterchangeElements(InterchangeFormatProcessor processor)
        {
            InterchangeChunk chunk = this.GetNextChunk(processor);

            if (chunk == null)
            {
                // Must have at least ONE interchange unit.
                this.ReportError(processor, InterchangeFormatErrors.ExpectedInterchangeUnit);
                return;
            }
            InterchangeUnitNode node = null;

            while (chunk != null)
            {
                node  = this.ProcessInterchangeElement(processor, node, chunk);
                chunk = this.GetNextChunk(processor);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Process the interchange file. The FileInProcessor will be notified for each read element.
        /// </summary>
        public void ProcessInterchangeFile()
        {
            InterchangeChunk chunk = this.GetNextChunk();

            if (chunk == null)
            {
                return; // Empty file
            }
            // All interchange files start with a version identifier.
            if (!this.ProcessVersionSpecification(chunk))
            {
                return; // Cannot process this version
            }
            // ProcessVersionSpecification() should have ensured this is set correctly or aborted, but we check anyway.
            if (this.VersionService != null)
            {
                this.VersionService.ProcessInterchangeElements(this);
            }
        }
        /// <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));
        }