Better statement errors parsing

This commit is contained in:
Rafał Grodziński
2025-07-03 18:16:09 +09:00
parent e0081ee12b
commit f9ec29fee8
7 changed files with 261 additions and 69 deletions

View File

@@ -2,8 +2,11 @@
#define PARSER_H
#include <vector>
#include "Types.h"
#include "Lexer/Token.h"
class Token;
enum class TokenKind;
class Error;
class Expression;
class ExpressionInvalid;
@@ -17,6 +20,7 @@ class Parser {
private:
vector<shared_ptr<Token>> tokens;
int currentIndex = 0;
vector<shared_ptr<Error>> errors;
shared_ptr<Statement> nextStatement();
shared_ptr<Statement> nextInBlockStatement();
@@ -30,7 +34,6 @@ private:
shared_ptr<Statement> matchStatementReturn();
shared_ptr<Statement> matchStatementRepeat();
shared_ptr<Statement> matchStatementExpression();
shared_ptr<StatementInvalid> matchStatementInvalid(string message = "");
shared_ptr<Expression> nextExpression();
shared_ptr<Expression> matchEquality(); // =, !=
@@ -51,6 +54,8 @@ private:
bool tryMatchingTokenKinds(vector<TokenKind> kinds, bool shouldMatchAll, bool shouldAdvance);
optional<ValueType> valueTypeForToken(shared_ptr<Token> token);
void markError(optional<TokenKind> expectedTokenKind, optional<string> message);
public:
Parser(vector<shared_ptr<Token>> tokens);
vector<shared_ptr<Statement>> getStatements();