mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-07 15:38:49 +00:00
expression builders finished, type builders started
This commit is contained in:
parent
6682e0beb1
commit
535d8d26c3
12 changed files with 909 additions and 76 deletions
|
|
@ -52,17 +52,23 @@ proxy_to_expr_optional(const std::optional<nodes::ExpressionProxy> &proxy) {
|
|||
} // namespace utils
|
||||
|
||||
// --- flow control
|
||||
|
||||
class Match : public Node {
|
||||
public:
|
||||
class Case : public Node {
|
||||
public:
|
||||
Case(Node node, bool match_left_with_right, ExpressionProxy value,
|
||||
enum CaseType {
|
||||
PATTERN_VALUE,
|
||||
VALUE_PATTERN,
|
||||
};
|
||||
|
||||
Case(Node node, CaseType case_type, ExpressionProxy value,
|
||||
std::optional<ExpressionProxy> condition = std::nullopt,
|
||||
std::optional<ExpressionProxy> expression = std::nullopt)
|
||||
: Node(node), match_left_with_right_(match_left_with_right),
|
||||
value_(value), condition_(condition), expression_(expression) {}
|
||||
: Node(node), case_type_(case_type), value_(value),
|
||||
condition_(condition), expression_(expression) {}
|
||||
|
||||
bool match_left_with_right() const { return match_left_with_right_; }
|
||||
CaseType case_type() const { return case_type_; }
|
||||
|
||||
Expression *get_value() { return value_.get(); }
|
||||
|
||||
|
|
@ -85,7 +91,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
bool match_left_with_right_;
|
||||
CaseType case_type_;
|
||||
ExpressionProxy value_;
|
||||
std::optional<ExpressionProxy> condition_;
|
||||
std::optional<ExpressionProxy> expression_;
|
||||
|
|
@ -212,6 +218,7 @@ private:
|
|||
};
|
||||
|
||||
// --- containers
|
||||
|
||||
class Container : public Node {
|
||||
public:
|
||||
enum ContainerType {
|
||||
|
|
@ -244,6 +251,7 @@ private:
|
|||
};
|
||||
|
||||
// --- modifiers
|
||||
|
||||
class Return : public Node {
|
||||
public:
|
||||
enum ReturnType {
|
||||
|
|
@ -337,10 +345,11 @@ private:
|
|||
class ModifierExpression : public Node {
|
||||
public:
|
||||
enum Modifier {
|
||||
REFERENCE, // <> x
|
||||
MOVE, // <- x
|
||||
IF_VALUE, // x?
|
||||
VALUE_OR_PANIC, // x!
|
||||
OUT, // -> x
|
||||
IN, // <- x
|
||||
REF, // <> x
|
||||
OR_FALSE, // x?
|
||||
OR_PANIC, // x!
|
||||
};
|
||||
|
||||
ModifierExpression(Node node, Modifier modifier, ExpressionProxy expression)
|
||||
|
|
@ -359,11 +368,16 @@ private:
|
|||
};
|
||||
|
||||
// --- other
|
||||
|
||||
class NameExpression : public Node {
|
||||
public:
|
||||
template <typename T>
|
||||
NameExpression(Node node, T &&name)
|
||||
: Node(node), name_(std::forward<T>(name)) {}
|
||||
|
||||
template <typename T, typename U, typename V>
|
||||
NameExpression(Node node, T &&name, U &&arguments = {},
|
||||
V &&prefix = std::nullopt, bool is_point_call = false)
|
||||
NameExpression(Node node, T &&name, U &&arguments, V &&prefix,
|
||||
bool is_point_call = false)
|
||||
: Node(node), name_(std::forward<T>(name)),
|
||||
arguments_(std::forward<U>(arguments)),
|
||||
prefix_(std::forward<V>(prefix)), is_point_call_(is_point_call) {}
|
||||
|
|
@ -372,19 +386,16 @@ public:
|
|||
|
||||
const std::string *get_name() const { return name_.get(); }
|
||||
|
||||
std::optional<std::pair<std::string *, std::string *>> get_prefix() {
|
||||
std::optional<const Type *> get_prefix() {
|
||||
if (prefix_.has_value()) {
|
||||
return std::pair<std::string *, std::string *>{
|
||||
prefix_.value().first.get(), prefix_.value().second.get()};
|
||||
return &prefix_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::pair<const std::string *, const std::string *>>
|
||||
get_prefix() const {
|
||||
std::optional<const Type *> get_prefix() const {
|
||||
if (prefix_.has_value()) {
|
||||
return std::pair<const std::string *, const std::string *>{
|
||||
prefix_.value().first.get(), prefix_.value().second.get()};
|
||||
return &prefix_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
@ -420,7 +431,7 @@ private:
|
|||
std::vector<std::pair<std::optional<std::string>, ExpressionProxy>>
|
||||
arguments_;
|
||||
// universal function call syntax
|
||||
std::optional<std::pair<Identifier, Identifier>> prefix_;
|
||||
std::optional<const Type> prefix_;
|
||||
// for static methods
|
||||
bool is_point_call_ = false; // x.f ... or f x ...
|
||||
};
|
||||
|
|
@ -429,7 +440,7 @@ private:
|
|||
template NameExpression::NameExpression(
|
||||
Node, Identifier &&,
|
||||
std::vector<std::pair<std::optional<std::string>, ExpressionProxy>> &&,
|
||||
std::optional<std::pair<Identifier, Identifier>> &&, bool);
|
||||
std::optional<const Type> &&, bool);
|
||||
|
||||
class Constructor : public Node {
|
||||
public:
|
||||
|
|
@ -546,7 +557,10 @@ private:
|
|||
ModifierExpression,
|
||||
|
||||
// --- other
|
||||
NameExpression, Constructor, Lambda
|
||||
NameExpression, Constructor, Lambda,
|
||||
|
||||
// --- literal
|
||||
Literal
|
||||
|
||||
>
|
||||
expression_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue