Pattern Language rewrite (#111)

* Initial parser rewrite effort

Lexer and Token cleanup, Parser started over

* Greatly improved parser syntax

* Reimplemented using declarations and variable placement parsing

* Added back unions and structs

* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)

* Code style improvement

* Implemented arrays and fixed memory issues

* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns

* Fixed builtin types, arrays and reimplemented strings

* Improved error messages

* Made character a distinct type, used for chars and strings

* Implemented padding, fixed arrays

* Added bitfields

* Added rvalue parsing, no evaluating yet

* Added .idea folder to gitignore

* Fixed build on MacOS

* Added custom implementation of integral concept if not available

* Rebased onto master

* Fixed array variable decl crash

* Added rvalues and dot syntax

* Lower case all pattern language error messages

* Fixed typo in variable name

* Fixed bug where preprocessor would not ignore commented out directives

* Reimplemented pointers

* Fixed rebase issues
This commit is contained in:
WerWolv
2021-01-02 20:27:11 +01:00
committed by GitHub
parent d510f8c7cf
commit 78ef07cf0f
21 changed files with 2204 additions and 1681 deletions

View File

@@ -26,7 +26,7 @@ namespace hex {
static std::pair<const char* const, size_t> builtInTypes[] = {
{ "u8", 1 }, { "u16", 2 }, { "u32", 4 }, { "u64", 8 }, { "u128", 16 },
{ "s8", 1 }, { "s16", 2 }, { "s32", 4 }, { "s64", 8 }, { "s128", 16 },
{ "float", 4 }, { "double", 8 }, { "padding", 1 }
{ "float", 4 }, { "double", 8 }, { "char", 1 }, { "padding", 1 }
};
for (const auto &[name, size] : builtInTypes) {
TextEditor::Identifier id;
@@ -251,17 +251,6 @@ namespace hex {
lang::PatternData::resetPalette();
}
template<derived_from<lang::ASTNode> T>
static std::vector<T*> findNodes(const lang::ASTNode::Type type, const std::vector<lang::ASTNode*> &nodes) {
std::vector<T*> result;
for (const auto & node : nodes)
if (node->getType() == type)
result.push_back(static_cast<T*>(node));
return result;
}
void ViewPattern::parsePattern(char *buffer) {
this->clearPatternData();
this->m_textEditor.SetErrorMarkers({ });
@@ -285,14 +274,14 @@ namespace hex {
});
preprocessor.addDefaultPragmaHandlers();
auto preprocesedCode = preprocessor.preprocess(buffer);
if (!preprocesedCode.has_value()) {
auto preprocessedCode = preprocessor.preprocess(buffer);
if (!preprocessedCode.has_value()) {
this->m_textEditor.SetErrorMarkers({ preprocessor.getError() });
return;
}
hex::lang::Lexer lexer;
auto tokens = lexer.lex(preprocesedCode.value());
auto tokens = lexer.lex(preprocessedCode.value());
if (!tokens.has_value()) {
this->m_textEditor.SetErrorMarkers({ lexer.getError() });
return;
@@ -302,11 +291,10 @@ namespace hex {
auto ast = parser.parse(tokens.value());
if (!ast.has_value()) {
this->m_textEditor.SetErrorMarkers({ parser.getError() });
printf("%d %s\n", parser.getError().first, parser.getError().second.c_str());
return;
}
hex::ScopeExit deleteAst([&ast]{ for(auto &node : ast.value()) delete node; });
SCOPE_EXIT( for(auto &node : ast.value()) delete node; );
hex::lang::Validator validator;
auto validatorResult = validator.validate(ast.value());
@@ -322,8 +310,8 @@ namespace hex {
this->m_textEditor.SetErrorMarkers({ evaluator.getError() });
return;
}
this->m_patternData = patternData.value();
this->m_patternData = patternData.value();
this->postEvent(Events::PatternChanged);
}