summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/comment.hh
blob: 21fa3ea38d483210c02611585fd3a47ec6d1b2f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#ifndef EOLIAN_CXX_STD_COMMENT_HH
#define EOLIAN_CXX_STD_COMMENT_HH

#include <string>
#include <sstream>
#include <iosfwd>
#include <ostream>

#include "tab.hh"

namespace efl { namespace eolian { namespace grammar {

using std::endl;

const std::string comment_prefix("///");

struct comment
{
   std::string _doc;
   int _tab;
   std::string _if_empty;
   comment(std::string const& doc, int tab = 0, std::string const& if_empty = "")
     : _doc(doc), _tab(tab), _if_empty(if_empty)
   {}
};

inline std::ostream&
operator<<(std::ostream& out, comment const& x)
{
   std::string const& doc = !x._doc.empty() ? x._doc : x._if_empty;
   std::istringstream ss(doc);
   std::string line;
   while(std::getline(ss, line))
     {
        out << tab(x._tab) << comment_prefix
            << (line.size() ? (" " + line) : "")
            << endl;
     }
   return out;
}

} } } // namespace efl { namespace eolian { namespace grammar {

#endif // EOLIAN_CXX_STD_COMMENT_HH