diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-26 20:39:18 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-26 20:39:18 +0000 |
commit | 2d44d77fed3200e2eff289f55493317e90d3398c (patch) | |
tree | d1d93511e3b05ef54497369d2d0ca603499d2862 /lib/AST/CommentBriefParser.cpp | |
parent | 5283c99365ec4697a5a6bb2b2505469a9aa474d5 (diff) |
Implement a lexer for structured comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CommentBriefParser.cpp')
-rw-r--r-- | lib/AST/CommentBriefParser.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/AST/CommentBriefParser.cpp b/lib/AST/CommentBriefParser.cpp new file mode 100644 index 0000000000..528fd2606f --- /dev/null +++ b/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 + + |