Lots more tests for function statements, fixes several bugs.

This commit is contained in:
2020-10-10 16:04:59 +02:00
parent dcf143b1b2
commit f5baed48a9
3 changed files with 118 additions and 12 deletions

View File

@@ -300,8 +300,8 @@ namespace MalachScript::Parser {
}
while (currentToken != nullptr && currentToken->GetKind() == LexTokenKind::ColonColonSymbol) {
PROGRESS_TOKEN(currentToken);
const auto* n = currentToken;
PROGRESS_TOKEN(n);
if (ParseIdentifier(identifier, n)) {
PROGRESS_TOKEN(n);
if (n->GetKind() == LexTokenKind::ColonColonSymbol) {
@@ -341,12 +341,13 @@ namespace MalachScript::Parser {
}
while (true) {
parameters.emplace_back();
auto parameter = parameters.at(parameters.size() - 1);
auto& parameter = parameters.at(parameters.size() - 1);
if (!ParseType((const ParsedStatement*&)parameter.GetTypeStatement(), currentToken)) {
LogError(Diagnostics::DiagnosticType::UnexpectedToken, currentToken->GetSpan());
}
ParseTypeMod(parameter.GetTypeMod());
ParseIdentifier(parameter.GetIdentifier(), currentToken);
PROGRESS_TOKEN(currentToken);
if (currentToken->GetKind() != LexTokenKind::CommaSymbol) {
break;
}
@@ -390,14 +391,14 @@ namespace MalachScript::Parser {
case LexTokenKind::Int16Keyword: out = PrimitiveTypes::Int16Name(); return true;
case LexTokenKind::Int32Keyword: out = PrimitiveTypes::Int32Name(); return true;
case LexTokenKind::Int64Keyword: out = PrimitiveTypes::Int64Name(); return true;
case LexTokenKind::UintKeyword: PrimitiveTypes::UintName(); return true;
case LexTokenKind::Uint8Keyword: PrimitiveTypes::Uint8Name(); return true;
case LexTokenKind::Uint16Keyword: PrimitiveTypes::Uint16Name(); return true;
case LexTokenKind::Uint32Keyword: PrimitiveTypes::Uint32Name(); return true;
case LexTokenKind::Uint64Keyword: PrimitiveTypes::Uint64Name(); return true;
case LexTokenKind::FloatKeyword: PrimitiveTypes::FloatName(); return true;
case LexTokenKind::DoubleKeyword: PrimitiveTypes::DoubleName(); return true;
case LexTokenKind::BoolKeyword: PrimitiveTypes::BoolName(); return true;
case LexTokenKind::UintKeyword: out = PrimitiveTypes::UintName(); return true;
case LexTokenKind::Uint8Keyword: out = PrimitiveTypes::Uint8Name(); return true;
case LexTokenKind::Uint16Keyword: out = PrimitiveTypes::Uint16Name(); return true;
case LexTokenKind::Uint32Keyword: out = PrimitiveTypes::Uint32Name(); return true;
case LexTokenKind::Uint64Keyword: out = PrimitiveTypes::Uint64Name(); return true;
case LexTokenKind::FloatKeyword: out = PrimitiveTypes::FloatName(); return true;
case LexTokenKind::DoubleKeyword: out = PrimitiveTypes::DoubleName(); return true;
case LexTokenKind::BoolKeyword: out = PrimitiveTypes::BoolName(); return true;
default: return false;
}
}

View File

@@ -106,7 +106,7 @@ namespace MalachScript::Parser {
class ParsedParameter {
private:
const ParsedTypeStatement* _typeStatement = nullptr;
TypeMod _typeMod;
TypeMod _typeMod = TypeMod::None;
Identifier _identifier;
const ParsedExpression* _defaultExpression = nullptr;
@@ -132,6 +132,8 @@ namespace MalachScript::Parser {
public:
ParsedParamListStatement(TextSpan span, std::vector<ParsedParameter> parameters)
: ParsedStatementImpl<ParsedStatementKind::ParamList>(span), _parameters(std::move(parameters)){};
[[nodiscard]] const std::vector<ParsedParameter>& GetParameters() const noexcept { return _parameters; }
};
class ParsedFuncStatement : public ParsedStatementImpl<ParsedStatementKind::Func> {