Implements namespace statement.
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
}
|
||||
|
||||
namespace MalachScript::Parser {
|
||||
ParsedScriptStatement* Parser::Parse() {
|
||||
const ParsedScriptStatement* Parser::Parse() { return ParseScript(); }
|
||||
|
||||
const ParsedScriptStatement* Parser::ParseScript() {
|
||||
std::vector<const ParsedStatement*> statements;
|
||||
statements.reserve(32);
|
||||
size_t current = 0;
|
||||
@@ -26,7 +28,10 @@ namespace MalachScript::Parser {
|
||||
break;
|
||||
}
|
||||
const ParsedStatement* statement;
|
||||
if (ParseClass(statement)) {
|
||||
auto result = ParseClass(statement) || ParseNamespace(statement);
|
||||
if (!result) {
|
||||
// TODO: Log error
|
||||
continue;
|
||||
}
|
||||
statements.push_back(statement);
|
||||
current++;
|
||||
@@ -123,16 +128,28 @@ namespace MalachScript::Parser {
|
||||
|
||||
PROGRESS_TOKEN(_currentToken);
|
||||
Identifier defineTo;
|
||||
if (!ParseIdentifier(defineTo, _currentToken, encounteredErrors)) {
|
||||
LogError(Diagnostics::DiagnosticType::UnexpectedToken, _currentToken->GetSpan());
|
||||
}
|
||||
ParseIdentifier(defineTo, _currentToken, encounteredErrors);
|
||||
PROGRESS_TOKEN(_currentToken);
|
||||
EXPECT_TOKEN(_currentToken, SemicolonSymbol);
|
||||
PROGRESS_TOKEN(_currentToken);
|
||||
if (_currentToken->GetKind() != LexTokenKind::SemicolonSymbol) {
|
||||
LogError(Diagnostics::DiagnosticType::UnexpectedToken, _currentToken->GetSpan());
|
||||
}
|
||||
out = new ParsedTypeDefStatement(TextSpan(start, _currentToken->GetSpan().GetEnd()), defineTo, defineFrom);
|
||||
return true;
|
||||
}
|
||||
bool Parser::ParseNamespace(const ParsedStatement*& out) {
|
||||
if (_currentToken->GetKind() != LexTokenKind::NamespaceKeyword) {
|
||||
return false;
|
||||
}
|
||||
auto start = _currentToken->GetSpan().GetStart();
|
||||
PROGRESS_TOKEN(_currentToken);
|
||||
Identifier identifier;
|
||||
bool encounteredErrors = false;
|
||||
ParseIdentifier(identifier, _currentToken, encounteredErrors);
|
||||
auto script = ParseScript();
|
||||
auto end = _currentToken->GetSpan().GetEnd();
|
||||
PROGRESS_TOKEN(_currentToken);
|
||||
out = new ParsedNamespaceStatement(TextSpan(start, end), identifier, script);
|
||||
return true;
|
||||
}
|
||||
bool Parser::ParseVirtProp([[maybe_unused]] const ParsedStatement*& out) { return false; }
|
||||
bool Parser::ParseFunc([[maybe_unused]] const ParsedStatement*& out) { return false; }
|
||||
bool Parser::ParseVar([[maybe_unused]] const ParsedStatement*& out) { return false; }
|
||||
|
||||
Reference in New Issue
Block a user