Skip to content

Commit

Permalink
[#10] WIP: Got the regexes figured out, probably... but didn't have t…
Browse files Browse the repository at this point in the history
…ime to actually remove the version specs if we found a match.
  • Loading branch information
DaloLorn authored Jan 27, 2025
1 parent 3a4d60a commit 9222035
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions source/game/scripts/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

#define DISABLE_SCRIPT_CACHE

#define OSR_COMPILER_VERSION 1

namespace scripts {
extern void RegisterEarlyNetworkBinds(asIScriptEngine* engine);

Expand Down Expand Up @@ -368,6 +370,20 @@ void preloadScript(const std::string& filename) {
loadScript(filename, dummy);
}

bool matchesCompilerVersion(const std::string& minVersion, const std::string& maxVersion) {
if(std::strlen(minVersion)) {
const int version = std::stoi(minVersion);
if(OSR_COMPILER_VERSION < version)
return false;
}
if(std::strlen(maxVersion)) {
const int version = std::stoi(maxVersion);
if(OSR_COMPILER_VERSION > version)
return false;
}
return true;
}

threads::Mutex reg_compile_lock;

void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFiles = true) {
Expand All @@ -390,6 +406,9 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
reg_compile(pre_import_from, "^[ \t]*from[ \t]+([A-Za-z0-9._-]+)[ \t]+import[ \t]+([^;]+);");
reg_compile(pre_import_all, "^[ \t]*import[ \t]+(([A-Za-z0-9._-]|, )+);");
reg_compile(pre_export, "^[ \t]*export[ \t]+(([A-Za-z0-9._-]|,* )+);");
reg_compile(pre_osr_single_line, "(.*)///([0-9]*)-?([0-9]*)(.*)");
reg_compile(pre_osr_multi_open, "(.*)/\*\*([0-9]*)-?([0-9]*)(.*)");
reg_compile(pre_osr_multi_close, "(.*)[ \t]([0-9]*)-?([0-9]*)\*\*/(.*)");
reg_compile_lock.release();
reg_result match;

Expand Down Expand Up @@ -467,6 +486,17 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
}
}

// TODO: Figure out something a little better-optimized than always running
// three regexes on every line of code?
if(reg_match(line, match, pre_osr_single_line)) {
const std::string prefix = reg_str(line, match, 1);
const std::string postfix = reg_str(line, match, 4);
// TODO: Actually evaluate this bit here. The goal is to replace line with prefix+postfix if the spec matches.
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {

}
}

if(line[lineStart] == 'f' && reg_match(line, match, pre_import_from)) {
std::string mod = reg_str(line, match, 1);
std::string def = reg_str(line, match, 2);
Expand Down

0 comments on commit 9222035

Please sign in to comment.