Gathers need not have an expression

This commit is contained in:
2019-05-14 20:36:08 -06:00
parent 3daaf2c165
commit 1f6d16b390
4 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
Hey, you!
* Hello, world!
I just love meeting friendly people.
* Goodbye, cruel world!
Was it something I said?
-
Some text after this.
-

View File

@@ -0,0 +1,6 @@
Hey, you!
* Hello, world!
* Goodbye, cruel world!
> 1: Hello, world!
I just love meeting friendly people.
Some text after this.

View File

@@ -359,8 +359,11 @@ class HankBuffer {
return getLine(trimmed, takeUntil, true); return getLine(trimmed, takeUntil, true);
} }
public function skipWhitespace() { public function skipWhitespace(terminator: String = '') {
var whitespace = cleanBuffer.substr(0, cleanBuffer.length - cleanBuffer.ltrim().length); var nextTerm = cleanBuffer.indexOf(terminator);
var withoutTerm = cleanBuffer.length - cleanBuffer.ltrim().length;
var end = if (nextTerm <= 0) withoutTerm else Math.floor(Math.min(nextTerm, withoutTerm));
var whitespace = cleanBuffer.substr(0, end);
drop(whitespace); drop(whitespace);
} }

View File

@@ -179,8 +179,15 @@ class Parser {
var depth = buffer.countConsecutive('-'); var depth = buffer.countConsecutive('-');
buffer.skipWhitespace(); buffer.skipWhitespace();
var label = buffer.expressionIfNext('(', ')'); var label = buffer.expressionIfNext('(', ')');
buffer.skipWhitespace(); buffer.skipWhitespace('\n');
return EGather(label, depth, parseExpr(buffer, buffer.position()));
var gatherOp = switch (buffer.peekLine()) {
case Some("") | None:
ENoOp;
default:
parseExpr(buffer, buffer.position());
}
return EGather(label, depth, gatherOp);
} }
static var choices: Int = 0; static var choices: Int = 0;