CommentBriefParser.cpp revision 2d44d77fed3200e2eff289f55493317e90d3398c
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
12namespace clang {
13namespace comments {
14
15std::string BriefParser::Parse() {
16  std::string FirstParagraph;
17  std::string Brief;
18  bool InFirstParagraph = true;
19  bool InBrief = false;
20  bool BriefDone = false;
21
22  while (Tok.isNot(tok::eof)) {
23    if (Tok.is(tok::text)) {
24      if (InFirstParagraph)
25        FirstParagraph += Tok.getText();
26      if (InBrief)
27        Brief += Tok.getText();
28      ConsumeToken();
29      continue;
30    }
31
32    if (!BriefDone && Tok.is(tok::command) && Tok.getCommandName() == "brief") {
33      InBrief = true;
34      ConsumeToken();
35      continue;
36    }
37
38    if (Tok.is(tok::newline)) {
39      if (InFirstParagraph)
40        FirstParagraph += '\n';
41      if (InBrief)
42        Brief += '\n';
43      ConsumeToken();
44
45      if (Tok.is(tok::newline)) {
46        ConsumeToken();
47        // We found a paragraph end.
48        InFirstParagraph = false;
49        if (InBrief) {
50          InBrief = false;
51          BriefDone = true;
52        }
53      }
54      continue;
55    }
56
57    // We didn't handle this token, so just drop it.
58    ConsumeToken();
59  }
60
61  if (Brief.size() > 0)
62    return Brief;
63
64  return FirstParagraph;
65}
66
67BriefParser::BriefParser(Lexer &L) : L(L)
68{
69  // Get lookahead token.
70  ConsumeToken();
71}
72
73} // end namespace comments
74} // end namespace clang
75
76
77