summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/CommentBriefParser.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-06-26 20:39:18 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-06-26 20:39:18 +0000
commit5188c4b9cc063b1be5fbb4688711f91b7cadd62f (patch)
tree432598630731554a67aef1a0a821c83bdaf122b6 /clang/lib/AST/CommentBriefParser.cpp
parentadd5e9e289b0e0f5e46617219f076c39fecff2a3 (diff)
downloadbcm5719-llvm-5188c4b9cc063b1be5fbb4688711f91b7cadd62f.tar.gz
bcm5719-llvm-5188c4b9cc063b1be5fbb4688711f91b7cadd62f.zip
Implement a lexer for structured comments.
llvm-svn: 159223
Diffstat (limited to 'clang/lib/AST/CommentBriefParser.cpp')
-rw-r--r--clang/lib/AST/CommentBriefParser.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/clang/lib/AST/CommentBriefParser.cpp b/clang/lib/AST/CommentBriefParser.cpp
new file mode 100644
index 00000000000..528fd2606fe
--- /dev/null
+++ b/clang/lib/AST/CommentBriefParser.cpp
@@ -0,0 +1,76 @@
+//===--- CommentBriefParser.cpp - Dumb comment parser ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/CommentBriefParser.h"
+
+namespace clang {
+namespace comments {
+
+std::string BriefParser::Parse() {
+ std::string FirstParagraph;
+ std::string Brief;
+ bool InFirstParagraph = true;
+ bool InBrief = false;
+ bool BriefDone = false;
+
+ while (Tok.isNot(tok::eof)) {
+ if (Tok.is(tok::text)) {
+ if (InFirstParagraph)
+ FirstParagraph += Tok.getText();
+ if (InBrief)
+ Brief += Tok.getText();
+ ConsumeToken();
+ continue;
+ }
+
+ if (!BriefDone && Tok.is(tok::command) && Tok.getCommandName() == "brief") {
+ InBrief = true;
+ ConsumeToken();
+ continue;
+ }
+
+ if (Tok.is(tok::newline)) {
+ if (InFirstParagraph)
+ FirstParagraph += '\n';
+ if (InBrief)
+ Brief += '\n';
+ ConsumeToken();
+
+ if (Tok.is(tok::newline)) {
+ ConsumeToken();
+ // We found a paragraph end.
+ InFirstParagraph = false;
+ if (InBrief) {
+ InBrief = false;
+ BriefDone = true;
+ }
+ }
+ continue;
+ }
+
+ // We didn't handle this token, so just drop it.
+ ConsumeToken();
+ }
+
+ if (Brief.size() > 0)
+ return Brief;
+
+ return FirstParagraph;
+}
+
+BriefParser::BriefParser(Lexer &L) : L(L)
+{
+ // Get lookahead token.
+ ConsumeToken();
+}
+
+} // end namespace comments
+} // end namespace clang
+
+
OpenPOWER on IntegriCloud