Removed statement invalid
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
#include "Parser/Statement/StatementMetaExternFunction.h"
|
#include "Parser/Statement/StatementMetaExternFunction.h"
|
||||||
#include "Parser/Statement/StatementBlock.h"
|
#include "Parser/Statement/StatementBlock.h"
|
||||||
#include "Parser/Statement/StatementRepeat.h"
|
#include "Parser/Statement/StatementRepeat.h"
|
||||||
#include "Parser/Statement/StatementInvalid.h"
|
|
||||||
|
|
||||||
Parser::Parser(vector<shared_ptr<Token>> tokens): tokens(tokens) {
|
Parser::Parser(vector<shared_ptr<Token>> tokens): tokens(tokens) {
|
||||||
}
|
}
|
||||||
@@ -246,7 +245,6 @@ shared_ptr<Statement> Parser::matchStatementFunction() {
|
|||||||
markError(TokenKind::SEMICOLON, {});
|
markError(TokenKind::SEMICOLON, {});
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
//return matchStatementInvalid("Expected a \";\" after a function declaration");
|
|
||||||
|
|
||||||
return make_shared<StatementFunction>(name, arguments, returnType, dynamic_pointer_cast<StatementBlock>(statementBlock));
|
return make_shared<StatementFunction>(name, arguments, returnType, dynamic_pointer_cast<StatementBlock>(statementBlock));
|
||||||
}
|
}
|
||||||
@@ -311,8 +309,6 @@ shared_ptr<Statement> Parser::matchStatementRepeat() {
|
|||||||
|
|
||||||
// initial
|
// initial
|
||||||
initStatement = matchStatementVariable() ?: matchStatementAssignment();
|
initStatement = matchStatementVariable() ?: matchStatementAssignment();
|
||||||
if (initStatement != nullptr && !initStatement->isValid())
|
|
||||||
initStatement = nullptr;
|
|
||||||
|
|
||||||
if (!tryMatchingTokenKinds({TokenKind::COLON}, false, true)) {
|
if (!tryMatchingTokenKinds({TokenKind::COLON}, false, true)) {
|
||||||
// got initial, expect comma
|
// got initial, expect comma
|
||||||
@@ -369,8 +365,6 @@ shared_ptr<Statement> Parser::matchStatementExpression() {
|
|||||||
|
|
||||||
if (expression == nullptr)
|
if (expression == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
else if (!expression->isValid())
|
|
||||||
return make_shared<StatementInvalid>(tokens.at(currentIndex), "");// expression->toString(0));
|
|
||||||
|
|
||||||
return make_shared<StatementExpression>(expression);
|
return make_shared<StatementExpression>(expression);
|
||||||
}
|
}
|
||||||
@@ -601,8 +595,10 @@ shared_ptr<Expression> Parser::matchExpressionBlock(vector<TokenKind> terminalTo
|
|||||||
|
|
||||||
while (!tryMatchingTokenKinds(terminalTokenKinds, false, false)) {
|
while (!tryMatchingTokenKinds(terminalTokenKinds, false, false)) {
|
||||||
shared_ptr<Statement> statement = nextInBlockStatement();
|
shared_ptr<Statement> statement = nextInBlockStatement();
|
||||||
if (statement == nullptr || !statement->isValid())
|
if (statement == nullptr) {
|
||||||
return matchExpressionInvalid("Expected statement");
|
markError({}, "Expected statement");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
statements.push_back(statement);
|
statements.push_back(statement);
|
||||||
|
|
||||||
if (tryMatchingTokenKinds(terminalTokenKinds, false, false))
|
if (tryMatchingTokenKinds(terminalTokenKinds, false, false))
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ class Expression;
|
|||||||
class ExpressionInvalid;
|
class ExpressionInvalid;
|
||||||
|
|
||||||
class Statement;
|
class Statement;
|
||||||
class StatementInvalid;
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,3 @@ kind(kind) { }
|
|||||||
StatementKind Statement::getKind() {
|
StatementKind Statement::getKind() {
|
||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Statement::isValid() {
|
|
||||||
return kind != StatementKind::INVALID;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ enum class StatementKind {
|
|||||||
VARIABLE,
|
VARIABLE,
|
||||||
ASSIGNMENT,
|
ASSIGNMENT,
|
||||||
REPEAT,
|
REPEAT,
|
||||||
META_EXTERN_FUNCTION,
|
META_EXTERN_FUNCTION
|
||||||
INVALID
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Statement {
|
class Statement {
|
||||||
@@ -27,7 +26,6 @@ public:
|
|||||||
Statement(StatementKind kind);
|
Statement(StatementKind kind);
|
||||||
virtual ~Statement() { }
|
virtual ~Statement() { }
|
||||||
StatementKind getKind();
|
StatementKind getKind();
|
||||||
bool isValid();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#include "Parser/Statement/StatementInvalid.h"
|
|
||||||
|
|
||||||
#include "Lexer/Token.h"
|
|
||||||
|
|
||||||
StatementInvalid::StatementInvalid(shared_ptr<Token> token, string message):
|
|
||||||
Statement(StatementKind::INVALID), token(token), message(message) { }
|
|
||||||
|
|
||||||
string StatementInvalid::getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#include "Parser/Statement/Statement.h"
|
|
||||||
|
|
||||||
class Token;
|
|
||||||
|
|
||||||
class StatementInvalid: public Statement {
|
|
||||||
private:
|
|
||||||
shared_ptr<Token> token;
|
|
||||||
string message;
|
|
||||||
|
|
||||||
public:
|
|
||||||
StatementInvalid(shared_ptr<Token> token, string message);
|
|
||||||
string getMessage();
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user