scanFlowScalarNonSpaces errors are now thrown by the caller.

This commit is contained in:
Ferdinand Majerech 2014-07-24 18:56:22 +02:00
parent fb20ca1006
commit f9eb7b2eb1

View file

@ -1284,11 +1284,13 @@ final class Scanner
scope(exit) { if(error_) {reader_.sliceBuilder.finish();}} scope(exit) { if(error_) {reader_.sliceBuilder.finish();}}
scanFlowScalarNonSpacesToSlice(quotes, startMark); scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError();
while(reader_.peek() != quote) while(reader_.peek() != quote)
{ {
scanFlowScalarSpacesToSlice(startMark); scanFlowScalarSpacesToSlice(startMark);
throwIfError(); throwIfError();
scanFlowScalarNonSpacesToSlice(quotes, startMark); scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError();
} }
reader_.forward(); reader_.forward();
@ -1315,10 +1317,12 @@ final class Scanner
outer: for(;;) outer: for(;;)
{ {
const slice = reader_.slice(length, length + 32); const slice = reader_.slice(length, length + 32);
// XXX will be thrown by parent if(slice.empty)
enforce(slice.length > 0, {
new Error("While reading a flow scalar", startMark, setError("While reading a flow scalar", startMark,
"reached end of file", reader_.mark)); "reached end of file", reader_.mark);
return;
}
foreach(ch; slice) foreach(ch; slice)
{ {
if(search.canFind(ch)) { break outer; } if(search.canFind(ch)) { break outer; }
@ -1356,14 +1360,13 @@ final class Scanner
length = dyaml.escapes.escapeHexCodes[c]; length = dyaml.escapes.escapeHexCodes[c];
reader_.forward(); reader_.forward();
foreach(i; 0 .. length) foreach(i; 0 .. length) if(!reader_.peek(i).isHexDigit())
{ {
enforce(isHexDigit(reader_.peek(i)), setError("While scanning a double qouted scalar", startMark,
new Error( "expected escape sequence of " ~ length.to!string ~
"While scanning a double qouted scalar", startMark, " hexadecimal numbers, but found " ~
"expected escape sequence of " ~ length.to!string ~ reader_.peek(i).to!string, reader_.mark);
" hexadecimal numbers, but found " ~ return;
reader_.peek(i).to!string, reader_.mark));
} }
dchar[] hex = reader_.get(length); dchar[] hex = reader_.get(length);
@ -1373,13 +1376,14 @@ final class Scanner
{ {
scanLineBreak(); scanLineBreak();
scanFlowScalarBreaksToSlice(startMark); scanFlowScalarBreaksToSlice(startMark);
throwIfError(); if(error_) { return; }
} }
else else
{ {
throw new Error("While scanning a double quoted scalar", startMark, setError("While scanning a double quoted scalar", startMark,
"found unknown escape character: " ~ c.to!string, "found unknown escape character: " ~ c.to!string,
reader_.mark); reader_.mark);
return;
} }
} }
else { return; } else { return; }