diff --git a/lib/external/pattern_language b/lib/external/pattern_language index cbfcf0f18..312dc93be 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit cbfcf0f1848e4283e00f7a6820ef54fdaaf74dd8 +Subproject commit 312dc93becd44f24105baad2574b8449f449e831 diff --git a/lib/libimhex/include/hex/ui/toast.hpp b/lib/libimhex/include/hex/ui/toast.hpp index 1d99a8801..905c233a2 100644 --- a/lib/libimhex/include/hex/ui/toast.hpp +++ b/lib/libimhex/include/hex/ui/toast.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace hex { diff --git a/plugins/builtin/include/ui/pattern_drawer.hpp b/plugins/builtin/include/ui/pattern_drawer.hpp index f377ef0df..12e2ced2f 100644 --- a/plugins/builtin/include/ui/pattern_drawer.hpp +++ b/plugins/builtin/include/ui/pattern_drawer.hpp @@ -88,7 +88,7 @@ namespace hex::plugin::builtin::ui { std::optional value; }; - std::optional parseRValueFilter(pl::PatternLanguage *runtime, const std::string &filter) const; + std::optional parseRValueFilter(const std::string &filter) const; private: std::map m_displayEnd; diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 4fa24ea5d..890825ef5 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -133,7 +133,7 @@ namespace hex::plugin::builtin { // Execute the inspector file if (!inspectorCode.empty()) { - if (m_runtime.executeString(inspectorCode, pl::api::Source::DefaultSource, {}, inVariables, true)) { + if (m_runtime.executeString(inspectorCode, {}, inVariables, true)) { // Loop over patterns produced by the runtime const auto &patterns = m_runtime.getPatterns(); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 9fdafe347..0d69dc326 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -857,13 +857,14 @@ namespace hex::plugin::builtin { if (!file.isValid()) continue; - auto &preprocessor = runtime.getInternals().preprocessor; - - auto source = runtime.addVirtualSource(file.readString(), wolv::util::toUTF8String(file.getPath())); - - auto result = preprocessor->preprocess(&runtime, source); - if (result.hasErrs()) { - log::warn("Failed to preprocess file {} during MIME analysis", entry.path().string()); + try { + auto &preprocessor = runtime.getInternals().preprocessor; + auto ret = preprocessor->preprocess(runtime, file.readString()); + if (!ret.has_value()) { + log::warn("Failed to preprocess file {} during MIME analysis: {}", entry.path().string(), preprocessor->getError()->what()); + } + } catch (pl::core::err::PreprocessorError::Exception &e) { + log::warn("Failed to preprocess file {} during MIME analysis: {}", entry.path().string(), e.what()); } if (foundCorrectType) @@ -959,7 +960,7 @@ namespace hex::plugin::builtin { m_runningParsers += 1; ContentRegistry::PatternLanguage::configureRuntime(*m_parserRuntime, nullptr); - auto ast = m_parserRuntime->parseString(code, pl::api::Source::DefaultSource); + auto ast = m_parserRuntime->parseString(code); auto &patternVariables = m_patternVariables.get(provider); @@ -1087,7 +1088,7 @@ namespace hex::plugin::builtin { }; - m_lastEvaluationResult = runtime.executeString(code, pl::api::Source::DefaultSource, envVars, inVariables); + m_lastEvaluationResult = runtime.executeString(code, envVars, inVariables); if (!m_lastEvaluationResult) { *m_lastEvaluationError = runtime.getError(); } diff --git a/plugins/builtin/source/ui/pattern_drawer.cpp b/plugins/builtin/source/ui/pattern_drawer.cpp index e2315e2ed..631aafe4e 100644 --- a/plugins/builtin/source/ui/pattern_drawer.cpp +++ b/plugins/builtin/source/ui/pattern_drawer.cpp @@ -150,7 +150,7 @@ namespace hex::plugin::builtin::ui { } - std::optional PatternDrawer::parseRValueFilter(pl::PatternLanguage *runtime, const std::string &filter) const { + std::optional PatternDrawer::parseRValueFilter(const std::string &filter) const { Filter result; if (filter.empty()) { @@ -162,16 +162,22 @@ namespace hex::plugin::builtin::ui { char c = filter[i]; if (i < filter.size() - 1 && c == '=' && filter[i + 1] == '=') { - auto tokens = runtime->lexString(filter.substr(i + 2), pl::api::Source::DefaultSource); - if (!tokens.has_value()) + try { + pl::core::Lexer lexer; + + auto source = filter.substr(i + 2); + auto tokens = lexer.lex(filter.substr(i + 2), filter.substr(i + 2)); + + if (!tokens.has_value() || tokens->size() != 2) + return std::nullopt; + + auto literal = std::get_if(&tokens->front().value); + if (literal == nullptr) + return std::nullopt; + result.value = *literal; + } catch (pl::core::err::LexerError &) { return std::nullopt; - - auto literal = std::get_if(&tokens->front().value); - if (literal == nullptr) - return std::nullopt; - - result.value = *literal; - + } break; } else if (c == '.') result.path.emplace_back(); @@ -1102,7 +1108,7 @@ namespace hex::plugin::builtin::ui { ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 9.5); if (ImGuiExt::InputTextIcon("##Search", ICON_VS_FILTER, m_filterText)) { - m_filter = parseRValueFilter(runtime, m_filterText).value_or(Filter{ }); + m_filter = parseRValueFilter(m_filterText).value_or(Filter{ }); } ImGui::PopItemWidth();