From 501ce5993f3d52208696c81248829247da7b46b5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Jun 2015 15:25:36 +0200 Subject: Add char-scanner to libbutl, use in libbpkg and build2 --- build/lexer | 59 +++++------------------------------------------------------ 1 file changed, 5 insertions(+), 54 deletions(-) (limited to 'build/lexer') diff --git a/build/lexer b/build/lexer index 1106ed0..5205ae9 100644 --- a/build/lexer +++ b/build/lexer @@ -10,6 +10,8 @@ #include // uint64_t #include +#include + #include #include @@ -25,10 +27,11 @@ namespace build // enum class lexer_mode {normal, value, variable, pairs}; - class lexer + class lexer: protected butl::char_scanner { public: - lexer (std::istream& is, const std::string& name): is_ (is), fail (name) {} + lexer (std::istream& is, const std::string& name) + : char_scanner (is), fail (name) {} const std::string& name () const {return fail.name_;} @@ -52,30 +55,6 @@ namespace build next (); private: - 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::uint64_t l, std::uint64_t c) - : v_ (v), l_ (l), c_ (c) {} - - operator char_type () const {return static_cast (v_);} - - int_type - value () const {return v_;} - - std::uint64_t line () const {return l_;} - std::uint64_t column () const {return c_;} - - private: - int_type v_; - std::uint64_t l_; - std::uint64_t c_; - }; - token name (xchar, bool separated); @@ -89,26 +68,6 @@ namespace build xchar escape (); - // Character interface. - // - private: - xchar - peek (); - - xchar - get (); - - void - unget (const xchar&); - - // Tests. - // - bool - is_eos (const xchar& c) const - { - return c.value () == xchar::traits_type::eof (); - } - // Diagnostics. // private: @@ -124,16 +83,8 @@ namespace build typedef diag_mark fail_mark; private: - std::istream& is_; fail_mark fail; - std::uint64_t l_ {1}; - std::uint64_t c_ {1}; - - bool unget_ {false}; - xchar buf_ {0, 0, 0}; - - bool eos_ {false}; lexer_mode mode_ {lexer_mode::normal}; char pair_separator_; lexer_mode next_mode_ {lexer_mode::normal}; // Switch to for next token. -- cgit v1.1