Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2021-2025 ChilliBits. All rights reserved. |
2 |
|
|
|
3 |
|
|
#pragma once |
4 |
|
|
|
5 |
|
|
#include <cstdint> |
6 |
|
|
#include <exception> |
7 |
|
|
#include <string> |
8 |
|
|
|
9 |
|
|
namespace spice::compiler { |
10 |
|
|
|
11 |
|
|
// Forward declarations |
12 |
|
|
struct CodeLoc; |
13 |
|
|
|
14 |
|
|
enum ParserErrorType : uint8_t { |
15 |
|
|
PARSING_FAILED, |
16 |
|
|
NUMBER_OUT_OF_RANGE, |
17 |
|
|
INVALID_QUALIFIER_COMBINATION, |
18 |
|
|
INVALID_CHAR_LITERAL, |
19 |
|
|
INVALID_ATTR_VALUE_TYPE, |
20 |
|
|
RESERVED_KEYWORD, |
21 |
|
|
RESERVED_TYPENAME, |
22 |
|
|
}; |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* Custom exception for errors, occurring while parsing |
26 |
|
|
*/ |
27 |
|
|
class ParserError final : public std::exception { |
28 |
|
|
public: |
29 |
|
|
// Constructors |
30 |
|
|
ParserError(const CodeLoc &codeLoc, const ParserErrorType &type, const std::string &message); |
31 |
|
|
|
32 |
|
|
// Public methods |
33 |
|
|
[[nodiscard]] const char *what() const noexcept override; |
34 |
|
|
[[nodiscard]] static std::string getMessagePrefix(ParserErrorType errorType); |
35 |
|
|
|
36 |
|
|
// Public members |
37 |
|
|
std::string errorMessage; |
38 |
|
|
}; |
39 |
|
|
|
40 |
|
|
} // namespace spice::compiler |
41 |
|
|
|