changes for new grammar, fixes

This commit is contained in:
ProgramSnail 2023-06-03 19:01:03 +03:00
parent 91f9affadc
commit 3106a64949
35 changed files with 605 additions and 550 deletions

View file

@ -65,7 +65,7 @@ struct Constructor {
struct FunctionDeclaration {
std::vector<Parameter> parameters;
std::vector<interpreter::tokens::AnyType*> argument_types;
std::vector<interpreter::tokens::ExtendedScopedAnyType*> argument_types;
interpreter::tokens::FunctionDeclaration* node = nullptr;
};

View file

@ -212,13 +212,14 @@ struct FunctionType;
struct TupleType;
struct VariantType;
struct TypeExpression;
struct TypeExpression;
using WrappedTypeExpression = TypeExpression;
using Constructor = std::string;
// // ScopedAnyType <-> AnyType
using AnyType = std::variant<
std::unique_ptr<TypeExpression>,
std::unique_ptr<WrappedTypeExpression>,
std::unique_ptr<TupleType>,
std::unique_ptr<VariantType>,
std::unique_ptr<FunctionType>>;
@ -272,6 +273,8 @@ struct Namespace {
TypeIdentifier type;
NamespaceSources scope;
bool is_type_namespace = false; // TODO: use
std::optional<utils::IdType> link_type_id_;
std::optional<utils::IdType> link_typeclass_id_;
};
@ -292,7 +295,7 @@ struct AliasDefinitionStatement {
utils::AliasModifier modifier;
TypeIdentifier type;
std::vector<AbstractTypeIdentifier> parameters;
std::unique_ptr<TypeExpression> value;
std::unique_ptr<WrappedTypeExpression> value;
utils::IdType type_id_ = 0;
};
@ -516,7 +519,7 @@ struct FunctionCallExpression {
BaseNode base;
std::optional<std::variant<std::unique_ptr<SubExpressionToken>,
std::unique_ptr<TypeExpression>>> prefix;
std::unique_ptr<WrappedTypeExpression>>> prefix;
NameOrOperatorIdentifier name;
std::vector<std::unique_ptr<TypeExpression>> parameters;
std::vector<SubExpression> arguments;
@ -621,21 +624,21 @@ struct AnnotatedName {
struct FunctionType {
BaseNode base;
std::vector<ScopedAnyType> types;
std::vector<std::unique_ptr<ExtendedScopedAnyType>> types;
};
struct TupleType {
BaseNode base;
std::optional<Constructor> type;
std::optional<TypeIdentifier> type;
std::vector<std::pair<std::optional<NameIdentifier>, std::unique_ptr<ExtendedScopedAnyType>>> entities;
};
struct VariantType {
BaseNode base;
std::optional<Constructor> type;
std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors;
std::optional<TypeIdentifier> type;
std::vector<std::pair<std::optional<Constructor>, std::optional<std::unique_ptr<TupleType>>>> constructors;
};
struct ParametrizedType {

View file

@ -98,6 +98,7 @@ const std::string FunctionType = "function_type";
const std::string TupleType = "tuple_type";
const std::string VariantType = "variant_type";
const std::string TypeExpression = "type_expression";
const std::string WrappedTypeExpression = "wrapped_type_expression";
const std::string Constructor = "constructor";
const std::string AnyType = "any_type";
const std::string ScopedAnyType = "scoped_any_type";

View file

@ -105,23 +105,23 @@ inline std::optional<InternalType> ToInternalType(const std::string& type) {
}
switch (type[0]) {
case 'F':
if (type == "Float") { return InternalType::Float; }
case 'f':
if (type == "float") { return InternalType::Float; }
break;
case 'I':
if (type == "Int") { return InternalType::Int; }
case 'i':
if (type == "int") { return InternalType::Int; }
break;
case 'S':
if (type == "String") { return InternalType::String; }
case 's':
if (type == "string") { return InternalType::String; }
break;
case 'C':
if (type == "Char") { return InternalType::Char; }
case 'c':
if (type == "char") { return InternalType::Char; }
break;
case 'B':
if (type == "Bool") { return InternalType::Bool; }
case 'b':
if (type == "bool") { return InternalType::Bool; }
break;
case 'U':
if (type == "Unit") { return InternalType::Unit; }
case 'u':
if (type == "unit") { return InternalType::Unit; }
break;
default:
break;
@ -135,22 +135,22 @@ inline std::string ToString(InternalType type) {
switch (type) {
case InternalType::Float:
result = "Float";
result = "float";
break;
case InternalType::Int:
result = "Int";
result = "int";
break;
case InternalType::String:
result = "String";
result = "string";
break;
case InternalType::Char:
result = "Char";
result = "char";
break;
case InternalType::Bool:
result = "Bool";
result = "bool";
break;
case InternalType::Unit:
result = "Unit";
result = "unit";
break;
}
return result;
@ -187,7 +187,7 @@ class VariantType {
public:
VariantType() = default;
VariantType(const std::optional<std::string>& name,
const std::vector<TupleType>& constructors,
const std::vector<std::pair<std::string, std::optional<TupleType>>>& constructors,
std::optional<size_t> current_constructor)
: name_(name), constructors_(constructors), current_constructor_(current_constructor) {}
@ -199,7 +199,7 @@ public:
std::optional<utils::IdType> GetFieldType(const std::string& name,
const std::unordered_set<utils::IdType>& type_namespaces) const;
const std::vector<TupleType>& GetConstructors() const {
const std::vector<std::pair<std::string, std::optional<TupleType>>>& GetConstructors() const {
return constructors_;
}
@ -210,7 +210,7 @@ public:
std::string ToString() const;
private:
std::optional<std::string> name_;
std::vector<TupleType> constructors_;
std::vector<std::pair<std::string, std::optional<TupleType>>> constructors_;
std::optional<size_t> current_constructor_;
};

View file

@ -35,6 +35,8 @@ ValueType IsConstModifierToValueType(IsConstModifier modifier);
ValueType ClassInternalsModifierToValueType(ClassInternalsModifier modifier);
std::optional<char> ToEscapeSymbol(char symbol);
bool IsBuiltinFunction(const std::string& name);
template<typename T>