scanTag is now nothrow.

This commit is contained in:
Ferdinand Majerech 2014-07-25 18:28:08 +02:00
parent 4e3619cf6a
commit 537eccc597

View file

@ -697,6 +697,7 @@ final class Scanner
allowSimpleKey_ = false; allowSimpleKey_ = false;
tokens_.push(scanTag()); tokens_.push(scanTag());
throwIfError();
} }
///Add block SCALAR token. ///Add block SCALAR token.
@ -1067,7 +1068,9 @@ final class Scanner
} }
/// Scan a tag token. /// Scan a tag token.
Token scanTag() @trusted pure ///
/// In case of an error, error_ is set. Use throwIfError() to handle this.
Token scanTag() @trusted pure nothrow
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
dchar c = reader_.peek(1); dchar c = reader_.peek(1);
@ -1084,11 +1087,14 @@ final class Scanner
handleEnd = 0; handleEnd = 0;
scanTagURIToSlice!"tag"(startMark); scanTagURIToSlice!"tag"(startMark);
throwIfError(); if(error_) { return Token.init; }
enforce(reader_.peek() == '>', if(reader_.peek() != '>')
new Error("While scanning a tag", startMark, {
"expected '>' but found" ~ reader_.peek().to!string, setError("While scanning a tag", startMark,
reader_.mark)); buildMsg("expected '>' but found ", reader_.peek()),
reader_.mark);
return Token.init;
}
reader_.forward(); reader_.forward();
} }
else if(" \t\0\n\r\u0085\u2028\u2029"d.canFind(c)) else if(" \t\0\n\r\u0085\u2028\u2029"d.canFind(c))
@ -1117,7 +1123,7 @@ final class Scanner
{ {
scanTagHandleToSlice!"tag"(startMark); scanTagHandleToSlice!"tag"(startMark);
handleEnd = cast(uint)reader_.sliceBuilder.length; handleEnd = cast(uint)reader_.sliceBuilder.length;
throwIfError(); if(error_) { return Token.init; }
} }
else else
{ {
@ -1127,14 +1133,17 @@ final class Scanner
} }
scanTagURIToSlice!"tag"(startMark); scanTagURIToSlice!"tag"(startMark);
throwIfError(); if(error_) { return Token.init; }
} }
enforce(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()), if(!" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()))
new Error("While scanning a tag", startMark, {
"expected ' ' but found" ~ reader_.peek().to!string, setError("While scanning a tag", startMark,
reader_.mark)); buildMsg("expected ' ' but found ", reader_.peek()),
const dstring slice = reader_.sliceBuilder.finish(); reader_.mark);
return Token.init;
}
const slice = reader_.sliceBuilder.finish();
return tagToken(startMark, reader_.mark, slice.utf32To8, handleEnd); return tagToken(startMark, reader_.mark, slice.utf32To8, handleEnd);
} }