Prettify errors

This commit is contained in:
ala89 2023-12-15 14:37:39 +01:00
parent 0cd17b9003
commit f7af17c899

View File

@ -12,8 +12,16 @@ using namespace std;
/** /**
* Tokens definition * Tokens definition
*/ */
enum class TokenType { Identifier, Litteral, Plus, Minus, DoublePlus, DoubleMinus, DoubleEqual, Land, Lor, Lt, Gt, Leq, Geq, NotEqual, Not, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese, LCurlyBracket, RCurlyBracket, If, Else, While, For, Break, Continue, Comma }; enum class TokenType {
enum class Type { Int, Double }; Identifier, Litteral, Plus, Minus, DoublePlus, DoubleMinus, DoubleEqual, Land,
Lor, Lt, Gt, Leq, Geq, NotEqual, Not, Star, Slash, Percent, Equal, Semicolon,
LParenthese, RParenthese, LCurlyBracket, RCurlyBracket, If, Else, While, For,
Break, Continue, Comma
};
enum class Type {
Int, Double
};
using TokenData = variant<int, double, string, Type>; using TokenData = variant<int, double, string, Type>;
@ -183,7 +191,38 @@ struct Scope {
/** /**
* Errors * Errors
*/ */
enum class ErrorType { DivisionByZero, ModuloByZero, ExpectedIntegralType, ExpectedArithmeticType, UninitializedIdentifier, UnknownIdentifier, AlreadyDefinedIdentifier, EmptyInput, UnknownToken, InvalidSyntax, ExceptedLParen, ExpectedRParen, ExpectedRCurlyBracket, ExpectedSemicolon, DependentDeclaration, TypesNotComparable, TypeNotCastable, UnknownType }; enum class ErrorType {
// Generic
NotImplemented,
// Lexing
UnknownToken,
// Parsing
EmptyInput,
InvalidSyntax,
ExceptedLParen,
ExpectedRParen,
ExpectedRCurlyBracket,
ExpectedSemicolon,
DependentDeclaration,
// Analysis
UnknownType,
TypeNotCastable,
TypesNotComparable,
ExpectedIntegralType,
ExpectedArithmeticType,
// Runtime
DivisionByZero,
ModuloByZero,
UnknownIdentifier,
AlreadyDefinedIdentifier,
UninitializedIdentifier,
BreakNotWithinLoop,
ContinueNotWithinLoop,
};
using ErrorData = variant<monostate, string>; using ErrorData = variant<monostate, string>;