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; |
| 19 | bool BriefDone = false; |
| 20 | |
| 21 | while (Tok.isNot(tok::eof)) { |
| 22 | if (Tok.is(tok::text)) { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame^] | 23 | if (InFirstParagraph || InBrief) |
| 24 | Paragraph += Tok.getText(); |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 25 | ConsumeToken(); |
| 26 | continue; |
| 27 | } |
| 28 | |
| 29 | if (!BriefDone && Tok.is(tok::command) && Tok.getCommandName() == "brief") { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame^] | 30 | Paragraph.clear(); |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 31 | InBrief = true; |
| 32 | ConsumeToken(); |
| 33 | continue; |
| 34 | } |
| 35 | |
| 36 | if (Tok.is(tok::newline)) { |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame^] | 37 | if (InFirstParagraph || InBrief) |
| 38 | Paragraph += '\n'; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 39 | ConsumeToken(); |
| 40 | |
| 41 | if (Tok.is(tok::newline)) { |
| 42 | ConsumeToken(); |
| 43 | // We found a paragraph end. |
| 44 | InFirstParagraph = false; |
| 45 | if (InBrief) { |
| 46 | InBrief = false; |
| 47 | BriefDone = true; |
| 48 | } |
| 49 | } |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | // We didn't handle this token, so just drop it. |
| 54 | ConsumeToken(); |
| 55 | } |
| 56 | |
Dmitri Gribenko | c0b8324 | 2012-06-27 01:17:34 +0000 | [diff] [blame^] | 57 | return Paragraph; |
Dmitri Gribenko | 2d44d77 | 2012-06-26 20:39:18 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | BriefParser::BriefParser(Lexer &L) : L(L) |
| 61 | { |
| 62 | // Get lookahead token. |
| 63 | ConsumeToken(); |
| 64 | } |
| 65 | |
| 66 | } // end namespace comments |
| 67 | } // end namespace clang |
| 68 | |
| 69 | |