aboutsummaryrefslogtreecommitdiff
path: root/odb/cxx-lexer.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-16 16:03:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-16 16:03:25 +0200
commitb79567fbc72df23f870049652d5f254aba948bea (patch)
tree186168269cf249ce97be89fd02aab4c75e83574c /odb/cxx-lexer.hxx
parentd780414989ef7e101cdaf269d4b01003d0721e6a (diff)
Support for views; integrated part
Diffstat (limited to 'odb/cxx-lexer.hxx')
-rw-r--r--odb/cxx-lexer.hxx79
1 files changed, 73 insertions, 6 deletions
diff --git a/odb/cxx-lexer.hxx b/odb/cxx-lexer.hxx
index 729f196..e5b117e 100644
--- a/odb/cxx-lexer.hxx
+++ b/odb/cxx-lexer.hxx
@@ -10,29 +10,96 @@
#include <string>
+#include <odb/cxx-token.hxx>
+
// A C++ keyword. This is an extension to libcpp token types.
//
#define CPP_KEYWORD ((cpp_ttype) (N_TTYPES + 1))
-// A thin wrapper around cpp_reader for lexing C++ code fragments.
-//
class cxx_lexer
{
public:
- cxx_lexer ();
+ virtual
~cxx_lexer ();
public:
struct invalid_input {};
+ virtual cpp_ttype
+ next (std::string& token) = 0;
+
+public:
+ static char const* token_spelling[N_TTYPES + 1];
+};
+
+
+// Adapter to scan a saved token sequence.
+//
+class cxx_tokens_lexer: public cxx_lexer
+{
+public:
void
- start (std::string const&);
+ start (cxx_tokens const&);
- cpp_ttype
+ virtual cpp_ttype
next (std::string& token);
+private:
+ cxx_tokens const* tokens_;
+ cxx_tokens::const_iterator cur_;
+};
+
+
+// A thin wrapper around the pragma_lex() function that recognizes
+// CPP_KEYWORD.
+//
+class cxx_pragma_lexer: public cxx_lexer
+{
public:
- static char const* token_spelling[N_TTYPES + 1];
+ void
+ start ();
+
+ // Start with an already extracted (using the pragma_lex() function)
+ // token. This function translates the CPP_NAME to CPP_KEYWORD if
+ // necessary and returns the string token. It also uses the passed
+ // token and type for subsequent calls to next() so after the last
+ // next() call they will contain the information about the last
+ // token parsed.
+ //
+ std::string
+ start (tree& token, cpp_ttype& type);
+
+ virtual cpp_ttype
+ next (std::string& token);
+
+private:
+ std::string
+ translate ();
+
+private:
+ tree* token_;
+ cpp_ttype* type_;
+
+ tree token_data_;
+ cpp_ttype type_data_;
+};
+
+// A thin wrapper around cpp_reader for lexing C++ code fragments.
+//
+class cxx_string_lexer: public cxx_lexer
+{
+public:
+ cxx_string_lexer ();
+
+ virtual
+ ~cxx_string_lexer ();
+
+public:
+ void
+ start (std::string const&);
+
+ virtual cpp_ttype
+ next (std::string& token);
private:
std::string data_;