From 4fb98bc8454572fd4f5f5634f079998e5cf2fc58 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 17 Nov 2021 17:42:02 -0700 Subject: [PATCH] throw errors for unterminated strings with better position link --- kiss/src/kiss/Reader.hx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kiss/src/kiss/Reader.hx b/kiss/src/kiss/Reader.hx index 4f353f0e..57f36185 100644 --- a/kiss/src/kiss/Reader.hx +++ b/kiss/src/kiss/Reader.hx @@ -314,8 +314,10 @@ class Reader { } do { - // TODO here, give the position of the start of the literal if expect fails - var next = stream.expect('closing "', () -> stream.takeChars(1)); + var next = switch (stream.takeChars(1)) { + case Some(c): c; + default: throw new StreamError(pos, 'Unterminated string literal. Expected "'); + } switch (next) { case '$': @@ -382,8 +384,15 @@ class Reader { } } while (true); + var startingPos = stream.position(); // TODO here, give the position of the start of the literal if expect fails - return StrExp(stream.expect('closing $terminator', () -> stream.takeUntilAndDrop(terminator))); + + return switch (stream.takeUntilAndDrop(terminator)) { + case Some(str): + StrExp(str); + default: + throw new StreamError(startingPos, 'Unterminated string literal. Expected $terminator'); + }; } public static function toString(exp:ReaderExpDef) {