Renames project.

This commit is contained in:
2020-10-05 17:45:00 +02:00
parent 125bb8459c
commit f299d5183f
23 changed files with 197 additions and 67 deletions

View File

@@ -1,11 +1,11 @@
#ifndef ELOHIMSCRIPT_DIAGNOSTIC_HPP
#define ELOHIMSCRIPT_DIAGNOSTIC_HPP
#ifndef MALACHSCRIPT_DIAGNOSTIC_HPP
#define MALACHSCRIPT_DIAGNOSTIC_HPP
#include "../TextSpan.hpp"
#include "DiagnosticLevel.hpp"
#include "DiagnosticType.hpp"
namespace ElohimScript::Diagnostics {
namespace MalachScript::Diagnostics {
class Diagnostic {
DiagnosticLevel _level;
DiagnosticType _type;
@@ -24,4 +24,4 @@ namespace ElohimScript::Diagnostics {
};
}
#endif // ELOHIMSCRIPT_DIAGNOSTIC_HPP
#endif // MALACHSCRIPT_DIAGNOSTIC_HPP

View File

@@ -1,8 +1,8 @@
#ifndef ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
#define ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
#ifndef MALACHSCRIPT_DIAGNOSTICLEVEL_HPP
#define MALACHSCRIPT_DIAGNOSTICLEVEL_HPP
#include <cstdint>
namespace ElohimScript::Diagnostics {
namespace MalachScript::Diagnostics {
enum class DiagnosticLevel : uint8_t {
Trace,
Information,
@@ -12,4 +12,4 @@ namespace ElohimScript::Diagnostics {
};
}
#endif // ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
#endif // MALACHSCRIPT_DIAGNOSTICLEVEL_HPP

View File

@@ -1,8 +1,8 @@
#ifndef ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
#define ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
#ifndef MALACHSCRIPT_DIAGNOSTICTYPE_HPP
#define MALACHSCRIPT_DIAGNOSTICTYPE_HPP
#include <string>
namespace ElohimScript::Diagnostics {
namespace MalachScript::Diagnostics {
enum class DiagnosticType : uint8_t { UnknownToken, InvalidNumericalBase, ExpectedEndOfString };
class DiagnosticTypeHelper {
@@ -17,4 +17,4 @@ namespace ElohimScript::Diagnostics {
};
}
#endif // ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
#endif // MALACHSCRIPT_DIAGNOSTICTYPE_HPP

View File

@@ -1,10 +1,10 @@
#ifndef ELOHIMSCRIPT_DIAGNOSTICS_HPP
#define ELOHIMSCRIPT_DIAGNOSTICS_HPP
#ifndef MALACHSCRIPT_DIAGNOSTICS_HPP
#define MALACHSCRIPT_DIAGNOSTICS_HPP
#include <vector>
#include "Diagnostic.hpp"
namespace ElohimScript::Diagnostics {
namespace MalachScript::Diagnostics {
class Diagnostics {
std::vector<Diagnostic> _messages;
@@ -32,4 +32,4 @@ namespace ElohimScript::Diagnostics {
};
}
#endif // ELOHIMSCRIPT_DIAGNOSTICS_HPP
#endif // MALACHSCRIPT_DIAGNOSTICS_HPP

View File

@@ -0,0 +1,8 @@
#ifndef MALACHSCRIPT_PARSEDEXPERSSION_HPP
#define MALACHSCRIPT_PARSEDEXPERSSION_HPP
namespace MalachScript::Parser{
class ParsedExpression{};
}
#endif // MALACHSCRIPT_PARSEDEXPERSSION_HPP

View File

@@ -1,8 +1,8 @@
#ifndef ELOHIMSCRIPT_LEXRESULT_HPP
#define ELOHIMSCRIPT_LEXRESULT_HPP
#ifndef MALACHSCRIPT_LEXRESULT_HPP
#define MALACHSCRIPT_LEXRESULT_HPP
#include "LexToken.hpp"
namespace ElohimScript::Parser {
namespace MalachScript::Parser {
class LexResult {
public:
LexResult(const LexToken* first, const uint8_t* memoryMap) : _first(first), _memoryMap(memoryMap) {}
@@ -16,4 +16,4 @@ namespace ElohimScript::Parser {
};
}
#endif // ELOHIMSCRIPT_LEXRESULT_HPP
#endif // MALACHSCRIPT_LEXRESULT_HPP

View File

@@ -1,11 +1,11 @@
#ifndef ELOHIMSCRIPT_LEXTOKEN_HPP
#define ELOHIMSCRIPT_LEXTOKEN_HPP
#ifndef MALACHSCRIPT_LEXTOKEN_HPP
#define MALACHSCRIPT_LEXTOKEN_HPP
#include <memory>
#include <utility>
#include "LexTokenKind.hpp"
namespace ElohimScript::Parser {
namespace MalachScript::Parser {
class LexToken {
friend class Lexer;
@@ -62,4 +62,4 @@ namespace ElohimScript::Parser {
};
}
#endif // ELOHIMSCRIPT_LEXTOKEN_HPP
#endif // MALACHSCRIPT_LEXTOKEN_HPP

View File

@@ -1,8 +1,8 @@
#ifndef ELOHIMSCRIPT_LEXTOKENKIND_HPP
#define ELOHIMSCRIPT_LEXTOKENKIND_HPP
#ifndef MALACHSCRIPT_LEXTOKENKIND_HPP
#define MALACHSCRIPT_LEXTOKENKIND_HPP
#include <cstdint>
namespace ElohimScript::Parser {
namespace MalachScript::Parser {
enum class LexTokenKind : uint8_t {
Unknown,
EndOfFile,
@@ -136,4 +136,4 @@ namespace ElohimScript::Parser {
};
}
#endif // ELOHIMSCRIPT_LEXTOKENKIND_HPP
#endif // MALACHSCRIPT_LEXTOKENKIND_HPP

View File

@@ -3,7 +3,7 @@
#include <stdexcept>
#include "NumericalLexers.hpp"
namespace ElohimScript::Parser {
namespace MalachScript::Parser {
const LexToken* Lexer::Lex() {
auto* first = LexNext();
if (first->GetKind() == LexTokenKind::EndOfFile) {

View File

@@ -1,12 +1,12 @@
#ifndef ELOHIMSCRIPT_LEXER_HPP
#define ELOHIMSCRIPT_LEXER_HPP
#ifndef MALACHSCRIPT_LEXER_HPP
#define MALACHSCRIPT_LEXER_HPP
#include <string_view>
#include "../../Diagnostics/Diagnostics.hpp"
#include "../../Utils/MemoryAllocator.hpp"
#include "LexToken.hpp"
namespace ElohimScript::Parser {
namespace MalachScript::Parser {
class Lexer {
public:
Lexer(const char* scriptName, const char* script, Diagnostics::Diagnostics* diag)
@@ -65,4 +65,4 @@ namespace ElohimScript::Parser {
};
}
#endif // ELOHIMSCRIPT_LEXER_HPP
#endif // MALACHSCRIPT_LEXER_HPP

View File

@@ -1,5 +1,5 @@
#ifndef ELOHIMSCRIPT_NUMERICALLEXERS_HPP
#define ELOHIMSCRIPT_NUMERICALLEXERS_HPP
#ifndef MALACHSCRIPT_NUMERICALLEXERS_HPP
#define MALACHSCRIPT_NUMERICALLEXERS_HPP
#include <cstdint>
@@ -8,4 +8,4 @@ uint8_t LexHexadecimalValue(char8_t c);
uint8_t LexOctalValue(char8_t c);
uint8_t LexBinaryValue(char8_t c);
#endif // ELOHIMSCRIPT_NUMERICALLEXERS_HPP
#endif // MALACHSCRIPT_NUMERICALLEXERS_HPP

26
src/Parser/Parser.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "Parser.hpp"
namespace MalachScript::Parser {
ParsedScriptStatement* Parser::Parse() {
std::vector<const ParsedStatement*> statements(32);
size_t current = 0;
while (true) {
auto next = this->Consume();
if (next->GetKind() == LexTokenKind::EndOfFile) {
break;
}
statements[current] = this->ParseStatement(next);
current++;
}
statements.resize(current);
auto end = 0;
if (current > 0) {
end = statements.back()->GetSpan().GetEnd();
}
const auto* block = new ParsedBlockStatement(TextSpan(0, end), statements);
return new ParsedScriptStatement(block);
}
const ParsedStatement* Parser::ParseStatement(const LexToken* token) {
// If modifier (shared, external, private, protected, etc) push to buffer, continue
}
}

33
src/Parser/Parser.hpp Normal file
View File

@@ -0,0 +1,33 @@
#ifndef MALACHSCRIPT_PARSER_HPP
#define MALACHSCRIPT_PARSER_HPP
#include "Lexer/LexToken.hpp"
#include "Statements/ParsedStatement.hpp"
namespace MalachScript::Parser {
class Parser {
public:
Parser(const LexToken* firstToken) : _currentToken(firstToken) {}
ParsedScriptStatement* Parse();
private:
const LexToken* _currentToken;
inline const LexToken* Peek() {
if (_currentToken->GetKind() == LexTokenKind::EndOfFile) {
return _currentToken;
}
return _currentToken->GetNext().get();
}
inline const LexToken* Consume() {
if (_currentToken->GetKind() == LexTokenKind::EndOfFile) {
return _currentToken;
}
_currentToken = _currentToken->GetNext().get();
return _currentToken;
}
const ParsedStatement* ParseStatement(const LexToken* token);
};
}
#endif // MALACHSCRIPT_PARSER_HPP

View 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

View File

@@ -0,0 +1,12 @@
#ifndef MALACHSCRIPT_PARSEDSTATEMENTKIND_HPP
#define MALACHSCRIPT_PARSEDSTATEMENTKIND_HPP
namespace MalachScript::Parser {
enum class ParsedStatementKind{
Unknown,
Block,
Script,
};
}
#endif // MALACHSCRIPT_PARSEDSTATEMENTKIND_HPP

View File

@@ -1,8 +1,8 @@
#ifndef ELOHIMSCRIPT_TEXTSPAN_HPP
#define ELOHIMSCRIPT_TEXTSPAN_HPP
#ifndef MALACHSCRIPT_TEXTSPAN_HPP
#define MALACHSCRIPT_TEXTSPAN_HPP
#include <cstddef>
namespace ElohimScript {
namespace MalachScript {
class TextSpan {
size_t _start;
size_t _end;
@@ -16,4 +16,4 @@ namespace ElohimScript {
};
}
#endif // ELOHIMSCRIPT_TEXTSPAN_HPP
#endif // MALACHSCRIPT_TEXTSPAN_HPP

View File

@@ -1,11 +1,11 @@
#ifndef ELOHIMSCRIPT_MEMORYALLOCATOR_HPP
#define ELOHIMSCRIPT_MEMORYALLOCATOR_HPP
#ifndef MALACHSCRIPT_MEMORYALLOCATOR_HPP
#define MALACHSCRIPT_MEMORYALLOCATOR_HPP
#include <cstddef>
#include <cstdint>
#include <stdexcept>
namespace ElohimScript::Utils {
namespace MalachScript::Utils {
template <size_t initialSize, size_t steps>
class MemoryAllocator {
size_t _offset;
@@ -42,4 +42,4 @@ namespace ElohimScript::Utils {
};
}
#endif // ELOHIMSCRIPT_MEMORYALLOCATOR_HPP
#endif // MALACHSCRIPT_MEMORYALLOCATOR_HPP