Fixing bugs
This commit is contained in:
@@ -22,7 +22,7 @@ else
|
||||
|
||||
= two
|
||||
|
||||
Second output. {start} {start.one} {start.two} {one.gather}
|
||||
Second output. {start} {start.one} {two} {one.gather}
|
||||
-> one.gather
|
||||
|
||||
-> three
|
||||
|
||||
@@ -26,6 +26,11 @@ var test2 = 5;
|
||||
```
|
||||
, Output "this"
|
||||
```
|
||||
```
|
||||
,,,
|
||||
Output "this"
|
||||
,,,
|
||||
```
|
||||
|
||||
- no label gather on an output
|
||||
--(labeled) deep gather
|
||||
|
||||
@@ -101,6 +101,7 @@ class HInterface {
|
||||
public function runEmbeddedHaxe(h: String, scope: Array<Dynamic>) {
|
||||
interp.variables['scope'] = scope;
|
||||
|
||||
trace(h);
|
||||
var expr = parser.parseString(h);
|
||||
expr = transmute(expr);
|
||||
interp.execute(expr);
|
||||
|
||||
@@ -25,7 +25,7 @@ class Parser {
|
||||
var ast: HankAST = [];
|
||||
|
||||
public function new() {
|
||||
|
||||
choices = 0;
|
||||
}
|
||||
|
||||
public function parseString(h: String): HankAST {
|
||||
@@ -35,6 +35,7 @@ class Parser {
|
||||
do {
|
||||
var position = stringBuffer.position();
|
||||
stringBuffer.skipWhitespace();
|
||||
if (stringBuffer.isEmpty()) break;
|
||||
var expr = parseExpr(stringBuffer, position);
|
||||
switch(expr) {
|
||||
case EIncludeFile(file):
|
||||
@@ -200,12 +201,12 @@ class Parser {
|
||||
// Transform , and ,,, expressions into Hank embedded in Haxe embedded in Hank
|
||||
do {
|
||||
var nextLine = blockBuffer.takeLine('lr').unwrap();
|
||||
if (StringTools.startsWith(nextLine, ',')) {
|
||||
if (nextLine == ',,,'){
|
||||
var embeddedHankBlock = blockBuffer.takeUntil([',,,'],false,true).unwrap().output;
|
||||
processedContents += 'story.runEmbeddedHank("${escapeQuotes(embeddedHankBlock)}"); ';
|
||||
} else if (StringTools.startsWith(nextLine, ',')) {
|
||||
nextLine = StringTools.trim(nextLine.substr(1));
|
||||
processedContents += 'story.runEmbeddedHank("${escapeQuotes(nextLine)}"); ';
|
||||
} else if (nextLine == ',,,'){
|
||||
var embeddedHankBlock = blockBuffer.takeUntil(['```'],false,true).unwrap().output;
|
||||
processedContents += 'story.runEmbeddedHank("${escapeQuotes(embeddedHankBlock)}"); ';
|
||||
} else {
|
||||
processedContents += nextLine+' ';
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Story {
|
||||
|
||||
var parser: Parser;
|
||||
|
||||
var embedded: Option<Story> = None;
|
||||
var embeddedBlocks: Array<Story> = [];
|
||||
var parent: Option<Story> = None;
|
||||
|
||||
function new(r: Random, p: Parser, ast: HankAST, st: StoryNode, sc: Array<StoryNode>, vc: Map<StoryNode, Int>, hi: HInterface) {
|
||||
@@ -75,15 +75,18 @@ class Story {
|
||||
}
|
||||
|
||||
public function nextFrame(): StoryFrame {
|
||||
switch (embedded) {
|
||||
case Some(s):
|
||||
return s.nextFrame();
|
||||
case None:
|
||||
if (exprIndex >= ast.length) {
|
||||
return Finished;
|
||||
}
|
||||
return processExpr(ast[exprIndex].expr);
|
||||
while (embeddedBlocks.length > 0) {
|
||||
var nf = embeddedBlocks[0].nextFrame();
|
||||
if(nf == Finished) {
|
||||
embeddedBlocks.remove(embeddedBlocks[0]);
|
||||
} else {
|
||||
return nf;
|
||||
}
|
||||
}
|
||||
if (exprIndex >= ast.length) {
|
||||
return Finished;
|
||||
}
|
||||
return processExpr(ast[exprIndex].expr);
|
||||
}
|
||||
|
||||
private function processExpr(expr: ExprType) {
|
||||
@@ -134,7 +137,6 @@ class Story {
|
||||
case Some(node):
|
||||
newScopes = whichScope.slice(i);
|
||||
newScopes.insert(0, node);
|
||||
trace(newScopes);
|
||||
// Then resolve the rest of the parts inward from there
|
||||
for (part in targetParts.slice(1)) {
|
||||
var scope = newScopes[0];
|
||||
@@ -154,13 +156,13 @@ class Story {
|
||||
}
|
||||
|
||||
public function divertTo(target: String) {
|
||||
trace('diverting to $target');
|
||||
switch (parent) {
|
||||
case Some(p):
|
||||
p.embedded = None; //
|
||||
p.embeddedBlocks = []; //
|
||||
return p.divertTo(target); // A divert from inside embedded hank, ends the embedding
|
||||
default:
|
||||
}
|
||||
trace('diverting to $target');
|
||||
var newScopes = resolveNodeInScope(target);
|
||||
var targetIdx = newScopes[0].astIndex;
|
||||
|
||||
@@ -212,18 +214,17 @@ class Story {
|
||||
}
|
||||
|
||||
public function choose(choiceIndex: Int): String {
|
||||
switch (embedded) {
|
||||
case Some(s):
|
||||
return s.choose(choiceIndex);
|
||||
case None:
|
||||
// TODO if the choice has a label, increment its view count
|
||||
return '';
|
||||
if (embeddedBlocks.length > 0) {
|
||||
return embeddedBlocks[0].choose(choiceIndex);
|
||||
} else {
|
||||
// if not embedded, actually make the choice
|
||||
// TODO if the choice has a label, increment its view count
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** Parse and run embedded Hank script on the fly. **/
|
||||
public function runEmbeddedHank(h: String) {
|
||||
trace(h);
|
||||
embedded = Some(embeddedStory(h));
|
||||
embeddedBlocks.push(embeddedStory(h));
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,7 @@ class ParserTest extends utest.Test {
|
||||
assertNextExpr(EHaxeBlock("var haxeVar = 'test'; var test2 = 5; "));
|
||||
assertNextExpr(EHaxeBlock('story.runEmbeddedHank("Output this"); '));
|
||||
assertNextExpr(EHaxeBlock('story.runEmbeddedHank("Output \\"this\\""); '));
|
||||
assertNextExpr(EHaxeBlock('story.runEmbeddedHank("Output \\"this\\"\n"); '));
|
||||
assertNextExpr(EGather(None, 1, EOutput(new Output([Text("no label gather on an output")]))));
|
||||
assertNextExpr(EGather(Some('labeled'), 2, EOutput(new Output([Text("deep gather")]))));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user