Renames project.
This commit is contained in:
51
src/Parser/Statements/ParsedStatement.hpp
Normal file
51
src/Parser/Statements/ParsedStatement.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||
#define MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "../../TextSpan.hpp"
|
||||
#include "ParsedStatementKind.hpp"
|
||||
namespace MalachScript::Parser {
|
||||
class ParsedStatement {
|
||||
TextSpan _span;
|
||||
|
||||
public:
|
||||
ParsedStatement(TextSpan span) : _span(span) {}
|
||||
[[nodiscard]] virtual ParsedStatementKind GetKind() const noexcept = 0;
|
||||
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
||||
};
|
||||
|
||||
template <ParsedStatementKind kind> class ParsedStatementImpl : public ParsedStatement {
|
||||
public:
|
||||
ParsedStatementImpl(TextSpan span) : ParsedStatement(span) {}
|
||||
[[nodiscard]] inline ParsedStatementKind GetKind() const noexcept override { return kind; }
|
||||
};
|
||||
|
||||
class ParsedBlockStatement : public ParsedStatementImpl<ParsedStatementKind::Block> {
|
||||
std::vector<std::unique_ptr<const ParsedStatement>> _statements;
|
||||
|
||||
public:
|
||||
ParsedBlockStatement(TextSpan span, const std::vector<const ParsedStatement*>& statements)
|
||||
: ParsedStatementImpl<ParsedStatementKind::Block>(span), _statements(statements.size()) {
|
||||
for (size_t i = 0; i < statements.size(); i++)
|
||||
_statements[i] = std::unique_ptr<const ParsedStatement>(statements[i]);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const std::vector<std::unique_ptr<const ParsedStatement>>& GetStatements() const noexcept {
|
||||
return _statements;
|
||||
}
|
||||
};
|
||||
|
||||
class ParsedScriptStatement : public ParsedStatementImpl<ParsedStatementKind::Script> {
|
||||
std::unique_ptr<const ParsedBlockStatement> _block;
|
||||
|
||||
public:
|
||||
ParsedScriptStatement(const ParsedBlockStatement* block)
|
||||
: ParsedStatementImpl<ParsedStatementKind::Script>(block->GetSpan()), _block(block) {}
|
||||
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedBlockStatement>& GetBlock() const noexcept {
|
||||
return _block;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||
Reference in New Issue
Block a user