From cea6fb57ac8c9a893c0f404fef6c1469f0b6222b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Jul 2010 14:33:21 +0200 Subject: Next chunk of functionality Add SQL language lexer. Implement MySQL type declaration parser. Create sub-directories for databases, currently mysql and tracer. Create MySQL-specific context. --- odb/sql-lexer.hxx | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 odb/sql-lexer.hxx (limited to 'odb/sql-lexer.hxx') diff --git a/odb/sql-lexer.hxx b/odb/sql-lexer.hxx new file mode 100644 index 0000000..f650dc4 --- /dev/null +++ b/odb/sql-lexer.hxx @@ -0,0 +1,128 @@ +// file : odb/sql-lexer.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_SQL_LEXER_HXX +#define ODB_SQL_LEXER_HXX + +#include +#include +#include // std::size_t +#include + +#include + +class sql_lexer +{ +public: + sql_lexer (std::string const& sql); + + struct invalid_input + { + invalid_input (std::size_t l, std::size_t c, std::string const& m) + : line (l), column (c), message (m) + { + } + + std::size_t line; + std::size_t column; + std::string const message; + }; + + sql_token + next (); + +protected: + class xchar + { + public: + typedef std::char_traits traits_type; + typedef traits_type::int_type int_type; + typedef traits_type::char_type char_type; + + xchar (int_type v, std::size_t l, std::size_t c); + + operator char_type () const; + + int_type + value () const; + + std::size_t + line () const; + + std::size_t + column () const; + + private: + int_type v_; + std::size_t l_; + std::size_t c_; + }; + + xchar + peek (); + + xchar + get (); + + void + unget (xchar); + +protected: + void + skip_spaces (); + + sql_token + identifier (xchar); + + sql_token + int_literal (xchar, + bool neg = false, + std::size_t ml = 0, + std::size_t mc = 0); + + sql_token + string_literal (xchar); + +protected: + bool + is_alpha (char c) const; + + bool + is_oct_digit (char c) const; + + bool + is_dec_digit (char c) const; + + bool + is_hex_digit (char c) const; + + bool + is_alnum (char c) const; + + bool + is_space (char c) const; + + bool + is_eos (xchar const& c) const; + + char + to_upper (char c) const; + +private: + std::locale loc_; + std::istringstream is_; + std::size_t l_; + std::size_t c_; + + bool eos_; + bool include_; + + xchar buf_; + bool unget_; +}; + +#include + +#endif // ODB_SQL_LEXER_HXX -- cgit v1.1