Skip to content

Commit 568163f

Browse files
authored
[#10] Let's try this again...
1 parent 70afff7 commit 568163f

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

source/game/scripts/manager.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
412412

413413

414414
for(auto iLine = lines.begin(), end = lines.end(); iLine != end; ++iLine) {
415-
std::string line = *iLine;
415+
const std::string& line = *iLine;
416416

417417
auto lineStart = line.find_first_not_of(" \t");
418418
if(lineStart == std::string::npos) {
@@ -487,39 +487,40 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
487487
// TODO: Figure out something a little better-optimized than always running
488488
// three regexes on every line of code?
489489
// On the bright side, we're only running them if we're in the right section...
490-
while(reg_match(line, match, pre_osr_single_line)) {
491-
const std::string prefix = reg_str(line, match, 1);
492-
const std::string postfix = reg_str(line, match, 4);
493-
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
494-
*iLine = prefix + postfix;
490+
std::string osrLine = line;
491+
while(reg_match(osrLine, match, pre_osr_single_line)) {
492+
const std::string prefix = reg_str(osrLine, match, 1);
493+
const std::string postfix = reg_str(osrLine, match, 4);
494+
if(matchesCompilerVersion(reg_str(osrLine, match, 2), reg_str(osrLine, match, 3))) {
495+
osrLine = prefix + postfix;
495496
}
496497
}
497-
while(reg_match(line, match, pre_osr_multi_open)) {
498-
const std::string prefix = reg_str(line, match, 1);
499-
const std::string postfix = reg_str(line, match, 4);
500-
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
501-
*iLine = prefix + postfix;
498+
while(reg_match(osrLine, match, pre_osr_multi_open)) {
499+
const std::string prefix = reg_str(osrLine, match, 1);
500+
const std::string postfix = reg_str(osrLine, match, 4);
501+
if(matchesCompilerVersion(reg_str(osrLine, match, 2), reg_str(osrLine, match, 3))) {
502+
osrLine = prefix + postfix;
502503
}
503504
}
504-
while(reg_match(line, match, pre_osr_multi_close)) {
505-
const std::string prefix = reg_str(line, match, 1);
506-
const std::string postfix = reg_str(line, match, 4);
507-
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
508-
*iLine = prefix + postfix;
505+
while(reg_match(osrLine, match, pre_osr_multi_close)) {
506+
const std::string prefix = reg_str(osrLine, match, 1);
507+
const std::string postfix = reg_str(osrLine, match, 4);
508+
if(matchesCompilerVersion(reg_str(osrLine, match, 2), reg_str(osrLine, match, 3))) {
509+
osrLine = prefix + postfix;
509510
}
510511
}
511512

512-
if(line[lineStart] == 'f' && reg_match(line, match, pre_import_from)) {
513-
std::string mod = reg_str(line, match, 1);
514-
std::string def = reg_str(line, match, 2);
513+
if(osrLine[lineStart] == 'f' && reg_match(osrLine, match, pre_import_from)) {
514+
std::string mod = reg_str(osrLine, match, 1);
515+
std::string def = reg_str(osrLine, match, 2);
515516

516517
fl.imports.insert(ImportSpec(mod, def));
517518
output += "\n";
518519
continue;
519520
}
520521

521-
if(line[lineStart] == 'i' && reg_match(line, match, pre_import_all)) {
522-
std::string mod = reg_str(line, match, 1);
522+
if(osrLine[lineStart] == 'i' && reg_match(osrLine, match, pre_import_all)) {
523+
std::string mod = reg_str(osrLine, match, 1);
523524

524525
if(mod.find(",") != std::string::npos) {
525526
std::vector<std::string> modules;
@@ -536,8 +537,8 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
536537
continue;
537538
}
538539

539-
if(line[lineStart] == 'e' && reg_match(line, match, pre_export)) {
540-
std::string sym = reg_str(line, match, 1);
540+
if(osrLine[lineStart] == 'e' && reg_match(osrLine, match, pre_export)) {
541+
std::string sym = reg_str(osrLine, match, 1);
541542
auto* lst = &fl.exports;
542543

543544
if(sym.compare(0, 5, "from ") == 0) {
@@ -560,9 +561,9 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
560561
continue;
561562
}
562563

563-
if(mayBeDirective && reg_match(line, match, pre_priority)) {
564-
std::string type = reg_str(line, match, 1);
565-
std::string prior = reg_str(line, match, 2);
564+
if(mayBeDirective && reg_match(osrLine, match, pre_priority)) {
565+
std::string type = reg_str(osrLine, match, 1);
566+
std::string prior = reg_str(osrLine, match, 2);
566567
int priority = toNumber<int>(prior);
567568

568569
if(type == "init") {
@@ -584,8 +585,8 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
584585

585586
output += "\n";
586587
}
587-
else if(mayBeDirective && reg_match(line, match, pre_include)) {
588-
std::string filePart = reg_str(line, match, 1);
588+
else if(mayBeDirective && reg_match(osrLine, match, pre_include)) {
589+
std::string filePart = reg_str(osrLine, match, 1);
589590

590591
//Check include relative to current file first
591592
std::string includeFile = getAbsolutePath(devices.mods.resolve(
@@ -648,7 +649,7 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
648649
output.append(1,'\n');
649650
}
650651
else {
651-
output += line;
652+
output += osrLine;
652653
output.append(1,'\n');
653654
}
654655
}

0 commit comments

Comments
 (0)