libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
explain.c
Go to the documentation of this file.
1// Copyright (C) 2023 Ethan Uppal. All rights reserved.
2
3#include "explain.h"
4#include "error.h"
5
6/* clang-format off */
7static STR explanations[PS_NUM_OF_ECODES] = {
8 [PS_ECODE_UNKNOWN_TOKEN] = "",
9 [PS_ECODE_UNBALANCED_SLASH_COMMENT] = "The lexer encountered an unknown "
10 "character or a known character in an invalid position.",
11
12 [PS_ECODE_INVALID_NUMBER] = "The lexer encountered a number with an "
13 "invalid digit representation or scientific notation.",
14
15 [PS_ECODE_EMPTY_CHR_LIT] = "The lexer encountered an empty character "
16 "literal in the source code. Character literals must contain at least one "
17 "character.",
18
19 [PS_ECODE_UNEXPECTED_TKN] = "The parser attempted to match a current token "
20 "in the token stream against a set number of possibilities. None of those "
21 "possibilities were encountered.",
22
23 [PS_ECODE_STOP] = "The maximum number of errors has been received.",
24
25 [PS_ECODE_EXPECTED_EXPR] = "The parser expected an expression in the "
26 "source code but did not find one. This could be due to a syntax error.",
27
28 [PS_ECODE_INVALID_OP] = "The parser encountered an invalid operator in the "
29 "source code. This could be due to an operator being used in an incorrect "
30 "context.",
31
32 [PS_ECODE_MISMATCH] = "The parser encountered mismatched groupings in the "
33 "source code. This could be due to mismatched parentheses, brackets, or "
34 "braces."
35};
36/* clang-format on */
37
39 if (code < 0 || code >= PS_NUM_OF_ECODES) {
40 return "The provided error code is invalid. Error codes must be in "
41 "range.";
42 }
43 STR explanation = explanations[code];
44 if (!explanation) {
45 return "The provided error code does not currently have an explanation "
46 "entry.";
47 }
48 return explanation;
49}
#define STR
Definition def.h:40
Error reporting and displaying utilities.
ps_error_code
The type of error that occured.
Definition error.h:33
@ PS_NUM_OF_ECODES
Definition error.h:37
STR ps_error_explain(enum ps_error_code code)
Returns an explanation of the error code code.
Definition explain.c:38
Error descriptions.