internal static XmlDocumentSyntax.Green XmlDocument( XmlDeclarationSyntax.Green prologue, SyntaxList <GreenNode> precedingMisc, XmlNodeSyntax.Green body, SyntaxList <GreenNode> followingMisc, SkippedTokensTriviaSyntax.Green skippedTokens, SyntaxToken.Green eof) { return(new XmlDocumentSyntax.Green(prologue, precedingMisc.Node, body, followingMisc.Node, skippedTokens, eof)); }
// 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 InternalSyntax.SyntaxList <GreenNode> CreateSkippedTrivia(GreenNode node, bool preserveDiagnostics, bool addDiagnosticToFirstTokenOnly, DiagnosticInfo addDiagnostic) { if (node.Kind == SyntaxKind.SkippedTokensTrivia) { // already skipped trivia if (addDiagnostic != null) { node = node.AddError(addDiagnostic); } return(node); } IList <DiagnosticInfo> diagnostics = new List <DiagnosticInfo>(); var tokenListBuilder = InternalSyntax.SyntaxListBuilder <SyntaxToken.Green> .Create(); CollectConstituentTokensAndDiagnostics(node, 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.Green currentToken = tokenListBuilder[i]; skippedTriviaBuilder.AddToken(currentToken, isFirst: (i == 0), isLast: (i == tokenListBuilder.Count - 1)); } return(skippedTriviaBuilder.GetTriviaList()); }
////public virtual SyntaxToken Visit(SyntaxToken token) ////{ //// return token; ////} ////public virtual GreenNode Visit(SyntaxList list) ////{ //// return list; ////} public virtual SyntaxToken.Green VisitSyntaxToken(SyntaxToken.Green token) { return(token); }
internal static bool IsMissingToken(SyntaxToken.Green token) { return(string.IsNullOrEmpty(token.Text)); }
internal static XmlDeclarationSyntax.Green XmlDeclaration(PunctuationSyntax.Green lessThanQuestionToken, SyntaxToken.Green xmlKeyword, XmlDeclarationOptionSyntax.Green version, XmlDeclarationOptionSyntax.Green encoding, XmlDeclarationOptionSyntax.Green standalone, PunctuationSyntax.Green questionGreaterThanToken) { return(new XmlDeclarationSyntax.Green(lessThanQuestionToken, xmlKeyword, version, encoding, standalone, questionGreaterThanToken)); }