private static List <Trivia> ConsumeTrivia(TrackableTextReader stream) { List <Trivia> triviaList = new List <Trivia>(); bool isTrivia = false; char next; do { next = stream.Peek(); switch (next) { case ' ': case '\t': isTrivia = true; triviaList.Add(CollectWhitespace(stream)); break; case '\n': isTrivia = true; Trivia newLineTrivia = new Trivia(SyntaxKind.Newline, stream.ReadChar().ToString()); triviaList.Add(newLineTrivia); break; case '\r': isTrivia = true; stream.ReadChar(); next = stream.Peek(); Trivia returnTrivia; if (next == '\n') { stream.ReadChar(); returnTrivia = new Trivia(SyntaxKind.Newline, "\r\n"); } else { returnTrivia = new Trivia(SyntaxKind.Newline, "\r"); } triviaList.Add(returnTrivia); break; case '-': stream.ReadChar(); if (stream.Peek() == '-') { isTrivia = true; stream.ReadChar(); string commentSoFar = ""; int?level = Lexer.GetLongCommentOpenBracket(stream, ref commentSoFar); if (level != null) { triviaList.Add(ReadLongComment(stream, "--" + commentSoFar, level)); } else { triviaList.Add(ReadLineComment(stream, new char[] { '-', '-' })); } } else { isTrivia = false; stream.Pushback(); } break; default: isTrivia = false; break; } } while (isTrivia); return(triviaList); }
private static List<Trivia> ConsumeTrivia(TrackableTextReader stream) { List<Trivia> triviaList = new List<Trivia>(); bool isTrivia = false; char next; do { next = stream.Peek(); switch (next) { case ' ': case '\t': isTrivia = true; triviaList.Add(CollectWhitespace(stream)); break; case '\n': isTrivia = true; Trivia newLineTrivia = new Trivia(SyntaxKind.Newline, stream.ReadChar().ToString()); triviaList.Add(newLineTrivia); break; case '\r': isTrivia = true; stream.ReadChar(); next = stream.Peek(); Trivia returnTrivia; if (next == '\n') { stream.ReadChar(); returnTrivia = new Trivia(SyntaxKind.Newline, "\r\n"); } else { returnTrivia = new Trivia(SyntaxKind.Newline, "\r"); } triviaList.Add(returnTrivia); break; case '-': stream.ReadChar(); if (stream.Peek() == '-') { isTrivia = true; stream.ReadChar(); string commentSoFar = ""; int? level = Lexer.GetLongCommentOpenBracket(stream, ref commentSoFar); if (level != null) { triviaList.Add(ReadLongComment(stream, "--" + commentSoFar, level)); } else { triviaList.Add(ReadLineComment(stream, new char[] { '-', '-' })); } } else { isTrivia = false; stream.Pushback(); } break; default: isTrivia = false; break; } } while (isTrivia); return triviaList; }