// Process a token. and add to the list of triva/tokens we're accumulating.
        public void AddToken(SyntaxToken token, bool isFirst, bool isLast)
        {
            bool isMissing = token.IsMissing;

            if (token.HasLeadingTrivia && (isFirst || isMissing || token.GetLeadingTrivia().TriviaListContainsStructuredTrivia()))
            {
                FinishInProgressTokens();
                AddTrivia(token.GetLeadingTrivia());
                token = ((SyntaxToken)token.WithLeadingTrivia(null));
            }

            ////if (!preserveExistingDiagnostics)
            ////{
            ////    token = token.WithoutDiagnostics();
            ////}

            SyntaxNode trailingTrivia = null;

            if (token.HasTrailingTrivia && (isLast || isMissing || token.GetTrailingTrivia().TriviaListContainsStructuredTrivia()))
            {
                trailingTrivia = token.GetTrailingTrivia();
                token          = ((SyntaxToken)token.WithTrailingTrivia(null));
            }

            if (isMissing)
            {
                // Don't add missing tokens to skipped tokens, but preserve their diagnostics.
                ////if (token.ContainsDiagnostics())
                ////{
                ////    // Move diagnostics on missing token to next token.
                ////    if (diagnosticsToAdd != null)
                ////    {
                ////        diagnosticsToAdd = diagnosticsToAdd.Concat(token.GetDiagnostics());
                ////    }
                ////    else
                ////    {
                ////        diagnosticsToAdd = token.GetDiagnostics();
                ////    }

                ////    addDiagnosticsToFirstTokenOnly = true;
                ////}
            }
            else
            {
                skippedTokensBuilder.Add(token);
            }

            if (trailingTrivia != null)
            {
                FinishInProgressTokens();
                AddTrivia(trailingTrivia);
            }

            if (isFirst && addDiagnosticsToFirstTokenOnly)
            {
                FinishInProgressTokens(); // implicitly adds the diagnostics.
            }
        }
        // Create a SkippedTokens trivia from any tokens currently accumulated into the skippedTokensBuilder. If not,
        // don't do anything.
        private void FinishInProgressTokens()
        {
            if (skippedTokensBuilder.Count > 0)
            {
                var skippedTokensTrivia = SyntaxFactory.SkippedTokensTrivia(skippedTokensBuilder.ToList());
                if (diagnosticsToAdd != null)
                {
                    foreach (var d in diagnosticsToAdd)
                    {
                        ////skippedTokensTrivia = skippedTokensTrivia.AddError(d);
                    }

                    diagnosticsToAdd = null; // only add once.
                }

                triviaListBuilder.Add(skippedTokensTrivia);
                skippedTokensBuilder.Clear();
            }
        }
Esempio n. 3
0
 public SyntaxListBuilder <TNode> Add(TNode node)
 {
     _builder.Add(node);
     return(this);
 }
Esempio n. 4
0
 internal override void CollectConstituentTokensAndDiagnostics(SyntaxListBuilder <SyntaxToken> tokenListBuilder, IList <DiagnosticInfo> nonTokenDiagnostics)
 {
     tokenListBuilder.Add(this);
 }
Esempio n. 5
0
 public void Add(XmlNodeSyntax xml)
 {
     _content.Add(xml);
 }