@safe pure nothrow @nogc and style in Token.
This commit is contained in:
parent
8a378471e6
commit
15f5add86d
|
@ -4,10 +4,8 @@
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
/**
|
/// YAML tokens.
|
||||||
* YAML tokens.
|
/// Code based on PyYAML: http://www.pyyaml.org
|
||||||
* Code based on PyYAML: http://www.pyyaml.org
|
|
||||||
*/
|
|
||||||
module dyaml.token;
|
module dyaml.token;
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +18,8 @@ import dyaml.style;
|
||||||
|
|
||||||
|
|
||||||
package:
|
package:
|
||||||
///Token types.
|
|
||||||
|
/// Token types.
|
||||||
enum TokenID : ubyte
|
enum TokenID : ubyte
|
||||||
{
|
{
|
||||||
Invalid = 0, /// Invalid (uninitialized) token
|
Invalid = 0, /// Invalid (uninitialized) token
|
||||||
|
@ -46,69 +45,63 @@ enum TokenID : ubyte
|
||||||
Scalar /// SCALAR
|
Scalar /// SCALAR
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Token produced by scanner.
|
||||||
* Token produced by scanner.
|
///
|
||||||
*
|
/// 32 bytes on 64-bit.
|
||||||
* 32 bytes on 64-bit.
|
|
||||||
*/
|
|
||||||
struct Token
|
struct Token
|
||||||
{
|
{
|
||||||
@disable int opCmp(ref Token);
|
@disable int opCmp(ref Token);
|
||||||
|
|
||||||
///Value of the token, if any.
|
/// Value of the token, if any.
|
||||||
string value;
|
string value;
|
||||||
///Start position of the token in file/stream.
|
/// Start position of the token in file/stream.
|
||||||
Mark startMark;
|
Mark startMark;
|
||||||
///End position of the token in file/stream.
|
/// End position of the token in file/stream.
|
||||||
Mark endMark;
|
Mark endMark;
|
||||||
///Token type.
|
/// Token type.
|
||||||
TokenID id;
|
TokenID id;
|
||||||
///Style of scalar token, if this is a scalar token.
|
/// Style of scalar token, if this is a scalar token.
|
||||||
ScalarStyle style;
|
ScalarStyle style;
|
||||||
///Encoding, if this is a stream start token.
|
/// Encoding, if this is a stream start token.
|
||||||
Encoding encoding;
|
Encoding encoding;
|
||||||
|
|
||||||
///Get string representation of the token ID.
|
/// 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;}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@safe pure nothrow @nogc:
|
||||||
* Construct a directive token.
|
|
||||||
*
|
/// Construct a directive token.
|
||||||
* Params: start = Start position of the token.
|
///
|
||||||
* end = End position of the token.
|
/// Params: start = Start position of the token.
|
||||||
* value = Value 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
|
Token directiveToken(const Mark start, const Mark end, const string value)
|
||||||
{
|
{
|
||||||
return Token(value, start, end, TokenID.Directive);
|
return Token(value, start, end, TokenID.Directive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Construct a simple (no value) token with specified type.
|
||||||
* Construct a simple (no value) token with specified type.
|
///
|
||||||
*
|
/// Params: id = Type of the token.
|
||||||
* Params: id = Type of the token.
|
/// start = Start position of the token.
|
||||||
* start = Start position of the token.
|
/// end = End position of the token.
|
||||||
* end = End position of the token.
|
Token simpleToken(TokenID id)(const Mark start, const Mark end)
|
||||||
*/
|
|
||||||
Token simpleToken(TokenID id)(const Mark start, const Mark end) pure @safe nothrow
|
|
||||||
{
|
{
|
||||||
return Token(null, start, end, id);
|
return Token(null, start, end, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Construct a stream start token.
|
||||||
* Construct a stream start token.
|
///
|
||||||
*
|
/// Params: start = Start position of the token.
|
||||||
* Params: start = Start position of the token.
|
/// end = End position of the token.
|
||||||
* end = End position of the token.
|
/// encoding = Encoding of the stream.
|
||||||
* encoding = Encoding of the stream.
|
Token streamStartToken(const Mark start, const Mark end, const Encoding encoding)
|
||||||
*/
|
|
||||||
Token streamStartToken(const Mark start, const Mark end, const Encoding encoding) pure @safe nothrow
|
|
||||||
{
|
{
|
||||||
return Token(null, start, end, TokenID.StreamStart, ScalarStyle.Invalid, encoding);
|
return Token(null, start, end, TokenID.StreamStart, ScalarStyle.Invalid, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
///Aliases for construction of simple token types.
|
/// Aliases for construction of simple token types.
|
||||||
alias simpleToken!(TokenID.StreamEnd) streamEndToken;
|
alias simpleToken!(TokenID.StreamEnd) streamEndToken;
|
||||||
alias simpleToken!(TokenID.BlockSequenceStart) blockSequenceStartToken;
|
alias simpleToken!(TokenID.BlockSequenceStart) blockSequenceStartToken;
|
||||||
alias simpleToken!(TokenID.BlockMappingStart) blockMappingStartToken;
|
alias simpleToken!(TokenID.BlockMappingStart) blockMappingStartToken;
|
||||||
|
@ -118,33 +111,29 @@ alias simpleToken!(TokenID.Value) valueToken;
|
||||||
alias simpleToken!(TokenID.BlockEntry) blockEntryToken;
|
alias simpleToken!(TokenID.BlockEntry) blockEntryToken;
|
||||||
alias simpleToken!(TokenID.FlowEntry) flowEntryToken;
|
alias simpleToken!(TokenID.FlowEntry) flowEntryToken;
|
||||||
|
|
||||||
/**
|
/// Construct a simple token with value with specified type.
|
||||||
* Construct a simple token with value with specified type.
|
///
|
||||||
*
|
/// Params: id = Type of the token.
|
||||||
* Params: id = Type of the token.
|
/// start = Start position of the token.
|
||||||
* start = Start position of the token.
|
/// end = End position of the token.
|
||||||
* end = End position of the token.
|
/// value = Value of the token.
|
||||||
* value = Value of the token.
|
Token simpleValueToken(TokenID id)(const Mark start, const Mark end, const string value)
|
||||||
*/
|
|
||||||
Token simpleValueToken(TokenID id)(const Mark start, const Mark end, string value) pure @safe nothrow
|
|
||||||
{
|
{
|
||||||
return Token(value, start, end, id);
|
return Token(value, start, end, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
///Alias for construction of tag token.
|
/// Alias for construction of tag token.
|
||||||
alias simpleValueToken!(TokenID.Tag) tagToken;
|
alias simpleValueToken!(TokenID.Tag) tagToken;
|
||||||
alias simpleValueToken!(TokenID.Alias) aliasToken;
|
alias simpleValueToken!(TokenID.Alias) aliasToken;
|
||||||
alias simpleValueToken!(TokenID.Anchor) anchorToken;
|
alias simpleValueToken!(TokenID.Anchor) anchorToken;
|
||||||
|
|
||||||
/**
|
/// Construct a scalar token.
|
||||||
* Construct a scalar token.
|
///
|
||||||
*
|
/// Params: start = Start position of the token.
|
||||||
* Params: start = Start position of the token.
|
/// end = End position of the token.
|
||||||
* end = End position of the token.
|
/// value = Value of the token.
|
||||||
* value = Value of the token.
|
/// style = Style of the token.
|
||||||
* style = Style of the token.
|
Token scalarToken(const Mark start, const Mark end, const string value, const ScalarStyle style)
|
||||||
*/
|
|
||||||
Token scalarToken(const Mark start, const Mark end, const string value, in ScalarStyle style) pure @safe nothrow
|
|
||||||
{
|
{
|
||||||
return Token(value, start, end, TokenID.Scalar, style);
|
return Token(value, start, end, TokenID.Scalar, style);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue