Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 1 | //===--- CommentBriefParser.cpp - Dumb comment parser ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/AST/CommentBriefParser.h" |
| 11 | |
| 12 | namespace clang { |
| 13 | namespace comments { |
| 14 | |
| 15 | std::string BriefParser::Parse() { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame] | 16 | std::string Paragraph; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 17 | bool InFirstParagraph = true; |
| 18 | bool InBrief = false; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 19 | |
| 20 | while (Tok.isNot(tok::eof)) { |
| 21 | if (Tok.is(tok::text)) { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame] | 22 | if (InFirstParagraph || InBrief) |
| 23 | Paragraph += Tok.getText(); |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 24 | ConsumeToken(); |
| 25 | continue; |
| 26 | } |
| 27 | |
Dmitri Gribenko | f199b9c | 2012-06-28 00:01:41 +0000 | [diff] [blame] | 28 | if (Tok.is(tok::command)) { |
| 29 | StringRef Name = Tok.getCommandName(); |
| 30 | if (Name == "brief") { |
| 31 | Paragraph.clear(); |
| 32 | InBrief = true; |
| 33 | ConsumeToken(); |
| 34 | continue; |
| 35 | } |
| 36 | // Check if this command implicitly starts a new paragraph. |
| 37 | if (Name == "param" || Name == "result" || Name == "return" || |
| 38 | Name == "returns") { |
| 39 | // We found an implicit paragraph end. |
| 40 | InFirstParagraph = false; |
| 41 | if (InBrief) { |
| 42 | InBrief = false; |
| 43 | break; |
| 44 | } |
| 45 | } |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | if (Tok.is(tok::newline)) { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame] | 49 | if (InFirstParagraph || InBrief) |
| 50 | Paragraph += '\n'; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 51 | ConsumeToken(); |
| 52 | |
| 53 | if (Tok.is(tok::newline)) { |
| 54 | ConsumeToken(); |
| 55 | // We found a paragraph end. |
| 56 | InFirstParagraph = false; |
| 57 | if (InBrief) { |
| 58 | InBrief = false; |
Dmitri Gribenko | f199b9c | 2012-06-28 00:01:41 +0000 | [diff] [blame] | 59 | break; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | continue; |
| 63 | } |
| 64 | |
| 65 | // We didn't handle this token, so just drop it. |
| 66 | ConsumeToken(); |
| 67 | } |
| 68 | |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame] | 69 | return Paragraph; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | BriefParser::BriefParser(Lexer &L) : L(L) |
| 73 | { |
| 74 | // Get lookahead token. |
| 75 | ConsumeToken(); |
| 76 | } |
| 77 | |
| 78 | } // end namespace comments |
| 79 | } // end namespace clang |
| 80 | |
| 81 | |