Compound pure nothrow @nogc in Scanner.

This commit is contained in:
Ferdinand Majerech 2014-08-05 22:52:51 +02:00
parent cd879c05d3
commit ada8335504

View file

@ -739,14 +739,16 @@ final class Scanner
tokens_.push(plain); tokens_.push(plain);
} }
pure nothrow @nogc:
///Check if the next token is DIRECTIVE: ^ '%' ... ///Check if the next token is DIRECTIVE: ^ '%' ...
bool checkDirective() @safe pure nothrow @nogc bool checkDirective() @safe
{ {
return reader_.peekByte() == '%' && reader_.column == 0; return reader_.peekByte() == '%' && reader_.column == 0;
} }
/// Check if the next token is DOCUMENT-START: ^ '---' (' '|'\n') /// Check if the next token is DOCUMENT-START: ^ '---' (' '|'\n')
bool checkDocumentStart() @safe pure nothrow @nogc bool checkDocumentStart() @safe
{ {
// Check one char first, then all 3, to prevent reading outside the buffer. // Check one char first, then all 3, to prevent reading outside the buffer.
return reader_.column == 0 && return reader_.column == 0 &&
@ -756,7 +758,7 @@ final class Scanner
} }
/// Check if the next token is DOCUMENT-END: ^ '...' (' '|'\n') /// Check if the next token is DOCUMENT-END: ^ '...' (' '|'\n')
bool checkDocumentEnd() @safe pure nothrow @nogc bool checkDocumentEnd() @safe
{ {
// Check one char first, then all 3, to prevent reading outside the buffer. // Check one char first, then all 3, to prevent reading outside the buffer.
return reader_.column == 0 && return reader_.column == 0 &&
@ -766,7 +768,7 @@ final class Scanner
} }
/// Check if the next token is BLOCK-ENTRY: '-' (' '|'\n') /// Check if the next token is BLOCK-ENTRY: '-' (' '|'\n')
bool checkBlockEntry() @safe pure nothrow @nogc bool checkBlockEntry() @safe
{ {
return searchAllWhitespace.canFind(reader_.peek(1)); return searchAllWhitespace.canFind(reader_.peek(1));
} }
@ -774,7 +776,7 @@ final class Scanner
/// Check if the next token is KEY(flow context): '?' /// Check if the next token is KEY(flow context): '?'
/// ///
/// or KEY(block context): '?' (' '|'\n') /// or KEY(block context): '?' (' '|'\n')
bool checkKey() @safe pure nothrow @nogc bool checkKey() @safe
{ {
return (flowLevel_ > 0 || searchAllWhitespace.canFind(reader_.peek(1))); return (flowLevel_ > 0 || searchAllWhitespace.canFind(reader_.peek(1)));
} }
@ -782,7 +784,7 @@ final class Scanner
/// Check if the next token is VALUE(flow context): ':' /// Check if the next token is VALUE(flow context): ':'
/// ///
/// or VALUE(block context): ':' (' '|'\n') /// or VALUE(block context): ':' (' '|'\n')
bool checkValue() @safe pure nothrow @nogc bool checkValue() @safe
{ {
return flowLevel_ > 0 || searchAllWhitespace.canFind(reader_.peek(1)); return flowLevel_ > 0 || searchAllWhitespace.canFind(reader_.peek(1));
} }
@ -801,7 +803,7 @@ final class Scanner
/// Note that we limit the last rule to the block context (except the /// Note that we limit the last rule to the block context (except the
/// '-' character) because we want the flow context to be space /// '-' character) because we want the flow context to be space
/// independent. /// independent.
bool checkPlain() @safe pure nothrow @nogc bool checkPlain() @safe
{ {
const c = reader_.peek(); const c = reader_.peek();
mixin FastCharSearch!"-?:,[]{}#&*!|>\'\"%@` \t\0\n\r\u0085\u2028\u2029"d mixin FastCharSearch!"-?:,[]{}#&*!|>\'\"%@` \t\0\n\r\u0085\u2028\u2029"d
@ -815,7 +817,7 @@ final class Scanner
} }
/// Move to the next non-space character. /// Move to the next non-space character.
void findNextNonSpace() @safe pure nothrow @nogc void findNextNonSpace() @safe
{ {
while(reader_.peekByte() == ' ') { reader_.forward(); } while(reader_.peekByte() == ' ') { reader_.forward(); }
} }
@ -826,8 +828,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanAlphaNumericToSlice(string name)(const Mark startMark) void scanAlphaNumericToSlice(string name)(const Mark startMark) @system
@system pure nothrow @nogc
{ {
size_t length = 0; size_t length = 0;
dchar c = reader_.peek(); dchar c = reader_.peek();
@ -845,7 +846,7 @@ final class Scanner
} }
/// Scan and throw away all characters until next line break. /// Scan and throw away all characters until next line break.
void scanToNextBreak() @safe pure nothrow @nogc void scanToNextBreak() @safe
{ {
while(!searchAllBreaks.canFind(reader_.peek())) { reader_.forward(); } while(!searchAllBreaks.canFind(reader_.peek())) { reader_.forward(); }
} }
@ -854,7 +855,7 @@ final class Scanner
/// ///
/// Assumes that the caller is building a slice in Reader, and puts the scanned /// Assumes that the caller is building a slice in Reader, and puts the scanned
/// characters into that slice. /// characters into that slice.
void scanToNextBreakToSlice() @system pure nothrow @nogc void scanToNextBreakToSlice() @system
{ {
uint length = 0; uint length = 0;
while(!searchAllBreaks.canFind(reader_.peek(length))) while(!searchAllBreaks.canFind(reader_.peek(length)))
@ -874,7 +875,7 @@ final class Scanner
/// We do not yet support BOM inside the stream as the /// We do not yet support BOM inside the stream as the
/// specification requires. Any such mark will be considered as a part /// specification requires. Any such mark will be considered as a part
/// of the document. /// of the document.
void scanToNextToken() @safe pure nothrow @nogc void scanToNextToken() @safe
{ {
// TODO(PyYAML): We need to make tab handling rules more sane. A good rule is: // TODO(PyYAML): We need to make tab handling rules more sane. A good rule is:
// Tabs cannot precede tokens // Tabs cannot precede tokens
@ -904,7 +905,7 @@ final class Scanner
} }
/// Scan directive token. /// Scan directive token.
Token scanDirective() @trusted pure nothrow Token scanDirective() @trusted
{ {
Mark startMark = reader_.mark; Mark startMark = reader_.mark;
// Skip the '%'. // Skip the '%'.
@ -948,7 +949,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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
{ {
// Scan directive name. // Scan directive name.
scanAlphaNumericToSlice!"a directive"(startMark); scanAlphaNumericToSlice!"a directive"(startMark);
@ -965,8 +966,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanYAMLDirectiveValueToSlice(const Mark startMark) void scanYAMLDirectiveValueToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
findNextNonSpace(); findNextNonSpace();
@ -999,8 +999,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanYAMLDirectiveNumberToSlice(const Mark startMark) void scanYAMLDirectiveNumberToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
if(!isDigit(reader_.peek())) if(!isDigit(reader_.peek()))
{ {
@ -1024,8 +1023,7 @@ final class Scanner
/// Returns: Length of tag handle (which is before tag prefix) in scanned data /// Returns: Length of tag handle (which is before tag prefix) in scanned data
/// ///
/// 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.
uint scanTagDirectiveValueToSlice(const Mark startMark) uint scanTagDirectiveValueToSlice(const Mark startMark) @system
@system pure nothrow
{ {
findNextNonSpace(); findNextNonSpace();
const startLength = reader_.sliceBuilder.length; const startLength = reader_.sliceBuilder.length;
@ -1044,8 +1042,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanTagDirectiveHandleToSlice(const Mark startMark) void scanTagDirectiveHandleToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
scanTagHandleToSlice!"directive"(startMark); scanTagHandleToSlice!"directive"(startMark);
if(error_) { return; } if(error_) { return; }
@ -1060,8 +1057,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanTagDirectivePrefixToSlice(const Mark startMark) void scanTagDirectivePrefixToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
scanTagURIToSlice!"directive"(startMark); scanTagURIToSlice!"directive"(startMark);
if(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())) { return; } if(" \0\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())) { return; }
@ -1072,7 +1068,7 @@ final class Scanner
/// Scan (and ignore) ignored line after a directive. /// Scan (and ignore) ignored line after a directive.
/// ///
/// 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 scanDirectiveIgnoredLine(const Mark startMark) @safe pure nothrow @nogc void scanDirectiveIgnoredLine(const Mark startMark) @safe
{ {
findNextNonSpace(); findNextNonSpace();
if(reader_.peekByte() == '#') { scanToNextBreak(); } if(reader_.peekByte() == '#') { scanToNextBreak(); }
@ -1098,7 +1094,7 @@ final class Scanner
/// Therefore we restrict aliases to ASCII alphanumeric characters. /// Therefore we restrict aliases to ASCII alphanumeric characters.
/// ///
/// 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.
Token scanAnchor(const TokenID id) @trusted pure nothrow @nogc Token scanAnchor(const TokenID id) @trusted
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
const dchar i = reader_.get(); const dchar i = reader_.get();
@ -1134,7 +1130,7 @@ final class Scanner
/// Scan a tag token. /// Scan a tag token.
/// ///
/// 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.
Token scanTag() @trusted pure nothrow @nogc Token scanTag() @trusted
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
dchar c = reader_.peek(1); dchar c = reader_.peek(1);
@ -1214,7 +1210,7 @@ final class Scanner
/// Scan a block scalar token with specified style. /// Scan a block scalar token with specified style.
/// ///
/// 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.
Token scanBlockScalar(const ScalarStyle style) @trusted pure nothrow @nogc Token scanBlockScalar(const ScalarStyle style) @trusted
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
@ -1356,8 +1352,7 @@ final class Scanner
/// Scan chomping and indentation indicators of a scalar token. /// Scan chomping and indentation indicators of a scalar token.
/// ///
/// 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.
Tuple!(Chomping, int) scanBlockScalarIndicators(const Mark startMark) Tuple!(Chomping, int) scanBlockScalarIndicators(const Mark startMark) @safe
@safe pure nothrow @nogc
{ {
auto chomping = Chomping.Clip; auto chomping = Chomping.Clip;
int increment = int.min; int increment = int.min;
@ -1393,7 +1388,7 @@ final class Scanner
/// ///
/// c = The character that may be a chomping indicator. /// c = The character that may be a chomping indicator.
/// chomping = Write the chomping value here, if detected. /// chomping = Write the chomping value here, if detected.
bool getChomping(ref dchar c, ref Chomping chomping) @safe pure nothrow @nogc bool getChomping(ref dchar c, ref Chomping chomping) @safe
{ {
if(!"+-"d.canFind(c)) { return false; } if(!"+-"d.canFind(c)) { return false; }
chomping = c == '+' ? Chomping.Keep : Chomping.Strip; chomping = c == '+' ? Chomping.Keep : Chomping.Strip;
@ -1415,8 +1410,7 @@ final class Scanner
/// startMark = Mark for error messages. /// startMark = Mark for error messages.
/// ///
/// 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.
bool getIncrement(ref dchar c, ref int increment, const Mark startMark) bool getIncrement(ref dchar c, ref int increment, const Mark startMark) @safe
@safe pure nothrow @nogc
{ {
if(!c.isDigit) { return false; } if(!c.isDigit) { return false; }
// Convert a digit to integer. // Convert a digit to integer.
@ -1436,7 +1430,7 @@ final class Scanner
/// Scan (and ignore) ignored line in a block scalar. /// Scan (and ignore) ignored line in a block scalar.
/// ///
/// 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 scanBlockScalarIgnoredLine(const Mark startMark) @safe pure nothrow @nogc void scanBlockScalarIgnoredLine(const Mark startMark) @safe
{ {
findNextNonSpace(); findNextNonSpace();
if(reader_.peekByte()== '#') { scanToNextBreak(); } if(reader_.peekByte()== '#') { scanToNextBreak(); }
@ -1454,8 +1448,7 @@ final class Scanner
/// ///
/// Assumes that the caller is building a slice in Reader, and puts the scanned /// Assumes that the caller is building a slice in Reader, and puts the scanned
/// characters into that slice. /// characters into that slice.
Tuple!(uint, Mark) scanBlockScalarIndentationToSlice() Tuple!(uint, Mark) scanBlockScalarIndentationToSlice() @system
@system pure nothrow @nogc
{ {
uint maxIndent; uint maxIndent;
Mark endMark = reader_.mark; Mark endMark = reader_.mark;
@ -1479,7 +1472,7 @@ final class Scanner
/// ///
/// Assumes that the caller is building a slice in Reader, and puts the scanned /// Assumes that the caller is building a slice in Reader, and puts the scanned
/// characters into that slice. /// characters into that slice.
Mark scanBlockScalarBreaksToSlice(const uint indent) @trusted pure nothrow @nogc Mark scanBlockScalarBreaksToSlice(const uint indent) @trusted
{ {
Mark endMark = reader_.mark; Mark endMark = reader_.mark;
@ -1497,7 +1490,7 @@ final class Scanner
/// Scan a qouted flow scalar token with specified quotes. /// Scan a qouted flow scalar token with specified quotes.
/// ///
/// 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.
Token scanFlowScalar(const ScalarStyle quotes) @trusted pure nothrow @nogc Token scanFlowScalar(const ScalarStyle quotes) @trusted
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
const quote = reader_.get(); const quote = reader_.get();
@ -1528,7 +1521,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 scanFlowScalarNonSpacesToSlice(const ScalarStyle quotes, const Mark startMark) void scanFlowScalarNonSpacesToSlice(const ScalarStyle quotes, const Mark startMark)
@system pure nothrow @nogc @system
{ {
for(;;) with(ScalarStyle) for(;;) with(ScalarStyle)
{ {
@ -1642,8 +1635,7 @@ final class Scanner
/// spaces into that slice. /// spaces into that slice.
/// ///
/// 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 scanFlowScalarSpacesToSlice(const Mark startMark) void scanFlowScalarSpacesToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
// Increase length as long as we see whitespace. // Increase length as long as we see whitespace.
size_t length = 0; size_t length = 0;
@ -1688,8 +1680,7 @@ final class Scanner
/// line breaks into that slice. /// line breaks into that slice.
/// ///
/// 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.
bool scanFlowScalarBreaksToSlice(const Mark startMark) bool scanFlowScalarBreaksToSlice(const Mark startMark) @system
@system pure nothrow @nogc
{ {
// True if at least one line break was found. // True if at least one line break was found.
bool anyBreaks; bool anyBreaks;
@ -1721,7 +1712,7 @@ final class Scanner
/// Scan plain scalar token (no block, no quotes). /// Scan plain scalar token (no block, no quotes).
/// ///
/// 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.
Token scanPlain() @trusted pure nothrow @nogc Token scanPlain() @trusted
{ {
// We keep track of the allowSimpleKey_ flag here. // We keep track of the allowSimpleKey_ flag here.
// Indentation rules are loosed for the flow context // Indentation rules are loosed for the flow context
@ -1818,7 +1809,7 @@ final class Scanner
/// ///
/// Assumes that the caller is building a slice in Reader, and puts the spaces /// Assumes that the caller is building a slice in Reader, and puts the spaces
/// into that slice. /// into that slice.
void scanPlainSpacesToSlice(const Mark startMark) @system pure nothrow @nogc void scanPlainSpacesToSlice(const Mark startMark) @system
{ {
// The specification is really confusing about tabs in plain scalars. // The specification is really confusing about tabs in plain scalars.
// We just forbid them completely. Do not use tabs in YAML! // We just forbid them completely. Do not use tabs in YAML!
@ -1882,8 +1873,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanTagHandleToSlice(string name)(const Mark startMark) void scanTagHandleToSlice(string name)(const Mark startMark) @system
@system pure nothrow @nogc
{ {
dchar c = reader_.peek(); dchar c = reader_.peek();
enum contextMsg = "While scanning a " ~ name; enum contextMsg = "While scanning a " ~ name;
@ -1920,8 +1910,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanTagURIToSlice(string name)(const Mark startMark) void scanTagURIToSlice(string name)(const Mark startMark) @trusted
@trusted pure nothrow @nogc
{ {
// Note: we do not check if URI is well-formed. // Note: we do not check if URI is well-formed.
dchar c = reader_.peek(); dchar c = reader_.peek();
@ -1963,8 +1952,7 @@ final class Scanner
/// characters into that slice. /// characters into that slice.
/// ///
/// 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 scanURIEscapesToSlice(string name)(const Mark startMark) void scanURIEscapesToSlice(string name)(const Mark startMark) @system
@system pure nothrow @nogc
{ {
// URI escapes encode a UTF-8 string. We store UTF-8 code units here for // URI escapes encode a UTF-8 string. We store UTF-8 code units here for
// decoding into UTF-32. // decoding into UTF-32.
@ -2060,7 +2048,7 @@ final class Scanner
/// '\u2028' : '\u2028' /// '\u2028' : '\u2028'
/// '\u2029 : '\u2029' /// '\u2029 : '\u2029'
/// no break : '\0' /// no break : '\0'
dchar scanLineBreak() @safe pure nothrow @nogc dchar scanLineBreak() @safe
{ {
// Fast path for ASCII line breaks. // Fast path for ASCII line breaks.
const b = reader_.peekByte(); const b = reader_.peekByte();