Esempio n. 1
0
		void ReadMultiLineComment(Comment.Type commentType, bool isNestingComment)
		{
			int nestedCommentDepth = 1;
			int nextChar;
			CodeLocation st = new CodeLocation(Col - ((commentType & Comment.Type.Documentation) != 0 ? 3 : 2), Line);
			StringBuilder scCurWord = new StringBuilder(); // current word, (scTag == null) or comment (when scTag != null)
			bool hadLineEnd = false;

			while ((nextChar = ReaderRead()) != -1)
			{

				char ch = (char)nextChar;

				// Catch deeper-nesting comments
				if (isNestingComment && ch == '/' && ReaderPeek() == '+')
				{
					nestedCommentDepth++;
					ReaderRead();
				}

				// End of multiline comment reached ?
				if ((isNestingComment ? ch == '+' : ch == '*') && ReaderPeek() == '/')
				{
					ReaderRead(); // Skip "*" or "+"

					if (nestedCommentDepth > 1)
						nestedCommentDepth--;
					else
					{
						if (commentType.HasFlag(Comment.Type.Documentation) || !OnlyEnlistDDocComments)
							Comments.Add(new Comment(commentType, scCurWord.ToString().Trim(ch, ' ', '\t', '\r', '\n', isNestingComment ? '+' : '*'), st.Column < 2, st, new CodeLocation(Col, Line)));
						return;
					}
				}

				if (HandleLineEnd(ch))
				{
					scCurWord.AppendLine();
					hadLineEnd = true;
				}

				// Skip intial white spaces, leading + as well as *
				else if (hadLineEnd)
				{
					if (char.IsWhiteSpace(ch) || (isNestingComment ? ch == '+' : ch == '*'))
					{ }
					else
					{
						scCurWord.Append(ch);
						hadLineEnd = false;
					}
				}
				else
					scCurWord.Append(ch);
			}

			// Reached EOF before end of multiline comment.
			if (commentType.HasFlag(Comment.Type.Documentation) || !OnlyEnlistDDocComments)
				Comments.Add(new Comment(commentType, scCurWord.ToString().Trim(), st.Column < 2, st, new CodeLocation(Col, Line)));

			OnError(Line, Col, String.Format("Reached EOF before the end of a multiline comment"));
		}
Esempio n. 2
0
		void ReadSingleLineComment(Comment.Type commentType)
		{
			int tagLen = ((commentType & Comment.Type.Documentation) != 0 ? 3 : 2);
			var st = new CodeLocation(Col - tagLen, Line);
			string comm = ReadToEndOfLine();
			var end = new CodeLocation(st.Column + tagLen + comm.Length, Line);

			if ((commentType &Comment.Type.Documentation) != 0 || !OnlyEnlistDDocComments)
				Comments.Add(new Comment(commentType, comm.TrimStart('/',' ','\t'), st.Column < 2, st, end));
		}