Adds parsing continue and break.

This commit is contained in:
Deukhoofd 2020-11-15 10:21:42 +01:00
parent 09023d6337
commit 0c8b9f3943
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 35 additions and 2 deletions

View File

@ -893,4 +893,24 @@ namespace MalachScript::Parser {
} }
return false; return false;
} }
bool Parser::ParseContinue(const ParsedStatement*& out, const LexToken*& currentToken) {
if (currentToken->GetKind() == LexTokenKind::ContinueKeyword) {
return false;
}
auto start = currentToken->GetSpan().GetStart();
PROGRESS_TOKEN(currentToken);
EXPECT_TOKEN(currentToken, SemicolonSymbol);
out = new ParsedContinueStatement(TextSpan(start, currentToken->GetSpan().GetEnd()));
return true;
}
bool Parser::ParseBreak(const ParsedStatement*& out, const LexToken*& currentToken) {
if (currentToken->GetKind() == LexTokenKind::BreakKeyword) {
return false;
}
auto start = currentToken->GetSpan().GetStart();
PROGRESS_TOKEN(currentToken);
EXPECT_TOKEN(currentToken, SemicolonSymbol);
out = new ParsedBreakStatement(TextSpan(start, currentToken->GetSpan().GetEnd()));
return true;
}
} }

View File

@ -146,8 +146,8 @@ namespace MalachScript::Parser {
bool ParseReturn(const ParsedStatement*& out, const LexToken*& currentToken); bool ParseReturn(const ParsedStatement*& out, const LexToken*& currentToken);
bool ParseExprStat(const ParsedStatement*& out, const LexToken*& currentToken); bool ParseExprStat(const ParsedStatement*& out, const LexToken*& currentToken);
// Continue bool ParseContinue(const ParsedStatement*& out, const LexToken*& currentToken);
// Break bool ParseBreak(const ParsedStatement*& out, const LexToken*& currentToken);
bool ParseIfStatement(const ParsedStatement*& out, const LexToken*& currentToken); bool ParseIfStatement(const ParsedStatement*& out, const LexToken*& currentToken);
// For // For

View File

@ -359,6 +359,17 @@ namespace MalachScript::Parser {
private: private:
std::unique_ptr<const ParsedStatement> _statement; std::unique_ptr<const ParsedStatement> _statement;
}; };
class ParsedContinueStatement : public ParsedStatementImpl<ParsedStatementKind::Continue> {
public:
ParsedContinueStatement(const TextSpan& span) : ParsedStatementImpl(span) {}
};
class ParsedBreakStatement : public ParsedStatementImpl<ParsedStatementKind::Continue> {
public:
ParsedBreakStatement(const TextSpan& span) : ParsedStatementImpl(span) {}
};
} }
#endif // MALACHSCRIPT_PARSEDSTATEMENT_HPP #endif // MALACHSCRIPT_PARSEDSTATEMENT_HPP

View File

@ -22,6 +22,8 @@ namespace MalachScript::Parser {
VarAccess, VarAccess,
Increment, Increment,
Decrement, Decrement,
Continue,
Break,
}; };
} }