Skip to content

Commit 9adb369

Browse files
authored
fix: improved error messages (#224)
Currently, when the parser encounters an invalid keyword inside a function or a structure it gives an invalid function statement or invalid member definition error instead of stating that an invalid keyword was found. This was written as a response to the feature request of better error messages when loops are used inside structs but expands on it to include all possible invalid keywords
1 parent a9a93ab commit 9adb369

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/source/pl/core/parser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,9 @@ namespace pl::core {
970970
statement = parseFunctionVariableDecl();
971971
} else if (sequence(tkn::Keyword::Const)) {
972972
statement = parseFunctionVariableDecl(true);
973+
} else if (m_curr[0].type == Token::Type::Keyword) {
974+
errorHere("Invalid {} found in function.", getFormattedToken(0));
975+
return nullptr;
973976
} else {
974977
errorHere("Invalid function statement.");
975978
next();
@@ -1930,7 +1933,10 @@ namespace pl::core {
19301933
return parseTryCatchStatement([this] { return parseMember(); });
19311934
else if (oneOf(tkn::Keyword::Return, tkn::Keyword::Break, tkn::Keyword::Continue))
19321935
member = parseFunctionControlFlowStatement();
1933-
else {
1936+
else if (m_curr[0].type == Token::Type::Keyword) {
1937+
errorHere("Invalid {} found in struct.", getFormattedToken(0));
1938+
return nullptr;
1939+
} else {
19341940
errorHere("Invalid struct member definition.");
19351941
next();
19361942
return nullptr;

0 commit comments

Comments
 (0)