Renamed setError() to error() for more compact error handling.
This commit is contained in:
parent
33110e295e
commit
cf014150ca
|
@ -260,8 +260,8 @@ final class Scanner
|
||||||
/// their callers.
|
/// their callers.
|
||||||
///
|
///
|
||||||
/// See_Also: dyaml.exception.MarkedYamlException
|
/// See_Also: dyaml.exception.MarkedYamlException
|
||||||
void setError(string context, const Mark contextMark, string problem,
|
void error(string context, const Mark contextMark, string problem,
|
||||||
const Mark problemMark) @safe pure nothrow @nogc
|
const Mark problemMark) @safe pure nothrow @nogc
|
||||||
{
|
{
|
||||||
assert(error_ == false,
|
assert(error_ == false,
|
||||||
"Setting an error when there already is a not yet thrown error");
|
"Setting an error when there already is a not yet thrown error");
|
||||||
|
@ -849,9 +849,9 @@ final class Scanner
|
||||||
if(length == 0)
|
if(length == 0)
|
||||||
{
|
{
|
||||||
enum contextMsg = "While scanning " ~ name;
|
enum contextMsg = "While scanning " ~ name;
|
||||||
setError(contextMsg, startMark,
|
error(contextMsg, startMark,
|
||||||
buildMsg("expected alphanumeric, '-' or '_', but found ", c),
|
buildMsg("expected alphanumeric, '-' or '_', but found ", c),
|
||||||
reader_.mark);
|
reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -960,9 +960,9 @@ final class Scanner
|
||||||
if(error_) { return; }
|
if(error_) { return; }
|
||||||
|
|
||||||
if(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())) { return; }
|
if(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())) { return; }
|
||||||
setError("While scanning a directive", startMark,
|
error("While scanning a directive", startMark,
|
||||||
buildMsg("expected alphanumeric, '-' or '_', but found ", reader_.peek()),
|
buildMsg("expected alphanumeric, '-' or '_', but found ", reader_.peek()),
|
||||||
reader_.mark);
|
reader_.mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
///Scan value of a YAML directive token. Returns major, minor version separated by '.'.
|
///Scan value of a YAML directive token. Returns major, minor version separated by '.'.
|
||||||
|
@ -1123,9 +1123,9 @@ final class Scanner
|
||||||
if(error_) { return Token.init; }
|
if(error_) { return Token.init; }
|
||||||
if(reader_.peek() != '>')
|
if(reader_.peek() != '>')
|
||||||
{
|
{
|
||||||
setError("While scanning a tag", startMark,
|
error("While scanning a tag", startMark,
|
||||||
buildMsg("expected '>' but found ", reader_.peek()),
|
buildMsg("expected '>' but found ", reader_.peek()),
|
||||||
reader_.mark);
|
reader_.mark);
|
||||||
return Token.init;
|
return Token.init;
|
||||||
}
|
}
|
||||||
reader_.forward();
|
reader_.forward();
|
||||||
|
@ -1169,15 +1169,15 @@ final class Scanner
|
||||||
if(error_) { return Token.init; }
|
if(error_) { return Token.init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()))
|
if(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()))
|
||||||
{
|
{
|
||||||
setError("While scanning a tag", startMark,
|
const slice = reader_.sliceBuilder.finish();
|
||||||
buildMsg("expected ' ' but found ", reader_.peek()),
|
return tagToken(startMark, reader_.mark, slice.utf32To8, handleEnd);
|
||||||
reader_.mark);
|
|
||||||
return Token.init;
|
|
||||||
}
|
}
|
||||||
const slice = reader_.sliceBuilder.finish();
|
|
||||||
return tagToken(startMark, reader_.mark, slice.utf32To8, handleEnd);
|
error("While scanning a tag", startMark,
|
||||||
|
buildMsg("expected ' ' but found ", reader_.peek()), reader_.mark);
|
||||||
|
return Token.init;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scan a block scalar token with specified style.
|
/// Scan a block scalar token with specified style.
|
||||||
|
@ -1347,15 +1347,14 @@ final class Scanner
|
||||||
if(gotIncrement) { getChomping(c, chomping); }
|
if(gotIncrement) { getChomping(c, chomping); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!" \0\n\r\u0085\u2028\u2029"d.canFind(c))
|
if(" \0\n\r\u0085\u2028\u2029"d.canFind(c))
|
||||||
{
|
{
|
||||||
setError("While scanning a block scalar", startMark,
|
return tuple(chomping, increment);
|
||||||
buildMsg("expected chomping or indentation indicator, but found ", c),
|
|
||||||
reader_.mark);
|
|
||||||
return tuple(Chomping.init, int.max);
|
|
||||||
}
|
}
|
||||||
|
error("While scanning a block scalar", startMark,
|
||||||
return tuple(chomping, increment);
|
buildMsg("expected chomping or indentation indicator, but found ", c),
|
||||||
|
reader_.mark);
|
||||||
|
return tuple(Chomping.init, int.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get chomping indicator, if detected. Return false otherwise.
|
/// Get chomping indicator, if detected. Return false otherwise.
|
||||||
|
@ -1395,16 +1394,15 @@ final class Scanner
|
||||||
// Convert a digit to integer.
|
// Convert a digit to integer.
|
||||||
increment = c - '0';
|
increment = c - '0';
|
||||||
assert(increment < 10 && increment >= 0, "Digit has invalid value");
|
assert(increment < 10 && increment >= 0, "Digit has invalid value");
|
||||||
if(increment == 0)
|
if(increment > 0)
|
||||||
{
|
{
|
||||||
setError("While scanning a block scalar", startMark,
|
reader_.forward();
|
||||||
"expected indentation indicator in range 1-9, but found 0",
|
c = reader_.peek();
|
||||||
reader_.mark);
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
reader_.forward();
|
error("While scanning a block scalar", startMark,
|
||||||
c = reader_.peek();
|
"expected indentation indicator in range 1-9, but found 0", reader_.mark);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scan (and ignore) ignored line in a block scalar.
|
/// Scan (and ignore) ignored line in a block scalar.
|
||||||
|
@ -1415,14 +1413,14 @@ final class Scanner
|
||||||
findNextNonSpace();
|
findNextNonSpace();
|
||||||
if(reader_.peek()== '#') { scanToNextBreak(); }
|
if(reader_.peek()== '#') { scanToNextBreak(); }
|
||||||
|
|
||||||
if(!"\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()))
|
if("\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek()))
|
||||||
{
|
{
|
||||||
setError("While scanning a block scalar", startMark,
|
scanLineBreak();
|
||||||
buildMsg("expected comment or line break, but found ", reader_.peek()),
|
|
||||||
reader_.mark);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scanLineBreak();
|
error("While scanning a block scalar", startMark,
|
||||||
|
buildMsg("expected comment or line break, but found ", reader_.peek()),
|
||||||
|
reader_.mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scan indentation in a block scalar, returning line breaks, max indent and end mark.
|
/// Scan indentation in a block scalar, returning line breaks, max indent and end mark.
|
||||||
|
@ -1519,8 +1517,8 @@ final class Scanner
|
||||||
const slice = reader_.slice(length, length + 32);
|
const slice = reader_.slice(length, length + 32);
|
||||||
if(slice.empty)
|
if(slice.empty)
|
||||||
{
|
{
|
||||||
setError("While reading a flow scalar", startMark,
|
error("While reading a flow scalar", startMark,
|
||||||
"reached end of file", reader_.mark);
|
"reached end of file", reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach(ch; slice)
|
foreach(ch; slice)
|
||||||
|
@ -1560,9 +1558,9 @@ final class Scanner
|
||||||
|
|
||||||
foreach(i; 0 .. hexLength) if(!reader_.peek(i).isHexDigit())
|
foreach(i; 0 .. hexLength) if(!reader_.peek(i).isHexDigit())
|
||||||
{
|
{
|
||||||
setError("While scanning a double quoted scalar", startMark,
|
error("While scanning a double quoted scalar", startMark,
|
||||||
"found an unexpected character; expected escape "
|
"found an unexpected character; expected escape "
|
||||||
"sequence of hexadecimal numbers.", reader_.mark);
|
"sequence of hexadecimal numbers.", reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,9 +1569,9 @@ final class Scanner
|
||||||
const decoded = cast(dchar)parseNoGC!int(hex, 16u, overflow);
|
const decoded = cast(dchar)parseNoGC!int(hex, 16u, overflow);
|
||||||
if(overflow)
|
if(overflow)
|
||||||
{
|
{
|
||||||
setError("While scanning a double quoted scalar", startMark,
|
error("While scanning a double quoted scalar", startMark,
|
||||||
"overflow when parsing an escape sequence of "
|
"overflow when parsing an escape sequence of "
|
||||||
"hexadecimal numbers.", reader_.mark);
|
"hexadecimal numbers.", reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reader_.sliceBuilder.write(decoded);
|
reader_.sliceBuilder.write(decoded);
|
||||||
|
@ -1586,9 +1584,9 @@ final class Scanner
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setError("While scanning a double quoted scalar", startMark,
|
error("While scanning a double quoted scalar", startMark,
|
||||||
buildMsg("found unsupported escape " "character", c),
|
buildMsg("found unsupported escape " "character", c),
|
||||||
reader_.mark);
|
reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1613,8 +1611,8 @@ final class Scanner
|
||||||
const c = whitespaces[$ - 1];
|
const c = whitespaces[$ - 1];
|
||||||
if(c == '\0')
|
if(c == '\0')
|
||||||
{
|
{
|
||||||
setError("While scanning a quoted scalar", startMark,
|
error("While scanning a quoted scalar", startMark,
|
||||||
"found unexpected end of buffer", reader_.mark);
|
"found unexpected end of buffer", reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1659,8 +1657,8 @@ final class Scanner
|
||||||
if((prefix == "---"d || prefix == "..."d) &&
|
if((prefix == "---"d || prefix == "..."d) &&
|
||||||
" \t\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek(3)))
|
" \t\0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek(3)))
|
||||||
{
|
{
|
||||||
setError("While scanning a quoted scalar", startMark,
|
error("While scanning a quoted scalar", startMark,
|
||||||
"found unexpected document separator", reader_.mark);
|
"found unexpected document separator", reader_.mark);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1723,10 +1721,10 @@ final class Scanner
|
||||||
spacesTransaction.commit();
|
spacesTransaction.commit();
|
||||||
reader_.sliceBuilder.finish();
|
reader_.sliceBuilder.finish();
|
||||||
reader_.forward(length);
|
reader_.forward(length);
|
||||||
setError("While scanning a plain scalar", startMark,
|
error("While scanning a plain scalar", startMark,
|
||||||
"found unexpected ':' . Please check "
|
"found unexpected ':' . Please check "
|
||||||
"http://pyyaml.org/wiki/YAMLColonInFlowContext "
|
"http://pyyaml.org/wiki/YAMLColonInFlowContext for details.",
|
||||||
"for details.", reader_.mark);
|
reader_.mark);
|
||||||
return Token.init;
|
return Token.init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1827,8 +1825,8 @@ final class Scanner
|
||||||
enum contextMsg = "While scanning a " ~ name;
|
enum contextMsg = "While scanning a " ~ name;
|
||||||
if(c != '!')
|
if(c != '!')
|
||||||
{
|
{
|
||||||
setError(contextMsg, startMark,
|
error(contextMsg, startMark,
|
||||||
buildMsg("expected a '!', but found: ", c), reader_.mark);
|
buildMsg("expected a '!', but found: ", c), reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1844,8 +1842,8 @@ final class Scanner
|
||||||
if(c != '!')
|
if(c != '!')
|
||||||
{
|
{
|
||||||
reader_.forward(length);
|
reader_.forward(length);
|
||||||
setError(contextMsg, startMark,
|
error(contextMsg, startMark,
|
||||||
buildMsg("expected a '!', but found: ", c), reader_.mark);
|
buildMsg("expected a '!', but found: ", c), reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++length;
|
++length;
|
||||||
|
@ -1891,8 +1889,8 @@ final class Scanner
|
||||||
if(reader_.sliceBuilder.length > startLen) { return; }
|
if(reader_.sliceBuilder.length > startLen) { return; }
|
||||||
|
|
||||||
enum contextMsg = "While parsing a " ~ name;
|
enum contextMsg = "While parsing a " ~ name;
|
||||||
setError(contextMsg, startMark, buildMsg("expected URI, but found: ", c),
|
error(contextMsg, startMark, buildMsg("expected URI, but found: ", c),
|
||||||
reader_.mark);
|
reader_.mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not @nogc yet because std.utf.decode is not @nogc
|
// Not @nogc yet because std.utf.decode is not @nogc
|
||||||
|
@ -1950,7 +1948,7 @@ final class Scanner
|
||||||
{
|
{
|
||||||
auto msg = buildMsg("expected URI escape sequence of 2 "
|
auto msg = buildMsg("expected URI escape sequence of 2 "
|
||||||
"hexadecimal numbers, but found: ", c);
|
"hexadecimal numbers, but found: ", c);
|
||||||
setError(contextMsg, startMark, msg, reader_.mark);
|
error(contextMsg, startMark, msg, reader_.mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1971,7 +1969,7 @@ final class Scanner
|
||||||
}
|
}
|
||||||
catch(UTFException e)
|
catch(UTFException e)
|
||||||
{
|
{
|
||||||
setError(contextMsg, startMark, e.msg, mark);
|
error(contextMsg, startMark, e.msg, mark);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
|
Loading…
Reference in a new issue