1
0
mirror of synced 2024-11-28 09:30:51 +01:00

Revert pattern language until it's stable again (#1468)

- Revert pattern language
This commit is contained in:
Justus Garbe 2023-12-21 22:01:07 +01:00 committed by GitHub
parent ffc1aa6a91
commit ad8e3e38f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 23 deletions

@ -1 +1 @@
Subproject commit cbfcf0f1848e4283e00f7a6820ef54fdaaf74dd8 Subproject commit 312dc93becd44f24105baad2574b8449f449e831

View File

@ -5,6 +5,7 @@
#include <list> #include <list>
#include <memory> #include <memory>
#include <mutex>
namespace hex { namespace hex {

View File

@ -88,7 +88,7 @@ namespace hex::plugin::builtin::ui {
std::optional<pl::core::Token::Literal> value; std::optional<pl::core::Token::Literal> value;
}; };
std::optional<Filter> parseRValueFilter(pl::PatternLanguage *runtime, const std::string &filter) const; std::optional<Filter> parseRValueFilter(const std::string &filter) const;
private: private:
std::map<const pl::ptrn::Pattern*, u64> m_displayEnd; std::map<const pl::ptrn::Pattern*, u64> m_displayEnd;

View File

@ -133,7 +133,7 @@ namespace hex::plugin::builtin {
// Execute the inspector file // Execute the inspector file
if (!inspectorCode.empty()) { 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 // Loop over patterns produced by the runtime
const auto &patterns = m_runtime.getPatterns(); const auto &patterns = m_runtime.getPatterns();

View File

@ -857,13 +857,14 @@ namespace hex::plugin::builtin {
if (!file.isValid()) if (!file.isValid())
continue; continue;
auto &preprocessor = runtime.getInternals().preprocessor; try {
auto &preprocessor = runtime.getInternals().preprocessor;
auto source = runtime.addVirtualSource(file.readString(), wolv::util::toUTF8String(file.getPath())); auto ret = preprocessor->preprocess(runtime, file.readString());
if (!ret.has_value()) {
auto result = preprocessor->preprocess(&runtime, source); log::warn("Failed to preprocess file {} during MIME analysis: {}", entry.path().string(), preprocessor->getError()->what());
if (result.hasErrs()) { }
log::warn("Failed to preprocess file {} during MIME analysis", entry.path().string()); } catch (pl::core::err::PreprocessorError::Exception &e) {
log::warn("Failed to preprocess file {} during MIME analysis: {}", entry.path().string(), e.what());
} }
if (foundCorrectType) if (foundCorrectType)
@ -959,7 +960,7 @@ namespace hex::plugin::builtin {
m_runningParsers += 1; m_runningParsers += 1;
ContentRegistry::PatternLanguage::configureRuntime(*m_parserRuntime, nullptr); 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); 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) { if (!m_lastEvaluationResult) {
*m_lastEvaluationError = runtime.getError(); *m_lastEvaluationError = runtime.getError();
} }

View File

@ -150,7 +150,7 @@ namespace hex::plugin::builtin::ui {
} }
std::optional<PatternDrawer::Filter> PatternDrawer::parseRValueFilter(pl::PatternLanguage *runtime, const std::string &filter) const { std::optional<PatternDrawer::Filter> PatternDrawer::parseRValueFilter(const std::string &filter) const {
Filter result; Filter result;
if (filter.empty()) { if (filter.empty()) {
@ -162,16 +162,22 @@ namespace hex::plugin::builtin::ui {
char c = filter[i]; char c = filter[i];
if (i < filter.size() - 1 && c == '=' && filter[i + 1] == '=') { if (i < filter.size() - 1 && c == '=' && filter[i + 1] == '=') {
auto tokens = runtime->lexString(filter.substr(i + 2), pl::api::Source::DefaultSource); try {
if (!tokens.has_value()) 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<pl::core::Token::Literal>(&tokens->front().value);
if (literal == nullptr)
return std::nullopt;
result.value = *literal;
} catch (pl::core::err::LexerError &) {
return std::nullopt; return std::nullopt;
}
auto literal = std::get_if<pl::core::Token::Literal>(&tokens->front().value);
if (literal == nullptr)
return std::nullopt;
result.value = *literal;
break; break;
} else if (c == '.') } else if (c == '.')
result.path.emplace_back(); result.path.emplace_back();
@ -1102,7 +1108,7 @@ namespace hex::plugin::builtin::ui {
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 9.5); ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 9.5);
if (ImGuiExt::InputTextIcon("##Search", ICON_VS_FILTER, m_filterText)) { 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(); ImGui::PopItemWidth();