mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-26 00:38:45 +00:00
result / optional return type modifiers for functions (one for all returns)
This commit is contained in:
parent
68463509d8
commit
195a26f9b7
10 changed files with 74 additions and 36 deletions
|
|
@ -5,6 +5,15 @@
|
|||
|
||||
namespace builders {
|
||||
|
||||
namespace utils {
|
||||
|
||||
inline bool is_suffix_modifier(nodes::Modifier modifier) {
|
||||
return modifier == nodes::Modifier::OPTIONAL ||
|
||||
modifier == nodes::Modifier::RESULT;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
// returns Modifier::NONE for incorrecnt input
|
||||
nodes::Modifier build_modifier(parser::ParseTree::Node parser_node);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,15 +16,18 @@ inline void print_position(std::ostream &out,
|
|||
<< ']';
|
||||
}
|
||||
|
||||
inline void
|
||||
handle_internal_error(const std::string &message,
|
||||
std::optional<const nodes::Node *> node = std::nullopt) {
|
||||
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message;
|
||||
if (node.has_value()) {
|
||||
std::cerr << " at ";
|
||||
print_position(std::cerr, node.value()->get_start_position(),
|
||||
node.value()->get_end_position());
|
||||
}
|
||||
inline void handle_internal_error(const std::string &message,
|
||||
const nodes::Node &node) {
|
||||
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at ";
|
||||
print_position(std::cerr, node.get_start_position(), node.get_end_position());
|
||||
std::cerr << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void handle_internal_error(const std::string &message,
|
||||
parser::ParseTree::Node node) {
|
||||
std::cerr << "\x1b[1;31mInternal Error:\x1b[0m " << message << " at ";
|
||||
print_position(std::cerr, node.get_start_point(), node.get_end_point());
|
||||
std::cerr << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ private:
|
|||
|
||||
class FunctionDefinition : public Node {
|
||||
public:
|
||||
enum ModifierType {
|
||||
enum MethodModifier {
|
||||
STATIC,
|
||||
LET,
|
||||
VAR,
|
||||
|
|
@ -237,12 +237,13 @@ public:
|
|||
|
||||
FunctionDefinition(Node node, SymbolDocs &&docs,
|
||||
std::vector<Constraint> &&constraints,
|
||||
ModifierType modifier, const Identifier &name,
|
||||
std::vector<Argument> &&arguments,
|
||||
Modifier return_modifier, MethodModifier method_modifier,
|
||||
const Identifier &name, std::vector<Argument> &&arguments,
|
||||
bool are_annotations_same_to_names,
|
||||
std::optional<ExpressionProxy> expression)
|
||||
: Node(node), docs_(std::move(docs)),
|
||||
constraints_(std::move(constraints)), modifier_(modifier), name_(name),
|
||||
constraints_(std::move(constraints)), return_modifier_(return_modifier),
|
||||
method_modifier_(method_modifier), name_(name),
|
||||
arguments_(std::move(arguments)),
|
||||
are_annotations_same_to_names_(are_annotations_same_to_names),
|
||||
expression_(expression) {}
|
||||
|
|
@ -265,7 +266,9 @@ public:
|
|||
|
||||
//
|
||||
|
||||
ModifierType get_modifier() const { return modifier_; }
|
||||
Modifier get_return_modifier() const { return return_modifier_; }
|
||||
|
||||
MethodModifier get_method_modifier() const { return method_modifier_; }
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -312,7 +315,8 @@ public:
|
|||
private:
|
||||
SymbolDocs docs_;
|
||||
std::vector<Constraint> constraints_;
|
||||
ModifierType modifier_;
|
||||
Modifier return_modifier_;
|
||||
MethodModifier method_modifier_;
|
||||
Identifier name_;
|
||||
std::vector<Argument> arguments_;
|
||||
bool are_annotations_same_to_names_; // needed for easier prinitng process
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue