From a7c7fc3e28f0a90878b13fdedf9d5f23900c23eb Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 10 Oct 2020 18:35:31 +0200 Subject: [PATCH] Continue parsing paramslist until we've found the closing parenthesis --- src/Parser/Parser.cpp | 8 +++++++- tests/ParserTests/ParserIntegrationTests.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 8b60db8..7b3c0d2 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -353,8 +353,14 @@ namespace MalachScript::Parser { } PROGRESS_TOKEN(currentToken); } - if (currentToken->GetKind() != LexTokenKind::CloseParenthesisSymbol) { + while (currentToken->GetKind() != LexTokenKind::CloseParenthesisSymbol) { LogError(Diagnostics::DiagnosticType::UnexpectedToken, currentToken->GetSpan()); + if (currentToken->GetKind() == LexTokenKind::EndOfFile) { + break; + } + if (currentToken->GetKind() == LexTokenKind::SemicolonSymbol) { + break; + } } out = new ParsedParamListStatement(TextSpan(start, currentToken->GetSpan().GetEnd()), parameters); PROGRESS_TOKEN(currentToken); diff --git a/tests/ParserTests/ParserIntegrationTests.cpp b/tests/ParserTests/ParserIntegrationTests.cpp index 09dfc71..2751127 100644 --- a/tests/ParserTests/ParserIntegrationTests.cpp +++ b/tests/ParserTests/ParserIntegrationTests.cpp @@ -25,4 +25,10 @@ PARSE_TEST("Parse class with empty definition", "class foobar {}", { REQUIRE(diags.GetMessages().empty()); REQUIRE(script->GetStatements().size() == 1); REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Class); -}) \ No newline at end of file +}) + +PARSE_TEST("Parse function without definition", "void foobar(int8 par1, bool &in x);", { + REQUIRE(diags.GetMessages().empty()); + REQUIRE(script->GetStatements().size() == 1); + REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Func); +})