From 165ebf5e12d5c421df06d4371295c7a10e30beba 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 --- bpkg/manifest-parser | 63 +++++----------------------------------------------- 1 file changed, 5 insertions(+), 58 deletions(-) (limited to 'bpkg/manifest-parser') diff --git a/bpkg/manifest-parser b/bpkg/manifest-parser index 6dc3ee3..cee0786 100644 --- a/bpkg/manifest-parser +++ b/bpkg/manifest-parser @@ -10,6 +10,8 @@ #include // uint64_t #include // runtime_error +#include + namespace bpkg { class manifest_parsing: public std::runtime_error @@ -42,11 +44,11 @@ namespace bpkg empty () const {return name.empty () && value.empty ();} }; - class manifest_parser + class manifest_parser: protected butl::char_scanner { public: manifest_parser (std::istream& is, const std::string& name) - : is_ (is), name_ (name) {} + : char_scanner (is), name_ (name) {} const std::string& name () const {return name_;} @@ -68,31 +70,6 @@ namespace bpkg 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_; - }; - - private: void parse_name (manifest_name_value&); @@ -104,41 +81,11 @@ namespace bpkg xchar skip_spaces (); - // 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 (); - } + const std::string name_; - private: enum {start, body, end} s_ = start; std::string version_; // Current format version. - - private: - std::istream& is_; - const std::string name_; - - std::uint64_t l_ {1}; - std::uint64_t c_ {1}; - - bool unget_ {false}; - xchar buf_ {0, 0, 0}; - - bool eos_ {false}; }; } -- cgit v1.1