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 
78 
79  Lexicon(Lexicon const &);
80 
82 
84 
85  virtual void Clear();
86 
91  Pair const & Find(Operator const &) const;
92 
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 
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 
231  Lexicon::ElementRange const &,
232  Lexicon::ElementRange const &
233  );
234 
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
An Element taker; takes at the back.
Definition: consumer.hpp:42
A partial implementation of Program.
A Program that contains a single elemental item (or none, when IsEmpty() returns true).
Definition: element.hpp:33
The current evaluation.
Definition: evaluation.hpp:42
A Lexicon Element range.
Definition: lexicon.hpp:191
virtual void Pop()
Pops the current item.
char thisOffset
The Element offset in the current Node.
Definition: lexicon.hpp:224
bool Equals(ElementRange const &) const
PairList::Node const * thisNode
The current Node, or null if none.
Definition: lexicon.hpp:218
virtual Element const & operator*() const
The Lexicon Program implementation.
Definition: lexicon.hpp:67
virtual void GiveElements(Consumer &)
virtual void GiveElements(Consumer &) const
Lexicon & operator=(Lexicon)
virtual bool IsEmpty() const
PairList::Node & GetOperandTaker(TheOperator &)
Ensures that there is a last Node with an empty Operand, and the given Operator, and returns a refere...
void Swap(Lexicon &)
void TakeOperator(TheOperator &)
Pair const & Find(Operator const &) const
virtual bool Translate(Evaluation &, Operator const &) const
Translates the Operator to an object that is then given to the Evaluation.
void TakeOperand(TheOperand &)
virtual std::auto_ptr< Om::Source::Source< Element const > > GetElementRange() const
boost::ptr_map< std::string, PairList::Node > Map
Definition: lexicon.hpp:135
virtual void ParseElements(Reader &)
Lexicon(Lexicon const &)
void TakeQuotedProducer(TheProducer &)
static void GiveElements(TheNode *theFirstNode, Consumer &theConsumer)
Gives each Element in the Lexicon.
void GivePair(PairList::NodeIndex const, Consumer &)
void FrontGivePair(Consumer &)
virtual void ParseQuotedElements(Reader &)
static char const * GetName()
virtual void Clear()
void BackGivePair(Consumer &)
PairList::Node & GetOperandTaker()
Ensures that there is a last Node with an empty Operand, and with any Operator, and returns a referen...
void TakeSeparator(TheSeparator &)
List< Pair > PairList
Definition: lexicon.hpp:130
The Operator implementation.
Definition: operator.hpp:60
An Operator and an Operand.
Definition: pair.hpp:32
Produces each CodePoint until the end of the Source.
Definition: reader.hpp:37
An Operator lookup for use by an Evaluator.
Definition: translator.hpp:62
A partial implementation of Source.
Any object that items can be pulled from.
Definition: source.hpp:31
Om header file.
Om source file.
Om header file.
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
The Om library.
Definition: code_point.hpp:26
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om header file.
Om header file.