Scanner style fixes.

This commit is contained in:
Ferdinand Majerech 2014-07-23 18:26:39 +02:00
parent 2a8f78f46f
commit d4a7b066d0

View file

@ -71,84 +71,79 @@ class ScannerException : MarkedYAMLException
private alias ScannerException Error; private alias ScannerException Error;
private alias MarkedYAMLExceptionData ErrorData; private alias MarkedYAMLExceptionData ErrorData;
///Generates tokens from data provided by a Reader. /// Generates tokens from data provided by a Reader.
final class Scanner final class Scanner
{ {
private: private:
/** /// A simple key is a key that is not denoted by the '?' indicator.
* A simple key is a key that is not denoted by the '?' indicator. /// For example:
* For example: /// ---
* --- /// block simple key: value
* block simple key: value /// ? not a simple key:
* ? not a simple key: /// : { flow simple key: value }
* : { flow simple key: value } /// We emit the KEY token before all keys, so when we find a potential simple
* We emit the KEY token before all keys, so when we find a potential /// key, we try to locate the corresponding ':' indicator. Simple keys should be
* simple key, we try to locate the corresponding ':' indicator. /// limited to a single line and 1024 characters.
* Simple keys should be limited to a single line and 1024 characters. ///
* /// 16 bytes on 64-bit.
* 16 bytes on 64-bit.
*/
static struct SimpleKey static struct SimpleKey
{ {
///Character index in reader where the key starts. /// Character index in reader where the key starts.
uint charIndex = uint.max; uint charIndex = uint.max;
///Index of the key token from start (first token scanned being 0). /// Index of the key token from start (first token scanned being 0).
uint tokenIndex; uint tokenIndex;
///Line the key starts at. /// Line the key starts at.
uint line; uint line;
///Column the key starts at. /// Column the key starts at.
ushort column; ushort column;
///Is this required to be a simple key? /// Is this required to be a simple key?
bool required; bool required;
///Is this struct "null" (invalid)?. /// Is this struct "null" (invalid)?.
bool isNull; bool isNull;
} }
///Block chomping types. /// Block chomping types.
enum Chomping enum Chomping
{ {
///Strip all trailing line breaks. '-' indicator. /// Strip all trailing line breaks. '-' indicator.
Strip, Strip,
///Line break of the last line is preserved, others discarded. Default. /// Line break of the last line is preserved, others discarded. Default.
Clip, Clip,
///All trailing line breaks are preserved. '+' indicator. /// All trailing line breaks are preserved. '+' indicator.
Keep Keep
} }
///Reader used to read from a file/stream. /// Reader used to read from a file/stream.
Reader reader_; Reader reader_;
///Are we done scanning? /// Are we done scanning?
bool done_; bool done_;
///Level of nesting in flow context. If 0, we're in block context. /// Level of nesting in flow context. If 0, we're in block context.
uint flowLevel_; uint flowLevel_;
///Current indentation level. /// Current indentation level.
int indent_ = -1; int indent_ = -1;
///Past indentation levels. Used as a stack. /// Past indentation levels. Used as a stack.
Array!int indents_; Array!int indents_;
///Processed tokens not yet emitted. Used as a queue. /// Processed tokens not yet emitted. Used as a queue.
Queue!Token tokens_; Queue!Token tokens_;
///Number of tokens emitted through the getToken method. /// Number of tokens emitted through the getToken method.
uint tokensTaken_; uint tokensTaken_;
/** /// Can a simple key start at the current position? A simple key may start:
* Can a simple key start at the current position? A simple key may /// - at the beginning of the line, not counting indentation spaces
* start: /// (in block context),
* - at the beginning of the line, not counting indentation spaces /// - after '{', '[', ',' (in the flow context),
* (in block context), /// - after '?', ':', '-' (in the block context).
* - after '{', '[', ',' (in the flow context), /// In the block context, this flag also signifies if a block collection
* - after '?', ':', '-' (in the block context). /// may start at the current position.
* In the block context, this flag also signifies if a block collection
* may start at the current position.
*/
bool allowSimpleKey_ = true; bool allowSimpleKey_ = true;
///Possible simple keys indexed by flow levels. /// Possible simple keys indexed by flow levels.
SimpleKey[] possibleSimpleKeys_; SimpleKey[] possibleSimpleKeys_;
///Used for constructing strings while limiting reallocation. /// Used for constructing strings while limiting reallocation.
Appender!(dchar[]) appender_; Appender!(dchar[]) appender_;