blob: f6473092461539c7e70d96aad87950083b285386 [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;
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000019
20 while (Tok.isNot(tok::eof)) {
21 if (Tok.is(tok::text)) {
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000022 if (InFirstParagraph || InBrief)
23 Paragraph += Tok.getText();
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000024 ConsumeToken();
25 continue;
26 }
27
Dmitri Gribenkof199b9c2012-06-28 00:01:41 +000028 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 Gribenko2d44d772012-06-26 20:39:18 +000046 }
47
48 if (Tok.is(tok::newline)) {
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000049 if (InFirstParagraph || InBrief)
50 Paragraph += '\n';
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000051 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 Gribenkof199b9c2012-06-28 00:01:41 +000059 break;
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000060 }
61 }
62 continue;
63 }
64
65 // We didn't handle this token, so just drop it.
66 ConsumeToken();
67 }
68
Dmitri Gribenkoc0b83242012-06-27 01:17:34 +000069 return Paragraph;
Dmitri Gribenko2d44d772012-06-26 20:39:18 +000070}
71
72BriefParser::BriefParser(Lexer &L) : L(L)
73{
74 // Get lookahead token.
75 ConsumeToken();
76}
77
78} // end namespace comments
79} // end namespace clang
80
81