mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
Added validator to catch more syntax errors in pattern code
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user