blob: 2f67602b74f09fa6f8bc6d2494977df44dcf3994 [file] [log] [blame]
Dmitri Gribenko2d44d772012-06-26 20:39:18 +00001//===--- 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
12namespace clang {
13namespace comments {
14
15std::string BriefParser::Parse() {
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000016 std::string Paragraph;
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000017 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 Gribenkoc0b83242012-06-27 01:17:34 +000023 if (InFirstParagraph || InBrief)
24 Paragraph += Tok.getText();
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000025 ConsumeToken();
26 continue;
27 }
28
29 if (!BriefDone && Tok.is(tok::command) && Tok.getCommandName() == "brief") {
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000030 Paragraph.clear();
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000031 InBrief = true;
32 ConsumeToken();
33 continue;
34 }
35
36 if (Tok.is(tok::newline)) {
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000037 if (InFirstParagraph || InBrief)
38 Paragraph += '\n';
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000039 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 Gribenkoc0b83242012-06-27 01:17:34 +000057 return Paragraph;
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000058}
59
60BriefParser::BriefParser(Lexer &L) : L(L)
61{
62 // Get lookahead token.
63 ConsumeToken();
64}
65
66} // end namespace comments
67} // end namespace clang
68
69