Fixed parser
This commit is contained in:
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,6 +1,12 @@
|
|||||||
.DS_Store
|
# ignore files without extensions
|
||||||
|
*
|
||||||
|
!*.*
|
||||||
|
# brb build artifiacts
|
||||||
*.o
|
*.o
|
||||||
brb
|
|
||||||
|
.DS_Store
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
|
||||||
|
# project build artifacts
|
||||||
*.dSYM
|
*.dSYM
|
||||||
build/
|
build/
|
||||||
|
|||||||
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -6,7 +6,7 @@
|
|||||||
"type": "lldb-dap",
|
"type": "lldb-dap",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${command:cmake.launchTargetPath}",
|
"program": "${command:cmake.launchTargetPath}",
|
||||||
"args": ["-v", "${workspaceFolder}/test.brc"],
|
"args": ["-v", "${workspaceFolder}/samples/test.brc"],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ shared_ptr<Statement> Parser::matchStatementMetaExternFunction() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
shared_ptr<Token> identifierToken = tokens.at(currentIndex++);
|
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();
|
shared_ptr<ValueType> argumentType = matchValueType();
|
||||||
if (argumentType == nullptr) {
|
if (argumentType == nullptr) {
|
||||||
markError(TokenKind::TYPE, {});
|
markError(TokenKind::TYPE, {});
|
||||||
@@ -143,8 +143,6 @@ shared_ptr<Statement> Parser::matchStatementMetaExternFunction() {
|
|||||||
markError(TokenKind::TYPE, {});
|
markError(TokenKind::TYPE, {});
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentIndex++; // type
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_shared<StatementMetaExternFunction>(identifierToken->getLexme(), arguments, returnType);
|
return make_shared<StatementMetaExternFunction>(identifierToken->getLexme(), arguments, returnType);
|
||||||
@@ -192,7 +190,6 @@ shared_ptr<Statement> Parser::matchStatementFunction() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
shared_ptr<Token> identifierToken = tokens.at(currentIndex++);
|
shared_ptr<Token> identifierToken = tokens.at(currentIndex++);
|
||||||
shared_ptr<Token> argumentTypeToken = tokens.at(currentIndex++);
|
|
||||||
shared_ptr<ValueType> argumentType = matchValueType();
|
shared_ptr<ValueType> argumentType = matchValueType();
|
||||||
if (argumentType == nullptr) {
|
if (argumentType == nullptr) {
|
||||||
markError(TokenKind::TYPE, {});
|
markError(TokenKind::TYPE, {});
|
||||||
@@ -207,7 +204,6 @@ shared_ptr<Statement> Parser::matchStatementFunction() {
|
|||||||
if (tryMatchingTokenKinds({TokenKind::RIGHT_ARROW}, true, true)) {
|
if (tryMatchingTokenKinds({TokenKind::RIGHT_ARROW}, true, true)) {
|
||||||
tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true); // skip new line
|
tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true); // skip new line
|
||||||
|
|
||||||
//shared_ptr<Token> returnTypeToken = tokens.at(currentIndex);
|
|
||||||
returnType = matchValueType();
|
returnType = matchValueType();
|
||||||
if (returnType == nullptr) {
|
if (returnType == nullptr) {
|
||||||
markError(TokenKind::TYPE, {});
|
markError(TokenKind::TYPE, {});
|
||||||
@@ -703,5 +699,9 @@ void Parser::markError(optional<TokenKind> expectedTokenKind, optional<string> m
|
|||||||
while (!tryMatchingTokenKinds(safeKinds, false, true))
|
while (!tryMatchingTokenKinds(safeKinds, false, true))
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
|
|
||||||
|
// Last END should not be consumed
|
||||||
|
if (currentIndex > tokens.size() - 1)
|
||||||
|
currentIndex = tokens.size() - 1;
|
||||||
|
|
||||||
errors.push_back(Error::parserError(actualToken, expectedTokenKind, message));
|
errors.push_back(Error::parserError(actualToken, expectedTokenKind, message));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user