Esempio n. 1
0
        /// <summary>
        /// Sets the current iterator position to a previous position returned by GetCurrentPosition.
        /// After a call to this method, GetNextToken returns the token FOLLOWING the current position.
        /// </summary>
        public void SeekToPosition(object iteratorPosition)
        {
            // Restore iterators positions
            currentPosition = (CopyTokensLinesIteratorPosition)iteratorPosition;
            if (currentPosition.ImportedDocumentIterator != null)
            {
                currentPosition.ImportedDocumentIterator.SeekToPosition(currentPosition.ImportedDocumentIteratorPosition);
            }

            // Restore current line & current token
            if (currentPosition.LineIndex >= 0)
            {
                currentLine = tokensLines[currentPosition.LineIndex];
            }
            else
            {
                currentLine = null;
            }
            if (currentPosition.TokenIndexInLine >= 0 && currentLine != null)
            {
                currentTokenInMainDocument = currentLine.TokensWithCompilerDirectives[currentPosition.TokenIndexInLine];
            }
            else
            {
                currentTokenInMainDocument = null;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Resets the iterator position : before the first token of the document
 /// </summary>
 public void Reset()
 {
     currentPosition.LineIndex        = 0;
     currentPosition.TokenIndexInLine = -1;
     if (tokensLines.Count > 0)
     {
         currentLine = tokensLines[0];
     }
     else
     {
         currentLine = null;
     }
     currentTokenInMainDocument = null;
 }
Esempio n. 3
0
        private static string BuildResultString(IProcessedTokensLine line)
        {
            StringBuilder tokensText = new StringBuilder();

            foreach (Token token in line.TokensWithCompilerDirectives)
            {
                tokensText.AppendLine(token.ToString());
            }

            StringBuilder diagnosticsText = new StringBuilder();

            if (line.PreprocessorDiagnostics != null)
            {
                foreach (Diagnostic diagnostic in line.PreprocessorDiagnostics)
                {
                    if (diagnostic.Info.Code != (int)MessageCode.FailedToLoadTextDocumentReferencedByCopyDirective)
                    {
                        diagnosticsText.AppendLine(diagnostic.ToString());
                    }
                }
            }

            return(tokensText.ToString() + diagnosticsText.ToString());
        }
        /// <summary>
        /// Sets the current iterator position to a previous position returned by GetCurrentPosition.
        /// After a call to this method, GetNextToken returns the token FOLLOWING the current position.
        /// </summary>
        public void SeekToPosition(object iteratorPosition)
        {
            // Restore iterators positions
            currentPosition = (CopyTokensLinesIteratorPosition)iteratorPosition;
            if(currentPosition.ImportedDocumentIterator != null)
            {
                currentPosition.ImportedDocumentIterator.SeekToPosition(currentPosition.ImportedDocumentIteratorPosition);
            }

            // Restore current line & current token
            if (currentPosition.LineIndex >= 0)
            {
                currentLine = tokensLines[currentPosition.LineIndex];
            }
            else
            {
                currentLine = null;
            }
            if (currentPosition.TokenIndexInLine >= 0 && currentLine != null)
            {
                currentTokenInMainDocument = currentLine.TokensWithCompilerDirectives[currentPosition.TokenIndexInLine];
            }
            else
            {
                currentTokenInMainDocument = null;
            }
        }
 /// <summary>
 /// Resets the iterator position : before the first token of the document
 /// </summary>
 public void Reset()
 {
     currentPosition.LineIndex = 0;
     currentPosition.TokenIndexInLine = -1;
     if (tokensLines.Count > 0)
     {
         currentLine = tokensLines[0];
     }
     else
     {
         currentLine = null;
     }
     currentTokenInMainDocument = null;
 }
        /// <summary>
        /// Get next token or EndOfFile
        /// </summary>
        public Token NextToken()
        {
            // If the document is empty or after end of file, immediately return EndOfFile
            if (currentLine == null)
            {
                currentPosition.CurrentToken = Token.END_OF_FILE;
                return Token.END_OF_FILE;
            }

            // If the iterator is positioned in an imported document, return the next imported token
            if(currentPosition.ImportedDocumentIterator != null)
            {
                Token nextImportedToken = currentPosition.ImportedDocumentIterator.NextToken();
                if(nextImportedToken == Token.END_OF_FILE)
                {
                    currentPosition.ImportedDocumentIterator = null;
                    currentPosition.ImportedDocumentIteratorPosition = null;
                }
                else
                {
                    currentPosition.CurrentToken = nextImportedToken;
                    //#235
                    var copyDirective = (CopyDirective)((CompilerDirectiveToken)currentTokenInMainDocument).CompilerDirective;
                    return new ImportedToken(nextImportedToken, copyDirective);
                }
            }

            // While we can find a next token
            currentTokenInMainDocument = null;
            while (currentTokenInMainDocument == null)
            {
                // try to find the next token on the same line
                currentPosition.TokenIndexInLine++;
                // but if we reached the end of the current line ...
                while (currentPosition.TokenIndexInLine >= currentLine.TokensWithCompilerDirectives.Count)
                {
                    // .. advance to next line
                    currentPosition.LineIndex++;
                    currentPosition.TokenIndexInLine = 0;
                    if (currentPosition.LineIndex < tokensLines.Count)
                    {
                        currentLine = tokensLines[currentPosition.LineIndex];
                    }
                    // and if we reached the last line of the document ...
                    else
                    {
                        // return EndOfFile
                        currentLine = null;
                        currentPosition.CurrentToken = Token.END_OF_FILE;
                        return Token.END_OF_FILE;
                    }
                }
                // Check if the next token found matches the filter criteria or is a COPY compiler directive or is a REPLACE directive
                Token nextTokenCandidate = currentLine.TokensWithCompilerDirectives[currentPosition.TokenIndexInLine];
                if (nextTokenCandidate.Channel == channelFilter || nextTokenCandidate.TokenType == TokenType.CopyImportDirective || nextTokenCandidate.TokenType == TokenType.ReplaceDirective)
                {
                    currentTokenInMainDocument = nextTokenCandidate;
                }
            }

            // Check if the next token is a COPY import compiler directive
            if (currentTokenInMainDocument.TokenType == TokenType.CopyImportDirective)
            {
                // Get next token in the imported document
                var compilerDirective = (CopyDirective)((CompilerDirectiveToken)currentTokenInMainDocument).CompilerDirective;
                ImportedTokensDocument importedDocument = currentLine.ImportedDocuments[compilerDirective];
                if (importedDocument != null)
                {
                    ITokensLinesIterator importedDocumentIterator = importedDocument.GetProcessedTokensIterator();
                    Token nextTokenCandidate = importedDocumentIterator.NextToken();

                    // No suitable next token found in the imported document
                    // -> get next token in the main document
                    if (nextTokenCandidate == Token.END_OF_FILE)
                    {
                        return NextToken();
                    }
                    // Start iterating in the imported document
                    else
                    {
                        currentPosition.ImportedDocumentIterator = importedDocumentIterator;
                        currentPosition.CurrentToken = nextTokenCandidate;
                        //#235
                        return new ImportedToken(nextTokenCandidate, compilerDirective);
                    }
                }
                // The reference to the ImportedDocument could not be resolved (error in an earlier phase)
                // -> get next token in the main document (fallback)
                else
                {
                    return NextToken();
                }
            }
            else
            {
                currentPosition.CurrentToken = currentTokenInMainDocument;
                return currentTokenInMainDocument;
            }
        }
Esempio n. 7
0
        private static string BuildResultString(IProcessedTokensLine line)
        {
            StringBuilder tokensText = new StringBuilder();
            foreach (Token token in line.TokensWithCompilerDirectives)
            {
                tokensText.AppendLine(token.ToString());
            }

            StringBuilder diagnosticsText = new StringBuilder();
            if (line.PreprocessorDiagnostics != null)
            {
                foreach (Diagnostic diagnostic in line.PreprocessorDiagnostics)
                {
                    if (diagnostic.Info.Code != (int)MessageCode.FailedToLoadTextDocumentReferencedByCopyDirective)
                    {
                        diagnosticsText.AppendLine(diagnostic.ToString());
                    }
                }
            }

            return tokensText.ToString() + diagnosticsText.ToString();
        }
Esempio n. 8
0
        /// <summary>
        /// Get next token or EndOfFile
        /// </summary>
        public Token NextToken()
        {
            // If the document is empty or after end of file, immediately return EndOfFile
            if (currentLine == null)
            {
                currentPosition.CurrentToken = Token.END_OF_FILE;
                return(Token.END_OF_FILE);
            }

            // If the iterator is positioned in an imported document, return the next imported token
            if (currentPosition.ImportedDocumentIterator != null)
            {
                Token nextImportedToken = currentPosition.ImportedDocumentIterator.NextToken();
                if (nextImportedToken == Token.END_OF_FILE)
                {
                    currentPosition.ImportedDocumentIterator         = null;
                    currentPosition.ImportedDocumentIteratorPosition = null;
                }
                else
                {
                    currentPosition.CurrentToken = nextImportedToken;
                    //#235
                    var copyDirective = (CopyDirective)((CompilerDirectiveToken)currentTokenInMainDocument).CompilerDirective;
                    return(new ImportedToken(nextImportedToken, copyDirective));
                }
            }

            // While we can find a next token
            currentTokenInMainDocument = null;
            while (currentTokenInMainDocument == null)
            {
                // try to find the next token on the same line
                currentPosition.TokenIndexInLine++;
                // but if we reached the end of the current line ...
                while (currentPosition.TokenIndexInLine >= currentLine.TokensWithCompilerDirectives.Count)
                {
                    // .. advance to next line
                    currentPosition.LineIndex++;
                    currentPosition.TokenIndexInLine = 0;
                    if (currentPosition.LineIndex < tokensLines.Count)
                    {
                        currentLine = tokensLines[currentPosition.LineIndex];
                    }
                    // and if we reached the last line of the document ...
                    else
                    {
                        // return EndOfFile
                        currentLine = null;
                        currentPosition.CurrentToken = Token.END_OF_FILE;
                        return(Token.END_OF_FILE);
                    }
                }
                // Check if the next token found matches the filter criteria or is a COPY compiler directive or is a REPLACE directive
                Token nextTokenCandidate = currentLine.TokensWithCompilerDirectives[currentPosition.TokenIndexInLine];
                if (nextTokenCandidate.Channel == channelFilter || nextTokenCandidate.TokenType == TokenType.CopyImportDirective || nextTokenCandidate.TokenType == TokenType.ReplaceDirective)
                {
                    currentTokenInMainDocument = nextTokenCandidate;
                }
            }

            // Check if the next token is a COPY import compiler directive
            if (currentTokenInMainDocument.TokenType == TokenType.CopyImportDirective)
            {
                // Get next token in the imported document
                var compilerDirective = (CopyDirective)((CompilerDirectiveToken)currentTokenInMainDocument).CompilerDirective;
                ImportedTokensDocument importedDocument = currentLine.ImportedDocuments[compilerDirective];
                if (importedDocument != null)
                {
                    ITokensLinesIterator importedDocumentIterator = importedDocument.GetProcessedTokensIterator();
                    Token nextTokenCandidate = importedDocumentIterator.NextToken();

                    // No suitable next token found in the imported document
                    // -> get next token in the main document
                    if (nextTokenCandidate == Token.END_OF_FILE)
                    {
                        return(NextToken());
                    }
                    // Start iterating in the imported document
                    else
                    {
                        currentPosition.ImportedDocumentIterator = importedDocumentIterator;
                        currentPosition.CurrentToken             = nextTokenCandidate;
                        //#235
                        return(new ImportedToken(nextTokenCandidate, compilerDirective));
                    }
                }
                // The reference to the ImportedDocument could not be resolved (error in an earlier phase)
                // -> get next token in the main document (fallback)
                else
                {
                    return(NextToken());
                }
            }
            else
            {
                currentPosition.CurrentToken = currentTokenInMainDocument;
                return(currentTokenInMainDocument);
            }
        }