KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SemLexer.h
Go to the documentation of this file.
1 #ifndef SEM_LEXER_H_
2 #define SEM_LEXER_H_
3 
11 #include <iostream>
12 #include <string>
13 
14 #include "semantics/SemanticIO.h"
15 #include "spear/Wide.h"
16 #include <boost/tuple/tuple.hpp>
17 #include <boost/tuple/tuple_io.hpp>
18 
19 namespace semantics {
20 
21  class Sem_lexer
22  {
23  public:
24 
26  {
34  };
35 
36  // Initialize with an input stream
37  inline Sem_lexer(std::istream& stream) :
38  input_stream_(stream)
39  {
40  }
41 
42  // reads a token and returns a token code as well as the contents
43  boost::tuple<Sem_lexer::Token_code, String> get_and_classify_token();
44 
45  private:
46 
48  std::istream& input_stream_;
49 
50  template<typename T>
51  T get_semantic_token_as(const String &input)
52  {
53  return enum_to_string<T>(input);
54  }
55 
57  void skip_white_spaces();
58 
59  inline bool is_space(Char c) const
60  {
61  return !(c != W(' ') && c != W('\t'));
62  }
63 
64  inline bool is_newline(Char c) const
65  {
66  return !(c != W('\n') && c != W('\r'));
67  }
68  };
69 
70 } // end namespace spear
71 
72 #endif
Definition: SemLexer.h:21
boost::tuple< Sem_lexer::Token_code, String > get_and_classify_token()
Definition: SemLexer.cpp:36
Definition: SemLexer.h:32
Definition: SemLexer.h:27
char Char
Definition: Wide.h:34
Definition: SemLexer.h:29
Definition: SemLexer.h:28
#define String
Definition: Wide.h:36
Definition: SemLexer.h:31
#define W(X)
Definition: Wide.h:45
Definition: SemLexer.h:30
Token_code
Definition: SemLexer.h:25
Definition: SemLexer.h:33
Sem_lexer(std::istream &stream)
Definition: SemLexer.h:37