scanAnchor is now nothrow.

This commit is contained in:
Ferdinand Majerech 2014-07-26 13:31:31 +02:00
parent 60e0270ffa
commit 5133257201

View file

@ -683,7 +683,9 @@ final class Scanner
//No simple keys after ALIAS/ANCHOR. //No simple keys after ALIAS/ANCHOR.
allowSimpleKey_ = false; allowSimpleKey_ = false;
tokens_.push(scanAnchor(id)); const anchor = scanAnchor(id);
throwIfError();
tokens_.push(anchor);
} }
///Aliases to add ALIAS or ANCHOR token. ///Aliases to add ALIAS or ANCHOR token.
@ -961,7 +963,7 @@ final class Scanner
/// In case of an error, error_ is set. Use throwIfError() to handle this. /// In case of an error, error_ is set. Use throwIfError() to handle this.
void scanDirectiveNameToSlice(const Mark startMark) @system pure nothrow @nogc void scanDirectiveNameToSlice(const Mark startMark) @system pure nothrow @nogc
{ {
//Scan directive name. // Scan directive name.
scanAlphaNumericToSlice!"a directive"(startMark); scanAlphaNumericToSlice!"a directive"(startMark);
if(error_) { return; } if(error_) { return; }
@ -1073,32 +1075,35 @@ final class Scanner
/// and /// and
/// [ *alias , "value" ] /// [ *alias , "value" ]
/// Therefore we restrict aliases to ASCII alphanumeric characters. /// Therefore we restrict aliases to ASCII alphanumeric characters.
Token scanAnchor(const TokenID id) @trusted pure ///
/// In case of an error, error_ is set. Use throwIfError() to handle this.
Token scanAnchor(const TokenID id) @trusted pure nothrow
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
const dchar i = reader_.get(); const dchar i = reader_.get();
reader_.sliceBuilder.begin(); reader_.sliceBuilder.begin();
{ if(i == '*') { scanAlphaNumericToSlice!"an alias"(startMark); }
scope(failure) { reader_.sliceBuilder.finish(); } else { scanAlphaNumericToSlice!"an anchor"(startMark); }
if(i == '*') { scanAlphaNumericToSlice!"an alias"(startMark); } // On error, value is discarded as we return immediately
else { scanAlphaNumericToSlice!"an anchor"(startMark); }
throwIfError();
}
const value = reader_.sliceBuilder.finish(); const value = reader_.sliceBuilder.finish();
if(error_) { return Token.init; }
enforce((" \t\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()) || if(!" \t\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()) &&
("?:,]}%@"d).canFind(reader_.peek())), !"?:,]}%@"d.canFind(reader_.peek()))
new Error("While scanning an " ~ (i == '*') ? "alias" : "anchor", {
startMark, "expected alphanumeric, - or _, but found "~ enum anchorCtx = "While scanning an anchor";
reader_.peek().to!string, reader_.mark)); enum aliasCtx = "While scanning an alias";
error(i == '*' ? aliasCtx : anchorCtx, startMark,
expected("alphanumeric, '-' or '_'", reader_.peek()), reader_.mark);
return Token.init;
}
if(id == TokenID.Alias) if(id == TokenID.Alias)
{ {
return aliasToken(startMark, reader_.mark, value.utf32To8); return aliasToken(startMark, reader_.mark, value.utf32To8);
} }
else if(id == TokenID.Anchor) if(id == TokenID.Anchor)
{ {
return anchorToken(startMark, reader_.mark, value.utf32To8); return anchorToken(startMark, reader_.mark, value.utf32To8);
} }