Added validator to catch more syntax errors in pattern code

This commit is contained in:
WerWolv
2020-11-16 22:54:39 +01:00
parent 896cad1fe0
commit c863b2f65b
5 changed files with 100 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
#include <random>
#include "views/view_pattern.hpp"
#include <random>
#include "parser/parser.hpp"
#include "parser/lexer.hpp"
#include "parser/validator.hpp"
#include "utils.hpp"
namespace hex {
@@ -111,6 +114,7 @@ namespace hex {
void ViewPattern::parsePattern(char *buffer) {
static hex::lang::Lexer lexer;
static hex::lang::Parser parser;
static hex::lang::Validator validator;
this->clearPatternData();
this->postEvent(Events::PatternChanged);
@@ -127,6 +131,12 @@ namespace hex {
return;
}
auto validatorResult = validator.validate(ast);
if (!validatorResult) {
for(auto &node : ast) delete node;
return;
}
for (auto &varNode : findNodes<lang::ASTNodeVariableDecl>(lang::ASTNode::Type::VariableDecl, ast)) {
if (!varNode->getOffset().has_value())
continue;