Fixed really long loop bug for TheIntercept

This commit is contained in:
2019-05-07 00:40:40 -06:00
parent 10a549fc29
commit b7d76ccf76
4 changed files with 27 additions and 8 deletions

View File

@@ -101,7 +101,7 @@ class HInterface {
public function runEmbeddedHaxe(h: String, scope: Array<Dynamic>) {
interp.variables['scope'] = scope;
trace(h);
// trace(h);
var expr = parser.parseString(h);
expr = transmute(expr);
interp.execute(expr);

View File

@@ -97,8 +97,8 @@ class HankBuffer {
return s;
}
public function indexOf(s: String): Int {
return cleanBuffer.indexOf(s);
public function indexOf(s: String, start:Int = 0): Int {
return cleanBuffer.indexOf(s, start);
}
public function everyIndexOf(s: String): Array<Int> {
@@ -110,8 +110,18 @@ class HankBuffer {
}
public function rootIndexOf(s: String) {
// Not the most efficient implementation, but DRY.
return everyRootIndexOf(s)[0];
// The DRYest possible implementation causes the program to hang when files are big:
// return everyRootIndexOf(s)[0];
var start = 0;
while (true) {
start = indexOf(s, start);
if (start == -1) return -1;
if (depthAtIndex('{', '}', start) == 0) {
return start;
}
start += 1;
}
}
public function rootSplit(delimiter: String): Array<String> {

View File

@@ -36,11 +36,19 @@ class Output {
public static function parse(buffer: HankBuffer, isPartOfAlt: Bool = false): Output {
var parts = [];
// We can run into performance issues if we keep biting off from the entire buffer
var eol = buffer.rootIndexOf('\n');
if (eol == -1) {
eol = buffer.length();
}
// trace('found eol @ $eol');
buffer = HankBuffer.Dummy(buffer.take(eol));
// If brackets appear on this line, the first step is to break it up into ToggleOutput segments because ToggleOutputs need to be outermost in the hierarchy.
var findBracketExpression = buffer.findNestedExpression('[', ']');
switch (findBracketExpression) {
case Some(slice):
if (slice.start < buffer.rootIndexOf('\n')) {
if (slice.start < eol) {
var part1 = buffer.take(slice.start);
buffer.take(1);
var part2 = buffer.take(slice.length-2);

View File

@@ -2,6 +2,7 @@ package hank;
using StringTools;
import hank.Story.StoryFrame;
import hank.LogUtil;
import haxe.CallStack;
import utest.Assert;
@@ -35,7 +36,7 @@ class StoryTestCase extends utest.Test {
validateAgainstTranscript('${testsDirectory}/${folder}/main.hank', '${testsDirectory}/${folder}/${file}', !partial, debug);
} catch (e: Dynamic) {
trace('Error testing $folder/$file at transcript line $lastTranscriptLine: $e');
trace(CallStack.exceptionStack());
LogUtil.prettyPrintStack(CallStack.exceptionStack());
Assert.fail();
}
}
@@ -62,7 +63,7 @@ class StoryTestCase extends utest.Test {
story = Story.FromFile(storyFile, randomSeed);
} catch (e: Dynamic) {
trace('Error parsing $storyFile: $e');
trace(CallStack.exceptionStack());
LogUtil.prettyPrintStack(CallStack.exceptionStack());
Assert.fail();
return;
}