Don't require whitespace after ==

This commit is contained in:
2019-03-17 14:07:52 -06:00
parent 1989720dc3
commit 5c7c3334e5
3 changed files with 20 additions and 4 deletions

View File

@@ -5,7 +5,11 @@ across more than one line */
~ var demo_var = "dynamic content"; // Hank scripts can embed Haxe logic by starting a line with '~'
== knot_example
=== knot_example
===knot_example
==knot_example
= stitch_example
=stitch_example
-> divert_example
->divert_example
->divert_example

View File

@@ -134,13 +134,21 @@ class Parser {
}
static function knot(buffer: HankBuffer, position: HankBuffer.Position) : ExprType {
var tokens = lineTokens(buffer, 2, position);
return EKnot(tokens[1]);
buffer.drop('==');
if (buffer.peekAhead(0, 1) == '=')
{
buffer.drop('=');
}
buffer.skipWhitespace();
var tokens = lineTokens(buffer, 1, position);
return EKnot(tokens[0]);
}
static function stitch(buffer: HankBuffer, position: HankBuffer.Position) : ExprType {
var tokens = lineTokens(buffer, 2, position);
return EStitch(tokens[1]);
buffer.drop('=');
buffer.skipWhitespace();
var tokens = lineTokens(buffer, 1, position);
return EStitch(tokens[0]);
}
static function haxeLine(buffer: HankBuffer, position: HankBuffer.Position) : ExprType {

View File

@@ -89,6 +89,10 @@ class ParserTest extends utest.Test {
ast = parser.parseFile('examples/parsing/misc.hank');
assertNextExpr(EHaxeLine('var demo_var = "dynamic content";'));
assertNextExpr(EKnot("knot_example"));
assertNextExpr(EKnot("knot_example"));
assertNextExpr(EKnot("knot_example"));
assertNextExpr(EKnot("knot_example"));
assertNextExpr(EStitch("stitch_example"));
assertNextExpr(EStitch("stitch_example"));
assertNextExpr(EDivert("divert_example"));
assertNextExpr(EDivert("divert_example"));