Fixed parser

This commit is contained in:
Rafał Grodziński
2025-07-08 19:20:31 +09:00
parent b980fd8753
commit 1c19600430
3 changed files with 15 additions and 9 deletions

12
.gitignore vendored
View File

@@ -1,6 +1,12 @@
.DS_Store
# ignore files without extensions
*
!*.*
# brb build artifiacts
*.o
brb
.DS_Store
.vscode/settings.json
# project build artifacts
*.dSYM
build/
build/

2
.vscode/launch.json vendored
View File

@@ -6,7 +6,7 @@
"type": "lldb-dap",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": ["-v", "${workspaceFolder}/test.brc"],
"args": ["-v", "${workspaceFolder}/samples/test.brc"],
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
}

View File

@@ -122,7 +122,7 @@ shared_ptr<Statement> Parser::matchStatementMetaExternFunction() {
return nullptr;
}
shared_ptr<Token> identifierToken = tokens.at(currentIndex++);
shared_ptr<Token> argumentTypeToken = tokens.at(currentIndex++);
//shared_ptr<Token> argumentTypeToken = tokens.at(currentIndex++);
shared_ptr<ValueType> argumentType = matchValueType();
if (argumentType == nullptr) {
markError(TokenKind::TYPE, {});
@@ -143,8 +143,6 @@ shared_ptr<Statement> Parser::matchStatementMetaExternFunction() {
markError(TokenKind::TYPE, {});
return nullptr;
}
currentIndex++; // type
}
return make_shared<StatementMetaExternFunction>(identifierToken->getLexme(), arguments, returnType);
@@ -192,7 +190,6 @@ shared_ptr<Statement> Parser::matchStatementFunction() {
return nullptr;
}
shared_ptr<Token> identifierToken = tokens.at(currentIndex++);
shared_ptr<Token> argumentTypeToken = tokens.at(currentIndex++);
shared_ptr<ValueType> argumentType = matchValueType();
if (argumentType == nullptr) {
markError(TokenKind::TYPE, {});
@@ -207,7 +204,6 @@ shared_ptr<Statement> Parser::matchStatementFunction() {
if (tryMatchingTokenKinds({TokenKind::RIGHT_ARROW}, true, true)) {
tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true); // skip new line
//shared_ptr<Token> returnTypeToken = tokens.at(currentIndex);
returnType = matchValueType();
if (returnType == nullptr) {
markError(TokenKind::TYPE, {});
@@ -703,5 +699,9 @@ void Parser::markError(optional<TokenKind> expectedTokenKind, optional<string> m
while (!tryMatchingTokenKinds(safeKinds, false, true))
currentIndex++;
// Last END should not be consumed
if (currentIndex > tokens.size() - 1)
currentIndex = tokens.size() - 1;
errors.push_back(Error::parserError(actualToken, expectedTokenKind, message));
}