예제 #1
0
        /*  <summary>
         * ''' Add all the tokens in this node and children to the build token list builder. While doing this, add any
         * ''' diagnostics not on tokens to the given diagnostic info list.
         * ''' </summary>
         */
        internal virtual void CollectConstituentTokensAndDiagnostics(SyntaxListBuilder <SyntaxToken> tokenListBuilder, IList <DiagnosticInfo> nonTokenDiagnostics)
        {
            DiagnosticInfo[] diagnostics = this.GetDiagnostics();
            if (diagnostics != null && diagnostics.Length > 0)
            {
                foreach (var diag in diagnostics)
                {
                    nonTokenDiagnostics.Add(diag);
                }
            }

            // Recurse to subtrees.
            for (var i = 0; i < SlotCount; i++)
            {
                var green = GetSlot(i);
                if (green != null)
                {
                    ((SyntaxNode)green).CollectConstituentTokensAndDiagnostics(tokenListBuilder, nonTokenDiagnostics);
                }
            }
        }
예제 #2
0
        internal static SyntaxList <SyntaxNode> GetStartOfTrivia(this SyntaxList <SyntaxNode> trivia, int indexOfEnd)
        {
            if (indexOfEnd == 0)
            {
                return(null);
            }
            else if (indexOfEnd == trivia.Count)
            {
                return(trivia);
            }
            else
            {
                var builder = SyntaxListBuilder <SyntaxNode> .Create();

                for (var i = 0; i < indexOfEnd; i++)
                {
                    builder.Add(trivia[i]);
                }

                return(builder.ToList());
            }
        }
예제 #3
0
        // From a syntax node, create a list of trivia node that encapsulates the same text. We use SkippedTokens trivia
        // to encapsulate the tokens, plus extract trivia from those tokens into the trivia list because:
        //    - We want leading trivia and trailing trivia to be directly visible in the trivia list, not on the tokens
        //      inside the skipped tokens trivia.
        //    - We have to expose structured trivia directives.
        //
        // Several options controls how diagnostics are handled:
        //   "preserveDiagnostics" means existing diagnostics are preserved, otherwise they are thrown away
        //   "addDiagnostic", if not Nothing, is added as a diagnostics
        //   "addDiagnosticsToFirstTokenOnly" means that "addDiagnostics" is attached only to the first token, otherwise
        //    it is attached to all tokens.
        private static SyntaxList <SyntaxNode> CreateSkippedTrivia(SyntaxNode node, bool preserveDiagnostics, bool addDiagnosticToFirstTokenOnly, DiagnosticInfo addDiagnostic)
        {
            if (node.Kind == SyntaxKind.SkippedTokensTrivia)
            {
                // already skipped trivia
                if (addDiagnostic != null)
                {
                    ////node = node.AddError(addDiagnostic); TODO
                }

                return(node);
            }

            IList <DiagnosticInfo> diagnostics = new List <DiagnosticInfo>();
            var tokenListBuilder = SyntaxListBuilder <SyntaxToken> .Create();

            node.CollectConstituentTokensAndDiagnostics(tokenListBuilder, diagnostics);
            // Adjust diagnostics based on input.
            if (!preserveDiagnostics)
            {
                diagnostics.Clear();
            }

            if (addDiagnostic != null)
            {
                diagnostics.Add(addDiagnostic);
            }

            var skippedTriviaBuilder = new SkippedTriviaBuilder(preserveDiagnostics, addDiagnosticToFirstTokenOnly, diagnostics);

            // Get through each token and add it.
            for (int i = 0; i < tokenListBuilder.Count; i++)
            {
                SyntaxToken currentToken = tokenListBuilder[i];
                skippedTriviaBuilder.AddToken(currentToken, isFirst: (i == 0), isLast: (i == tokenListBuilder.Count - 1));
            }

            return(skippedTriviaBuilder.GetTriviaList());
        }
예제 #4
0
 public SyntaxListBuilder(SyntaxListBuilder builder)
 {
     this.builder = builder;
 }
예제 #5
0
        private static SyntaxNode CreateNode(IEnumerable <TNode> nodes)
        {
            if (nodes == null)
            {
                return(null);
            }

            var collection = nodes as ICollection <TNode>;
            var builder    = (collection != null) ? new SyntaxListBuilder <TNode>(collection.Count) : SyntaxListBuilder <TNode> .Create();

            foreach (TNode node in nodes)
            {
                builder.Add(node);
            }

            return(builder.ToList().Node);
        }
예제 #6
0
 internal SyntaxListBuilder(SyntaxListBuilder builder)
 {
     _builder = builder;
 }
예제 #7
0
 internal override void CollectConstituentTokensAndDiagnostics(SyntaxListBuilder <SyntaxToken> tokenListBuilder, IList <DiagnosticInfo> nonTokenDiagnostics)
 {
     tokenListBuilder.Add(this);
 }
예제 #8
0
 public SeparatedSyntaxListBuilder(SyntaxListBuilder builder)
 {
     this.builder = builder;
 }
예제 #9
0
 public XmlContext(SyntaxListPool pool, XmlElementStartTagSyntax start)
 {
     _pool    = pool;
     _start   = start;
     _content = _pool.Allocate <XmlNodeSyntax>();
 }