Om
lexicon.hpp
Go to the documentation of this file.
1 
32 #ifndef Om_Language_Lexicon_
33 
34  #define Om_Language_Lexicon_ \
35  Om::Language::Lexicon
36 
37  #include "om/language/pair.hpp"
39  #include "om/list.hpp"
41 
42  #ifndef Om_Macro_Precompilation_
43 
44  #include "boost/ptr_container/ptr_map.hpp"
45 
46  #endif
47 
48  #define Om_Language_Lexicon_GetName_() \
49  "lexicon"
50 
51 namespace Om {
52 
53  namespace Language {
54 
56  class Evaluation;
58 
59  // MARK: - Om::Language::Lexicon
60 
65  class Lexicon:
66  public DefaultProgram<Lexicon>,
67  public Translator {
68 
69  public: // MARK: public (static)
70 
71  class ElementRange;
72 
73  static char const * GetName();
74 
75  public: // MARK: public (non-static)
76 
77  Lexicon();
78 
79  Lexicon(Lexicon const &);
80 
82 
83  void BackGivePair(Consumer &);
84 
85  virtual void Clear();
86 
91  Pair const & Find(Operator const &) const;
92 
93  void FrontGivePair(Consumer &);
94 
95  virtual std::auto_ptr<
97  > GetElementRange() const;
98 
99  virtual void GiveElements(Consumer &);
100 
101  virtual void GiveElements(Consumer &) const;
102 
103  virtual bool IsEmpty() const;
104 
105  virtual void ParseElements(Reader &);
106 
107  virtual void ParseQuotedElements(Reader &);
108 
109  void Swap(Lexicon &);
110 
111  template <typename TheOperand>
112  void TakeOperand(TheOperand &);
113 
114  template <typename TheOperator>
115  void TakeOperator(TheOperator &);
116 
117  template <typename TheProducer>
118  void TakeQuotedProducer(TheProducer &);
119 
120  template <typename TheSeparator>
121  void TakeSeparator(TheSeparator &);
122 
123  virtual bool Translate(
124  Evaluation &,
125  Operator const &
126  ) const;
127 
128  private: // MARK: private (static)
129 
131 
132  typedef boost::ptr_map<
133  std::string,
134  PairList::Node
135  > Map;
136 
145  template <typename TheNode>
146  static void GiveElements(
147  TheNode * theFirstNode,
148  Consumer & theConsumer
149  );
150 
151  private: // MARK: private (non-static)
152 
159  PairList::Node & GetOperandTaker();
160 
167  template <typename TheOperator>
168  PairList::Node & GetOperandTaker(TheOperator &);
169 
170  void GivePair(
171  PairList::NodeIndex const,
172  Consumer &
173  );
174 
176 
178 
179  };
180 
181  // MARK: - Om::Language::Lexicon::ElementRange
182 
189  Element const,
190  ElementRange
191  > {
192 
193  public: // MARK: public (non-static)
194 
195  ElementRange();
196 
197  explicit ElementRange(Lexicon const &);
198 
199  virtual bool operator !() const;
200 
201  virtual Element const & operator *() const;
202 
204  Element const,
206  >::Equals;
207 
208  bool Equals(ElementRange const &) const;
209 
210  virtual void Pop();
211 
212  private: // MARK: private (non-static)
213 
218  PairList::Node const * thisNode;
219 
225 
226  };
227 
228  // MARK: - Om::Language::
229 
230  bool operator ==(
231  Lexicon::ElementRange const &,
232  Lexicon::ElementRange const &
233  );
234 
235  bool operator !=(
236  Lexicon::ElementRange const &,
237  Lexicon::ElementRange const &
238  );
239 
240  }
241 
242 }
243 
244 namespace boost {
245 
246  // MARK: - boost::
247 
248  template <>
249  void swap(
252  );
253 
254 }
255 
256  #include "om/language/lexicon.cpp"
257 
258 #endif
Om::List< Pair >::NodeIndex
NodeIndex
Definition: list.hpp:39
Om::Language::Lexicon::ElementRange::thisNode
const PairList::Node * thisNode
The current Node, or null if none.
Definition: lexicon.hpp:218
Om::List< Pair >
translator.hpp
Om header file.
Om::Language::Lexicon::thisPairList
PairList thisPairList
Definition: lexicon.hpp:177
Om::Language::Lexicon::GetElementRange
virtual std::auto_ptr< Om::Source::Source< Element const > > GetElementRange() const
Om::Source::DefaultSource
A partial implementation of Source.
Definition: default_source.hpp:42
Om::Language::Operator
The Operator implementation.
Definition: operator.hpp:59
Om::Language::Lexicon::ElementRange
A Lexicon Element range.
Definition: lexicon.hpp:187
Om::Language::Lexicon::ElementRange::Equals
bool Equals(ElementRange const &) const
Om::Language::operator==
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
boost
Definition: expression.hpp:281
Om::Language::Element
A Program that contains a single elemental item (or none, when IsEmpty() returns true).
Definition: element.hpp:32
Om::Language::operator!=
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
Om::Language::Lexicon::PairList
List< Pair > PairList
Definition: lexicon.hpp:130
default_source.hpp
Om header file.
Om::Language::Lexicon::Clear
virtual void Clear()
Om::Language::Lexicon::Swap
void Swap(Lexicon &)
Om::Language::DefaultProgram
A partial implementation of Program.
Definition: default_program.hpp:41
Om::Language::Lexicon::GiveElements
virtual void GiveElements(Consumer &)
Gives each contained Element to the argument.
Om::Language::Consumer
An Element taker; takes at the back.
Definition: consumer.hpp:42
Om::Language::Lexicon::GivePair
void GivePair(PairList::NodeIndex const, Consumer &)
list.hpp
Om header file.
Om::Language::Translator
An Operator lookup for use by an Evaluator.
Definition: translator.hpp:62
Om::Language::Evaluation
The current evaluation.
Definition: evaluation.hpp:42
Om::Language::Lexicon::ElementRange::operator*
virtual const Element & operator*() const
Om::Language::Lexicon::BackGivePair
void BackGivePair(Consumer &)
Om::Language::Lexicon::GetName
static const char * GetName()
Om::Language::Pair
An Operator and an Operand.
Definition: pair.hpp:32
Om::Language::Lexicon::TakeSeparator
void TakeSeparator(TheSeparator &)
Om::Language::Reader
Produces each CodePoint until the end of the Source.
Definition: reader.hpp:33
Om::Language::Lexicon::ElementRange::thisOffset
char thisOffset
The Element offset in the current Node.
Definition: lexicon.hpp:224
Om::Language::Lexicon::ParseElements
virtual void ParseElements(Reader &)
Om::Language::Lexicon::Translate
virtual bool Translate(Evaluation &, Operator const &) const
Translates the Operator to an object that is then given to the Evaluation.
Om::Language::Lexicon::ElementRange::ElementRange
ElementRange()
Om::Language::Lexicon::Find
const Pair & Find(Operator const &) const
Om::Language::Lexicon::IsEmpty
virtual bool IsEmpty() const
Om::Language::Lexicon::operator=
Lexicon & operator=(Lexicon)
Om::Language::Lexicon::TakeQuotedProducer
void TakeQuotedProducer(TheProducer &)
Om
The Om library.
Definition: code_point.hpp:26
Om::Language::Lexicon::TakeOperator
void TakeOperator(TheOperator &)
Om::Language::Lexicon::ParseQuotedElements
virtual void ParseQuotedElements(Reader &)
Om::Language::Lexicon
The Lexicon Program implementation.
Definition: lexicon.hpp:65
Om::Source::Source
Any object that items can be pulled from.
Definition: source.hpp:31
Om::Language::Lexicon::FrontGivePair
void FrontGivePair(Consumer &)
lexicon.cpp
Om source file.
Om::Language::Lexicon::Lexicon
Lexicon()
Om::Language::Lexicon::ElementRange::Pop
virtual void Pop()
Pops the current item.
boost::swap
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om::Language::Lexicon::thisMap
Map thisMap
Definition: lexicon.hpp:175
Om::Language::Lexicon::Map
boost::ptr_map< std::string, PairList::Node > Map
Definition: lexicon.hpp:135
pair.hpp
Om header file.
Om::Language::Lexicon::ElementRange::operator!
virtual bool operator!() const
Om::Language::Lexicon::TakeOperand
void TakeOperand(TheOperand &)
Om::Language::Lexicon::GetOperandTaker
PairList::Node & GetOperandTaker()
Ensures that there is a last Node with an empty Operand, and with any Operator, and returns a referen...