Skip to content

Commit

Permalink
regex
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed Jun 1, 2024
1 parent a911056 commit c7c837b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions include/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ namespace encoding {

}

namespace regex {
void match(WrenVM* vm);

void contains(WrenVM* vm);
}

} // namespace lib
8 changes: 8 additions & 0 deletions include/vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#include <unordered_map>
#include <wren.hpp>

#ifndef NDEBUG
#include <rang.hpp>
#define DEBUG_PRINT(...) std::cout << rang::fg::blue << "DEBUG " << rang::fg::reset << __VA_ARGS__ << std::endl;
#else
#define DEBUG_PRINT(...)
#endif


namespace vm {

size_t createVmMap(WrenVM* vm, const int& slot, const std::unordered_map<std::string, std::string>& entries);
Expand Down
27 changes: 16 additions & 11 deletions src/vm/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "vm.hpp"

#include <boost/format.hpp>
#include <meta.hpp>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
Expand All @@ -11,6 +10,7 @@
#include <filesystem>
#include <iostream>
#include <memory>
#include <meta.hpp>
#include <ostream>
#include <rang.hpp>
#include <stdexcept>
Expand Down Expand Up @@ -149,13 +149,10 @@ static void errorFn(WrenVM* vm, const WrenErrorType errorType, const char* modul
} else {
std::cerr << rang::fg::red << "Error: " << rang::fg::reset << msg << std::endl;
if (std::getenv("FAN_LIB") == nullptr) {
std::cerr << rang::fg::blue << "\nHELP: " << rang::fg::reset
<< "Fan requires the " << rang::fg::yellow << "FAN_LIB " << rang::fg::reset
<< "environment variable to be set with the path to Fan's standard library.\n"
<< "This is typically found in the " << rang::fg::yellow << "lang/ " << rang::fg::reset
<< "directory included in your installation.\n\n"
<< "export FAN_LIB=\"" << rang::fg::yellow << "/fake/path/to/replace"
<< rang::fg::reset << "/fan/lang\"" << std::endl;
std::cerr << rang::fg::blue << "\nHELP: " << rang::fg::reset << "Fan requires the " << rang::fg::yellow << "FAN_LIB " << rang::fg::reset
<< "environment variable to be set with the path to Fan's standard library.\n"
<< "This is typically found in the " << rang::fg::yellow << "lang/ " << rang::fg::reset << "directory included in your installation.\n\n"
<< "export FAN_LIB=\"" << rang::fg::yellow << "/fake/path/to/replace" << rang::fg::reset << "/fan/lang\"" << std::endl;
}
}
// Need to find a way to keep track of user source to print actual file name.
Expand Down Expand Up @@ -419,10 +416,18 @@ WrenForeignMethodFn bindForeignMethodFn(WrenVM* vm, const char* module, const ch
return lib::encoding::md_to_html;
}
}
}

// if (std::strcmp(className, "JSON") == 0) {
//
// }
if (std::strcmp(module, "std/regex") == 0) {
if (std::strcmp(className, "Regex") == 0) {
if (isStatic && std::strcmp(signature, "match(_,_,_)") == 0) {
return lib::regex::match;
}

if (isStatic && std::strcmp(signature, "contains(_,_,_)") == 0) {
return lib::regex::contains;
}
}
}

return nullptr;
Expand Down

0 comments on commit c7c837b

Please sign in to comment.