Commit 148da471 by Jesse Beder

Update documentation for Scanner and AnchorDict, and fix formatting.

parent a45a6174
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include "../anchor.h" #include "../anchor.h"
namespace YAML { namespace YAML {
/// AnchorDict /**
/// . An object that stores and retrieves values correlating to anchor_t * An object that stores and retrieves values correlating to {@link anchor_t}
/// values. * values.
/// . Efficient implementation that can make assumptions about how anchor_t *
/// values are assigned by the Parser class. * <p>Efficient implementation that can make assumptions about how
* {@code anchor_t} values are assigned by the {@link Parser} class.
*/
template <class T> template <class T>
class AnchorDict { class AnchorDict {
public: public:
......
...@@ -24,15 +24,24 @@ namespace YAML { ...@@ -24,15 +24,24 @@ namespace YAML {
class Node; class Node;
class RegEx; class RegEx;
/**
* A scanner transforms a stream of characters into a stream of tokens.
*/
class Scanner { class Scanner {
public: public:
Scanner(std::istream &in); explicit Scanner(std::istream &in);
~Scanner(); ~Scanner();
// token queue management (hopefully this looks kinda stl-ish) /** Returns true if there are no more tokens to be read. */
bool empty(); bool empty();
/** Removes the next token in the queue. */
void pop(); void pop();
/** Returns, but does not remove, the next token in the queue. */
Token &peek(); Token &peek();
/** Returns the current mark in the input stream. */
Mark mark() const; Mark mark() const;
private: private:
...@@ -52,11 +61,29 @@ class Scanner { ...@@ -52,11 +61,29 @@ class Scanner {
private: private:
// scanning // scanning
/**
* Scans until there's a valid token at the front of the queue, or the queue
* is empty. The state can be checked by {@link #empty}, and the next token
* retrieved by {@link #peek}.
*/
void EnsureTokensInQueue(); void EnsureTokensInQueue();
/**
* The main scanning function; this method branches out to scan whatever the
* next token should be.
*/
void ScanNextToken(); void ScanNextToken();
/** Eats the input stream until it reaches the next token-like thing. */
void ScanToNextToken(); void ScanToNextToken();
/** Sets the initial conditions for starting a stream. */
void StartStream(); void StartStream();
/** Closes out the stream, finish up, etc. */
void EndStream(); void EndStream();
Token *PushToken(Token::TYPE type); Token *PushToken(Token::TYPE type);
bool InFlowContext() const { return !m_flows.empty(); } bool InFlowContext() const { return !m_flows.empty(); }
...@@ -64,9 +91,29 @@ class Scanner { ...@@ -64,9 +91,29 @@ class Scanner {
std::size_t GetFlowLevel() const { return m_flows.size(); } std::size_t GetFlowLevel() const { return m_flows.size(); }
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const; Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const;
/**
* Pushes an indentation onto the stack, and enqueues the proper token
* (sequence start or mapping start).
*
* @return the indent marker it generates (if any).
*/
IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type); IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type);
/**
* Pops indentations off the stack until it reaches the current indentation
* level, and enqueues the proper token each time. Then pops all invalid
* indentations off.
*/
void PopIndentToHere(); void PopIndentToHere();
/**
* Pops all indentations (except for the base empty one) off the stack, and
* enqueues the proper token each time.
*/
void PopAllIndents(); void PopAllIndents();
/** Pops a single indent, pushing the proper token. */
void PopIndent(); void PopIndent();
int GetTopIndent() const; int GetTopIndent() const;
...@@ -78,9 +125,17 @@ class Scanner { ...@@ -78,9 +125,17 @@ class Scanner {
bool VerifySimpleKey(); bool VerifySimpleKey();
void PopAllSimpleKeys(); void PopAllSimpleKeys();
/**
* Throws a ParserException with the current token location (if available),
* and does not parse any more tokens.
*/
void ThrowParserException(const std::string &msg) const; void ThrowParserException(const std::string &msg) const;
bool IsWhitespaceToBeEaten(char ch); bool IsWhitespaceToBeEaten(char ch);
/**
* Returns the appropriate regex to check if the next token is a value token.
*/
const RegEx &GetValueRegex() const; const RegEx &GetValueRegex() const;
struct SimpleKey { struct SimpleKey {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment