throw errors for unterminated strings with better position link

This commit is contained in:
2021-11-17 17:42:02 -07:00
parent 4e856bc4a7
commit 4fb98bc845

View File

@@ -314,8 +314,10 @@ class Reader {
} }
do { do {
// TODO here, give the position of the start of the literal if expect fails var next = switch (stream.takeChars(1)) {
var next = stream.expect('closing "', () -> stream.takeChars(1)); case Some(c): c;
default: throw new StreamError(pos, 'Unterminated string literal. Expected "');
}
switch (next) { switch (next) {
case '$': case '$':
@@ -382,8 +384,15 @@ class Reader {
} }
} while (true); } while (true);
var startingPos = stream.position();
// TODO here, give the position of the start of the literal if expect fails // 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) { public static function toString(exp:ReaderExpDef) {