mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
fixes, colored errors
This commit is contained in:
parent
4b4756b657
commit
047ead6fa3
11 changed files with 166 additions and 195 deletions
|
|
@ -79,8 +79,7 @@ struct Function {
|
|||
|
||||
struct Typeclass {
|
||||
std::vector<Parameter> parameters;
|
||||
std::vector<FunctionDeclaration> function_requirements;
|
||||
std::vector<FunctionDeclaration> method_requirements;
|
||||
interpreter::tokens::TypeclassDefinitionStatement* node;
|
||||
};
|
||||
|
||||
struct Import {
|
||||
|
|
|
|||
|
|
@ -23,38 +23,36 @@ inline void PrintPosition(std::ostream& out,
|
|||
inline void HandleParsingError(const std::string& message,
|
||||
std::pair<size_t, size_t> start_position,
|
||||
std::pair<size_t, size_t> end_position) {
|
||||
std::cout << "Parsing Error: " << message << " at ";
|
||||
std::cout << "\x1b[1;31mParsing Error:\x1b[0m " << message << " at ";
|
||||
PrintPosition(std::cout, start_position, end_position);
|
||||
std::cout << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleGeneralError(const std::string& message) {
|
||||
std::cout << "General Error: " << message << ".\n";
|
||||
std::cout << "\x1b[1;31mGeneral Error:\x1b[0m " << message << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
||||
std::cout << "Internal Error: " << message << " at " << place << ".\n";
|
||||
std::cout << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at " << place << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleTypecheckError(const std::string& message,
|
||||
const interpreter::tokens::BaseNode& node) { // TODO: place in code
|
||||
std::cout << "Typecheck Error: " << message << " at ";
|
||||
const interpreter::tokens::BaseNode& node) {
|
||||
std::cout << "\x1b[1;31mTypecheck Error:\x1b[0m " << message << " at ";
|
||||
PrintPosition(std::cout, node.start_position, node.end_position);
|
||||
std::cout << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleRuntimeError(const std::string& message,
|
||||
const interpreter::tokens::BaseNode& node) { // TODO: place in code
|
||||
std::cout << "Runtime Error: " << message << " at ";
|
||||
const interpreter::tokens::BaseNode& node) {
|
||||
std::cout << "\x1b[1;31mRuntime Error:\x1b[0m " << message << " at ";
|
||||
PrintPosition(std::cout, node.start_position, node.end_position);
|
||||
std::cout << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
} // namespace error_handling
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ private:
|
|||
|
||||
utils::IdType current_value_;
|
||||
std::optional<LoopControlExpression> active_loop_control_expression_;
|
||||
std::optional<utils::IdType> return_value_; // TODO: work outside block ??
|
||||
std::optional<utils::IdType> returned_value_; // TODO: work outside block ??
|
||||
std::optional<utils::IsConstModifier> is_const_definition_;
|
||||
bool case_matched_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ private:
|
|||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
|
||||
bool is_in_statement_ = false;
|
||||
std::any current_info_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -51,10 +51,12 @@ public:
|
|||
void ToGlobalNamespace();
|
||||
|
||||
utils::IdType AddFunctionDeclaration(const std::string& name,
|
||||
definition::FunctionDeclaration&& function_declaration_info);
|
||||
definition::FunctionDeclaration&& function_declaration_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddFunctionDefinition(const std::string& name,
|
||||
definition::FunctionDefinition&& function_definition_info);
|
||||
definition::FunctionDefinition&& function_definition_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddType(const std::string& type,
|
||||
definition::Type&& type_info,
|
||||
|
|
@ -124,6 +126,10 @@ public:
|
|||
std::optional<utils::IdType> FindNamespaceIn(
|
||||
utils::IdType current_namespace,
|
||||
const std::vector<std::string>& path);
|
||||
|
||||
std::unordered_map<std::string, utils::IdType>*
|
||||
ChooseNamespaces(std::optional<utils::IsConstModifier> modifier,
|
||||
utils::IdType namespace_id);
|
||||
private:
|
||||
GlobalInfo& global_info_;
|
||||
|
||||
|
|
@ -135,7 +141,6 @@ public:
|
|||
return NamespaceVisitor(*this);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
definition::Function& GetFunctionInfo(utils::IdType id) {
|
||||
return functions_.at(id);
|
||||
}
|
||||
|
|
@ -148,27 +153,22 @@ public:
|
|||
return &std::get<T>(types_[id].type);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
definition::Type& GetAnyTypeInfo(utils::IdType id) {
|
||||
return types_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
definition::Typeclass& GetTypeclassInfo(utils::IdType id) {
|
||||
return typeclasses_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
definition::Constructor& GetConstructorInfo(utils::IdType id) {
|
||||
return constructors_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
definition::Namespace& GetNamespaceInfo(utils::IdType id) {
|
||||
return namespaces_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
PartitionInfo& GetPartitionInfo(utils::IdType id) {
|
||||
return partitions_.at(id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue