Closed #67: disambiguating choice conditions

This commit is contained in:
2019-06-15 11:58:38 -06:00
parent 5943f47977
commit 3193eb64c5
5 changed files with 17 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ B: {choice_b}
C: {choice_c}
* (choice_a) Choice A
* (choice_b) Choice B
* (choice_c) {choice_b && choice_a} Choice C
* (choice_c) {choice_b && choice_a}? Choice C
-> end
- (gather) -> start

View File

@@ -16,7 +16,7 @@ You can include choices for the player.
~ flag = true;
~ var what_happened = "mouse";
+ Door B []opens but the room on the other side is {word}!
* {flag} Choices can depend on logical conditions being truthy.
* {flag}? Choices can depend on logical conditions being truthy.
-> final_choice
- -> choice_example // a hyphen gathers all choices to the same place.

View File

@@ -9,8 +9,8 @@ if (start <= 2) {
Loop #: {start}
* A series of choices
* In Hank script embedded in Haxe script embedded in Hank script!
* {start == 1} What could be more fun?
* {start == 2} Gosh this sucks
* {start == 1}? What could be more fun?
* {start == 2}? Gosh this sucks
- -> sanity
,,,
} else {

View File

@@ -321,7 +321,7 @@ class HankBuffer {
/** If the given expression comes next in the buffer, take its contents. Otherwise, return None **/
public function expressionIfNext(o:String, c:String):Option<String> {
if (cleanBuffer.startsWith(o)) {
if (cleanBuffer.startsWith(o) && cleanBuffer.indexOf(c) != -1) {
drop(o);
var end = cleanBuffer.indexOf(c);
var content = take(end);

View File

@@ -13,8 +13,17 @@ import hank.HankBuffer;
@:allow(tests.ParserTest)
class Parser {
static var symbols:Array<Map<String, HankBuffer->HankBuffer.Position->ExprType>> = [
['INCLUDE ' => include], ['<-' => thread], ['->' => divert], ['===' => knot], ['==' => knot], ['=' => stitch], ['~' => haxeLine],
['```' => haxeBlock], ['-' => gather], ['*' => choice], ['+' => choice]];
['INCLUDE ' => include],
['<-' => thread],
['->' => divert],
['===' => knot],
['==' => knot],
['=' => stitch],
['~' => haxeLine],
['```' => haxeBlock],
['-' => gather],
['*' => choice],
['+' => choice]];
var buffers:Array<HankBuffer> = [];
var ast:HankAST = [];
@@ -198,7 +207,7 @@ class Parser {
buffer.skipWhitespace();
var label = buffer.expressionIfNext('(', ')');
buffer.skipWhitespace();
var condition = buffer.expressionIfNext('{', '}');
var condition = buffer.expressionIfNext('{', '}?');
buffer.skipWhitespace();
var output = Output.parse(buffer);
var divertTarget = output.takeInlineDivert();