-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparsegen_error.hpp
84 lines (76 loc) · 2.34 KB
/
parsegen_error.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <stdexcept>
#include <string>
namespace parsegen {
class parse_error : public std::invalid_argument {
public:
parse_error(const std::string& msg);
virtual void out_of_line_virtual_method();
};
class error : public std::runtime_error {
std::string m_before_message;
std::string m_parser_message;
std::string m_after_message;
std::string m_full_message;
public:
error(
std::string const& before_message_arg,
std::string const& after_message_arg = "",
std::string const& parser_message_arg = "")
:std::runtime_error("")
,m_before_message(before_message_arg)
,m_parser_message(parser_message_arg)
,m_after_message(after_message_arg)
{
m_full_message = m_before_message + m_parser_message + m_after_message;
}
void set_before_message(std::string const& before_message_arg)
{
m_before_message = before_message_arg;
m_full_message = m_before_message + m_parser_message + m_after_message;
}
void set_after_message(std::string const& after_message_arg)
{
m_after_message = after_message_arg;
m_full_message = m_before_message + m_parser_message + m_after_message;
}
void set_parser_message(std::string const& parser_message_arg)
{
m_parser_message = parser_message_arg;
m_full_message = m_before_message + m_parser_message + m_after_message;
}
virtual const char* what() const noexcept override
{
return m_full_message.c_str();
}
};
class unacceptable_token : public error {
std::string m_token_name;
public:
unacceptable_token(
std::string const& parser_message_arg,
std::string const& token_name_arg)
:error("Unacceptable token\n", "", parser_message_arg)
,m_token_name(token_name_arg)
{
}
std::string const& token_name() const { return m_token_name; }
};
class bad_character : public error {
public:
bad_character(std::string const& parser_message_arg)
:error(
"Encountered a non-ASCII character\n",
"This parser can only handle ASCII characters.\n"
"Usually, non-ASCII characters are caused by trying to "
"use foreign-language accents or by copying text from a web page.\n",
parser_message_arg)
{}
};
class tokenization_failure : public error {
public:
tokenization_failure(std::string const& parser_message_arg)
:error("Could not tokenize the text\n", "", parser_message_arg)
{}
};
}