Om
separator.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Separator_
16 
17  #include "om/language/separator.hpp"
18 
19  #ifdef Om_Macro_Test_
20 
21  #include "om/language/writer.hpp"
22 
23  #ifndef Om_Macro_Precompilation_
24 
25  #include "boost/test/unit_test.hpp"
26 
27  #endif
28 
29 namespace Om {
30 
31  namespace Language {
32 
33  BOOST_AUTO_TEST_SUITE(SeparatorTest)
34 
35  BOOST_AUTO_TEST_CASE(DereferenceTest) {
36  {
37  Separator theMutableSeparator;
38  Atom & theMutableAtom = theMutableSeparator;
39  Program & theMutableDereference = *theMutableAtom;
40  BOOST_CHECK(
41  typeid(theMutableDereference) == typeid(Null)
42  );
43  }
44 
45  {
46  Separator const theImmutableSeparator;
47  Atom const & theImmutableAtom = theImmutableSeparator;
48  Program const & theImmutableDereference = *theImmutableAtom;
49  BOOST_CHECK(
50  typeid(theImmutableDereference) == typeid(Null)
51  );
52  }
53  }
54 
55  BOOST_AUTO_TEST_CASE(ReadTest) {
56  char const theCode[] = "0\n\t {1\n\t {2\n\t } 3\n\t } {4\n\t} 5\n";
57  std::string theResult;
58  {
60  std::back_insert_iterator<std::string>
61  > theCodePointSink(
62  std::back_inserter(theResult)
63  );
64  Writer theWriter(theCodePointSink);
65 
66  Om::Source::CodePointSource<> theCodePointSource(theCode);
67  Reader theReader(theCodePointSource);
68  Separator theSeparator;
69  theSeparator.ParseElements(theReader);
70  theSeparator.GiveElements(theWriter);
71  }
72  BOOST_CHECK_EQUAL(
73  "\n\t \n",
74  theResult
75  );
76  }
77 
78  BOOST_AUTO_TEST_SUITE_END()
79 
80  }
81 
82 }
83 
84  #endif
85 
86 #else
87 
88 // MARK: - Om::Language::Separator
89 
90  #define Type_ \
91  Om::Language::Separator
92 
93 // MARK: public (static)
94 
95 inline Type_ const & Type_::GetLineSeparator() {
96  static Separator const theSeparator(Symbol::theLineSeparatorSymbol);
97  return theSeparator;
98 }
99 
100 inline char const * Type_::GetName() {
102 }
103 
104 // MARK: public (non-static)
105 
106 inline Type_::Separator() {}
107 
108 inline Type_::Separator(
109  Om::Source::Source<CodePoint const> & theCodePointSource
110 ) {
111  for (
112  ;
113  theCodePointSource;
114  theCodePointSource.Pop()
115  ) {
116  switch (*theCodePointSource) {
117  default:
118  return;
120  this->thisString.push_back(
121  static_cast<char>(*theCodePointSource)
122  );
123  // Fall through.
124  }
125  }
126 }
127 
128 inline Type_::Separator(Symbol::SeparatorSymbol const theSeparatorSymbol):
129 DefaultAtom<Separator>(
130  static_cast<char>(theSeparatorSymbol)
131 ) {
132  assert(
133  Symbol::theSpaceSeparatorSymbol == theSeparatorSymbol ||
134  Symbol::theLineSeparatorSymbol == theSeparatorSymbol ||
135  Symbol::theTabSeparatorSymbol == theSeparatorSymbol
136  );
137 }
138 
139 inline Type_ & Type_::operator =(Separator theSeparator) {
140  this->Swap(theSeparator);
141  return *this;
142 }
143 
144 inline void Type_::ParseElements(Reader & theReader) {
145  for (
146  ;
147  theReader;
148  theReader.Pop()
149  ) {
150  assert(Symbol::theEndOperandSymbol != *theReader);
151  switch (*theReader) {
153  theReader.Pop();
154  {
155  // Ensure that this does not resolve to the copy constructor.
156  Om::Source::Source<CodePoint const> & theCodePointSource = theReader;
157 
158  Reader theOperandReader(theCodePointSource);
159  this->ParseQuotedElements(theOperandReader);
160  }
161  if (!theReader) {
162  return;
163  }
164  assert(Symbol::theEndOperandSymbol == *theReader);
165  continue;
167  this->thisString.push_back(
168  static_cast<char>(*theReader)
169  );
170  // Fall through.
171  }
172  }
173 }
174 
175 inline void Type_::ParseQuotedElements(Reader & theReader) {
176  for (
177  ;
178  theReader;
179  theReader.Pop()
180  ) {}
181 }
182 
183 template <typename TheOperand>
184 inline void Type_::TakeOperand(TheOperand &) {}
185 
186 template <typename TheOperator>
187 inline void Type_::TakeOperator(TheOperator &) {}
188 
189 template <typename TheProducer>
190 inline void Type_::TakeQuotedProducer(TheProducer &) {}
191 
192 template <typename TheSeparator>
193 inline void Type_::TakeSeparator(TheSeparator & theSeparator) {
194  assert(
195  !theSeparator.IsEmpty()
196  );
197  this->thisString.append(theSeparator.thisString);
198 }
199 
200 inline void Type_::TakeSeparatorSymbol(
201  Symbol::SeparatorSymbol const theSymbol
202 ) {
203  this->thisString.push_back(
204  static_cast<char>(theSymbol)
205  );
206 }
207 
208  #undef Type_
209 
210 // MARK: - boost::
211 
212 template <>
213 inline void boost::swap(
214  Om::Language::Separator & theFirst,
215  Om::Language::Separator & theSecond
216 ) {
217  theFirst.Swap(theSecond);
218 }
219 
220 #endif
void Swap(ThisImplementation &)
The Separator implementation.
Definition: separator.hpp:53
A CodePoint Sink that pushes each code unit to the iterator.
A CodePoint Source that reads each code unit from the iterator.
Any object that items can be pulled from.
Definition: source.hpp:31
virtual void Pop()=0
Pops the current item.
SeparatorSymbol
A Separator symbol.
The Om library.
Definition: code_point.hpp:26
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om header file.
#define Om_Language_Separator_GetName_()
Definition: separator.hpp:35
#define Om_Language_Symbol_SeparatorSymbol_GetCases_()
Generates switch cases for each Om::Language::Symbol::SeparatorSymbol.
Om header file.