This commit is contained in:
2024-02-15 16:35:09 -07:00
parent eedbdc4f55
commit 4fadaf6473
3 changed files with 22 additions and 8 deletions

View File

@@ -13,10 +13,12 @@ using StringTools;
class UnmatchedBracketSignal { class UnmatchedBracketSignal {
public var type:String; public var type:String;
public var position:Stream.Position; public var position:Stream.Position;
public var lastReadExpArrayStartPosition:Stream.Position;
public function new(type, position) { public function new(type, position, ?lastReadArrayStartPosition) {
this.type = type; this.type = type;
this.position = position; this.position = position;
this.lastReadExpArrayStartPosition = lastReadArrayStartPosition;
} }
} }
@@ -123,7 +125,7 @@ class Reader {
function unmatchedBracket(b:String) { function unmatchedBracket(b:String) {
readTable[b] = (stream:Stream, k) -> { readTable[b] = (stream:Stream, k) -> {
stream.putBackString(b); stream.putBackString(b);
throw new UnmatchedBracketSignal(b, stream.position()); throw new UnmatchedBracketSignal(b, stream.position(), currentReadExpArrayStart());
}; };
} }
@@ -332,9 +334,15 @@ class Reader {
return readExpArrayStartPositions[readExpArrayStartPositions.length - 1]; return readExpArrayStartPositions[readExpArrayStartPositions.length - 1];
} }
static var nestedReadExpArrayEndings = [];
static var readExpArrayEndings = [];
static function currentReadExpArrayEnding() {
return readExpArrayEndings[readExpArrayEndings.length - 1];
}
static function assertNoPriorState(stream) { static function assertNoPriorState(stream) {
if (readExpArrayStartPositions.length != 0) { if (readExpArrayStartPositions.length != 0) {
trace(readExpArrayStartPositions);
throw new StreamError(stream.position(), "Prior readExpArray() state is remaining in Reader"); throw new StreamError(stream.position(), "Prior readExpArray() state is remaining in Reader");
} }
} }
@@ -350,6 +358,7 @@ class Reader {
startingPos = stream.position(); startingPos = stream.position();
readExpArrayStartPositions.push(startingPos); readExpArrayStartPositions.push(startingPos);
readExpArrayEndings.push(end);
while (!stream.startsWith(end)) { while (!stream.startsWith(end)) {
stream.dropWhitespace(); stream.dropWhitespace();
@@ -359,15 +368,19 @@ class Reader {
case Some(exp): case Some(exp):
array.push(exp); array.push(exp);
case None: case None:
if (allowEof) { readExpArrayStartPositions.pop(); return array; } if (allowEof) {
readExpArrayStartPositions.pop();
readExpArrayEndings.pop();
return array;
}
else throw new StreamError(startingPos, 'Ran out of expressions before $end was found.'); else throw new StreamError(startingPos, 'Ran out of expressions before $end was found.');
} }
} catch (s:UnmatchedBracketSignal) { } catch (s:UnmatchedBracketSignal) {
if (s.type == end) { if (s.type == end && s.lastReadExpArrayStartPosition == currentReadExpArrayStart()) {
break; break;
} }
else { else {
readExpArrayStartPositions.pop();
throw s; throw s;
} }
} }
@@ -375,6 +388,7 @@ class Reader {
} }
stream.dropString(end); stream.dropString(end);
readExpArrayStartPositions.pop(); readExpArrayStartPositions.pop();
readExpArrayEndings.pop();
return array; return array;
} }

View File

@@ -13,7 +13,7 @@ import js.lib.Promise;
using StringTools; using StringTools;
@:build(kiss.Kiss.buildExpectingError(kiss.EType.EStream('Ran out of expressions before ) was found.'))) @:build(kiss.Kiss.buildExpectingError(kiss.EType.EUnmatchedBracket("}")))
class UnclosedFunctionTestCase extends Test { class UnclosedFunctionTestCase extends Test {
function testExpectedError() { function testExpectedError() {
_testExpectedError(); _testExpectedError();

View File

@@ -13,7 +13,7 @@ import js.lib.Promise;
using StringTools; using StringTools;
@:build(kiss.Kiss.buildExpectingError(kiss.EType.EStream('Ran out of expressions before ) was found.'))) @:build(kiss.Kiss.buildExpectingError(kiss.EType.EUnmatchedBracket("}")))
class UnclosedMacroTestCase extends Test { class UnclosedMacroTestCase extends Test {
function testExpectedError() { function testExpectedError() {
_testExpectedError(); _testExpectedError();