A simple scripting language in C++
Ferenc Szontágh
2025-04-14 d7cd4947b37a168034e9fca2501d98553fdcc137
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
#ifndef SCRIPT_EXCEPTION_MACROS_H
#define SCRIPT_EXCEPTION_MACROS_H
 
#include "ScriptException.hpp"
 
//
// Purpose of macros: unified exception handling with extended error information (source file and line number)
//
#define THROW_UNEXPECTED_END_OF_FILE_ERROR(token) \
    throw ScriptException::makeUnexpectedEndOfFileError(token, __FILE__, __LINE__)
 
// Invalid token type - expected different type
#define THROW_UNEXPECTED_TOKEN_ERROR(token, expected) \
    throw ScriptException::makeUnexpectedTokenError(token, expected, __FILE__, __LINE__)
 
#define THROW_UNEXPECTED_TOKEN_ERROR_HELPER(token, expected, file, line) \
    throw ScriptException::makeUnexpectedTokenError(token, expected, file, line)
 
// Accessing unknown (undefined) variable
#define THROW_UNDEFINED_VARIABLE_ERROR(name, token) \
    throw ScriptException::makeUndefinedVariableError(name, token, __FILE__, __LINE__)
 
#define THROW_UNDEFINED_VARIABLE_ERROR_HELPER(name, token, file, line) \
    throw ScriptException::makeUndefinedVariableError(name, token, file, line)
 
// Unknown (undefined) function call
#define THROW_UNDEFINED_FUNCTION_ERROR(name, token) \
    throw ScriptException::makeUndefinedFunctionError(name, token, __FILE__, __LINE__)
 
// Variable type mismatch - e.g. string instead of number
#define THROW_VARIABLE_TYPE_MISSMATCH_ERROR(target_variable_name, target_variable_type, source_variable_name,         \
                                            source_variable_type, token)                                              \
    throw ScriptException::makeVariableTypeMismatchError(target_variable_name, target_variable_type,                  \
                                                         source_variable_name, source_variable_type, token, __FILE__, \
                                                         __LINE__)
 
// Redefining a variable with the same name is not allowed
#define THROW_VARIABLE_REDEFINITION_ERROR(name, token) \
    throw ScriptException::makeVariableRedefinitionError(name, token, __FILE__, __LINE__)
 
#define THROW_FUNCTION_REDEFINITION_ERROR(name, token) \
    throw ScriptException::makeFunctionRedefinitionError(name, token, __FILE__, __LINE__)
 
// Invalid or incorrect function argument
#define THROW_INVALID_FUNCTION_ARGUMENT_ERROR(functionName, argName, token) \
    throw ScriptException::makeFunctionInvalidArgumentError(functionName, argName, token, __FILE__, __LINE__)
 
#define THROW_FUNCTION_ARG_COUNT_MISMATCH_ERROR(functionName, expected, actual, token)                             \
    throw ScriptException::makeFunctionArgumentCountMismatchError(functionName, expected, actual, token, __FILE__, \
                                                                  __LINE__)
 
#define THROW_FUNCTION_BODY_EMPTY(funcName, token) \
    throw ScriptException::makeFunctionBodyEmptyError(funcName, token, __FILE__, __LINE__)
 
#endif  // SCRIPT_EXCEPTION_MACROS_H