@safe pure nothrow @nogc and style in Token.

This commit is contained in:
Ferdinand Majerech 2014-07-23 02:54:34 +02:00
parent 8a378471e6
commit 15f5add86d

View file

@ -4,10 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
/**
* YAML tokens.
* Code based on PyYAML: http://www.pyyaml.org
*/
/// YAML tokens.
/// Code based on PyYAML: http://www.pyyaml.org
module dyaml.token;
@ -20,6 +18,7 @@ import dyaml.style;
package:
/// Token types.
enum TokenID : ubyte
{
@ -46,11 +45,9 @@ enum TokenID : ubyte
Scalar /// SCALAR
}
/**
* Token produced by scanner.
*
* 32 bytes on 64-bit.
*/
/// Token produced by scanner.
///
/// 32 bytes on 64-bit.
struct Token
{
@disable int opCmp(ref Token);
@ -69,41 +66,37 @@ struct Token
Encoding encoding;
/// Get string representation of the token ID.
@property string idString() const @trusted {return to!string(id);}
@property string idString() @safe pure const {return id.to!string;}
}
/**
* Construct a directive token.
*
* Params: start = Start position of the token.
* end = End position of the token.
* value = Value of the token.
*/
Token directiveToken(const Mark start, const Mark end, const string value) pure @safe nothrow
@safe pure nothrow @nogc:
/// Construct a directive token.
///
/// Params: start = Start position of the token.
/// end = End position of the token.
/// value = Value of the token.
Token directiveToken(const Mark start, const Mark end, const string value)
{
return Token(value, start, end, TokenID.Directive);
}
/**
* Construct a simple (no value) token with specified type.
*
* Params: id = Type of the token.
* start = Start position of the token.
* end = End position of the token.
*/
Token simpleToken(TokenID id)(const Mark start, const Mark end) pure @safe nothrow
/// Construct a simple (no value) token with specified type.
///
/// Params: id = Type of the token.
/// start = Start position of the token.
/// end = End position of the token.
Token simpleToken(TokenID id)(const Mark start, const Mark end)
{
return Token(null, start, end, id);
}
/**
* Construct a stream start token.
*
* Params: start = Start position of the token.
* end = End position of the token.
* encoding = Encoding of the stream.
*/
Token streamStartToken(const Mark start, const Mark end, const Encoding encoding) pure @safe nothrow
/// Construct a stream start token.
///
/// Params: start = Start position of the token.
/// end = End position of the token.
/// encoding = Encoding of the stream.
Token streamStartToken(const Mark start, const Mark end, const Encoding encoding)
{
return Token(null, start, end, TokenID.StreamStart, ScalarStyle.Invalid, encoding);
}
@ -118,15 +111,13 @@ alias simpleToken!(TokenID.Value) valueToken;
alias simpleToken!(TokenID.BlockEntry) blockEntryToken;
alias simpleToken!(TokenID.FlowEntry) flowEntryToken;
/**
* Construct a simple token with value with specified type.
*
* Params: id = Type of the token.
* start = Start position of the token.
* end = End position of the token.
* value = Value of the token.
*/
Token simpleValueToken(TokenID id)(const Mark start, const Mark end, string value) pure @safe nothrow
/// Construct a simple token with value with specified type.
///
/// Params: id = Type of the token.
/// start = Start position of the token.
/// end = End position of the token.
/// value = Value of the token.
Token simpleValueToken(TokenID id)(const Mark start, const Mark end, const string value)
{
return Token(value, start, end, id);
}
@ -136,15 +127,13 @@ alias simpleValueToken!(TokenID.Tag) tagToken;
alias simpleValueToken!(TokenID.Alias) aliasToken;
alias simpleValueToken!(TokenID.Anchor) anchorToken;
/**
* Construct a scalar token.
*
* Params: start = Start position of the token.
* end = End position of the token.
* value = Value of the token.
* style = Style of the token.
*/
Token scalarToken(const Mark start, const Mark end, const string value, in ScalarStyle style) pure @safe nothrow
/// Construct a scalar token.
///
/// Params: start = Start position of the token.
/// end = End position of the token.
/// value = Value of the token.
/// style = Style of the token.
Token scalarToken(const Mark start, const Mark end, const string value, const ScalarStyle style)
{
return Token(value, start, end, TokenID.Scalar, style);
}