From c09cd7512491cee1e82c1ad8128ce9fd4bc3f79b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Sep 2017 23:32:28 +0200 Subject: Initial modularization with both Clang and VC hacks Note: gave up on VC about half way though. --- libbutl/tab-parser.mxx | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 libbutl/tab-parser.mxx (limited to 'libbutl/tab-parser.mxx') diff --git a/libbutl/tab-parser.mxx b/libbutl/tab-parser.mxx new file mode 100644 index 0000000..609a46d --- /dev/null +++ b/libbutl/tab-parser.mxx @@ -0,0 +1,85 @@ +// file : libbutl/tab-parser.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef __cpp_modules +#pragma once +#endif + +// C includes. + +#ifndef __cpp_lib_modules +#include +#include +#include +#include // uint64_t +#include // runtime_error +#endif + +// Other includes. + +#ifdef __cpp_modules +export module butl.tab_parser; +#ifdef __cpp_lib_modules +import std.core; +import std.io; +#endif +#endif + +#include + +LIBBUTL_MODEXPORT namespace butl +{ + class LIBBUTL_SYMEXPORT tab_parsing: public std::runtime_error + { + public: + tab_parsing (const std::string& name, + std::uint64_t line, + std::uint64_t column, + const std::string& description); + + std::string name; + std::uint64_t line; + std::uint64_t column; + std::string description; + }; + + // Line and columns are useful for issuing diagnostics about invalid or + // missing fields. + // + struct tab_field + { + std::string value; // Field string (quoting preserved). + std::uint64_t column; // Field start column number (one-based). + }; + + struct tab_fields: std::vector + { + std::uint64_t line; // Line number (one-based). + std::uint64_t end_column; // End-of-line column (line length). + }; + + // Read and parse lines consisting of space-separated fields. Field can + // contain single or double quoted substrings (with spaces) which are + // interpreted but preserved. No escaping of the quote characters is + // supported. Blank lines and lines that start with # (collectively called + // empty lines) are ignored. + // + class LIBBUTL_SYMEXPORT tab_parser + { + public: + tab_parser (std::istream& is, const std::string& name) + : is_ (is), name_ (name) {} + + // Return next line of fields. Skip empty lines. Empty result denotes the + // end of stream. + // + tab_fields + next (); + + private: + std::istream& is_; + const std::string name_; + std::uint64_t line_ = 0; + }; +} -- cgit v1.1