10#include <kernel/util/string.hpp>
53 my_what(err_type +
": " + msg +
" in line " +
stringify(iline) +
": '" + sline +
"'")
76 virtual const char *
what() const noexcept
override
97 Error(iline, sline, msg,
"XML Syntax Error")
117 Error(iline, sline, msg,
"XML Grammar Error")
136 Error(iline, sline, msg,
"XML Content Error")
164 virtual bool attribs(std::map<String, bool>& attrs)
const = 0;
188 const std::map<String, String>& attrs,
224 virtual std::shared_ptr<MarkupParser>
markup(
int iline,
const String& sline,
const String& name) = 0;
263 virtual bool attribs(std::map<String, bool>&)
const override;
264 virtual void create(
int,
const String&,
const String&,
const std::map<String, String>&,
bool)
override;
266 virtual std::shared_ptr<MarkupParser>
markup(
int,
const String&,
const String&)
override;
291 explicit DumpParser(
const String& name,
bool lines =
true, std::size_t indent = 0);
292 virtual bool attribs(std::map<String, bool>&)
const override;
293 virtual void create(
int iline,
const String&,
const String&,
const std::map<String, String>& attrs,
bool closed)
override;
294 virtual void close(
int iline,
const String&)
override;
295 virtual std::shared_ptr<MarkupParser>
markup(
int,
const String&,
const String& name)
override;
296 virtual bool content(
int iline,
const String& sline)
override;
319 std::shared_ptr<MarkupParser> my_parser;
322 explicit MarkupInfo(
int _line,
const String& _name, std::shared_ptr<MarkupParser> _parser) :
323 my_line(_line), my_name(_name), my_parser(_parser)
332 const String& name()
const
337 std::shared_ptr<MarkupParser> parser()
375 explicit Scanner(std::istream& stream,
int lines_read = 0) :
485 void scan(std::shared_ptr<MarkupParser> root_parser);
String class implementation.
Dummy XML markup parser class.
virtual bool attribs(std::map< String, bool > &) const override
Specifies the mandatory and optional attributes.
virtual bool content(int, const String &) override
Called to process a content line.
virtual void create(int, const String &, const String &, const std::map< String, String > &, bool) override
Creates this markup parser node.
virtual void close(int, const String &) override
Closes this markup parser node.
virtual std::shared_ptr< MarkupParser > markup(int, const String &, const String &) override
Called to process a child markup node.
Dump XML markup parser class.
virtual std::shared_ptr< MarkupParser > markup(int, const String &, const String &name) override
Called to process a child markup node.
virtual void create(int iline, const String &, const String &, const std::map< String, String > &attrs, bool closed) override
Creates this markup parser node.
bool _lines
specifies whether to write line numbers
std::size_t _indent
indentation for this parser node
String _name
the name of this markup parser node
virtual bool attribs(std::map< String, bool > &) const override
Specifies the mandatory and optional attributes.
virtual bool content(int iline, const String &sline) override
Called to process a content line.
virtual void close(int iline, const String &) override
Closes this markup parser node.
int get_line_number() const
const String & get_message() const
String my_msg
error message
String my_what
what string
int my_iline
erroneous line number
const String & get_line_string() const
String my_sline
erroneous line string
virtual const char * what() const noexcept override
XML Markup Parser interface.
virtual ~MarkupParser()
virtual destructor
virtual bool content(int iline, const String &sline)=0
Called to process a content line.
virtual void close(int iline, const String &sline)=0
Closes this markup parser node.
virtual std::shared_ptr< MarkupParser > markup(int iline, const String &sline, const String &name)=0
Called to process a child markup node.
virtual void create(int iline, const String &sline, const String &name, const std::map< String, String > &attrs, bool closed)=0
Creates this markup parser node.
virtual bool attribs(std::map< String, bool > &attrs) const =0
Specifies the mandatory and optional attributes.
void set_root_parser(std::shared_ptr< MarkupParser > parser)
Sets the root markup parser node.
String _cur_sline
current line string
bool read_next_line()
Reads the next non-empty line from the stream.
bool _cur_is_termin
specifies whether the markup is a terminator
bool is_cur_markup() const
bool scan_markup()
Tries to interpret the current line as a XML markup line.
int _cur_iline
current line number
std::map< String, String > _cur_attribs
specifies the markup attributes of the current line
void read_root()
Tries to read the XML root markup.
void throw_content(const String &msg) const
Throws a ContentError for the current line.
bool _have_read_root
specifies whether the root has been read
void throw_grammar(const String &msg) const
Throws a GrammarError for the current line.
bool is_cur_termin() const
String _cur_name
specifies the markup name of the current line
void create_top_parser()
Creates the top parser node.
void process_markup()
Tries to process the current XML markup line.
void throw_syntax(const String &msg) const
Throws a SyntaxError for the current line.
bool _cur_is_markup
specifies whether this line is a markup
std::vector< MarkupInfo > _markups
the markup stack
const String & get_cur_sline() const
bool is_cur_closed() const
const std::map< String, String > & get_cur_attribs() const
void process_content()
Tries to process the current XML content line.
const String & get_cur_name() const
Scanner(std::istream &stream, int lines_read=0)
Creates a XML scanner for an input stream.
bool _cur_is_closed
specifies whether the markup is closed
void scan()
Scans the stream.
virtual ~Scanner()
virtual destructor
std::istream & _stream
the input stream
int get_cur_iline() const
String stringify(const T_ &item)
Converts an item into a String.