1 #ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 16 #include "ptr_vector.h" 19 #include "yaml-cpp/mark.h" 30 explicit Scanner(std::istream &in);
47 enum INDENT_TYPE { MAP, SEQ, NONE };
48 enum STATUS { VALID, INVALID, UNKNOWN };
49 IndentMarker(
int column_, INDENT_TYPE type_)
50 : column(column_), type(type_), status(VALID), pStartToken(
nullptr) {}
58 enum FLOW_MARKER { FLOW_MAP, FLOW_SEQ };
85 Token *PushToken(Token::TYPE type);
87 bool InFlowContext()
const {
return !m_flows.empty(); }
88 bool InBlockContext()
const {
return m_flows.empty(); }
89 std::size_t GetFlowLevel()
const {
return m_flows.size(); }
91 Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type)
const;
99 IndentMarker *
PushIndentTo(
int column, IndentMarker::INDENT_TYPE type);
116 int GetTopIndent()
const;
119 bool CanInsertPotentialSimpleKey()
const;
120 bool ExistsActiveSimpleKey()
const;
121 void InsertPotentialSimpleKey();
122 void InvalidateSimpleKey();
123 bool VerifySimpleKey();
124 void PopAllSimpleKeys();
132 bool IsWhitespaceToBeEaten(
char ch);
140 SimpleKey(
const Mark &mark_, std::size_t flowLevel_);
146 std::size_t flowLevel;
147 IndentMarker *pIndent;
148 Token *pMapStart, *pKey;
152 void ScanDirective();
155 void ScanBlockSeqStart();
156 void ScanBlockMapSTart();
158 void ScanBlockEntry();
159 void ScanFlowStart();
161 void ScanFlowEntry();
164 void ScanAnchorOrAlias();
166 void ScanPlainScalar();
167 void ScanQuotedScalar();
168 void ScanBlockScalar();
175 std::queue<Token> m_tokens;
178 bool m_startedStream, m_endedStream;
179 bool m_simpleKeyAllowed;
180 bool m_canBeJSONFlow;
181 std::stack<SimpleKey> m_simpleKeys;
182 std::stack<IndentMarker *> m_indents;
183 ptr_vector<IndentMarker> m_indentRefs;
184 std::stack<FLOW_MARKER> m_flows;
188 #endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 void ThrowParserException(const std::string &msg) const
Throws a ParserException with the current token location (if available), and does not parse any more ...
void PopIndentToHere()
Pops indentations off the stack until it reaches the current indentation level, and enqueues the prop...
void ScanToNextToken()
Eats the input stream until it reaches the next token-like thing.
void ScanNextToken()
The main scanning function; this method branches out to scan whatever the next token should be...
Token & peek()
Returns, but does not remove, the next token in the queue.
void EndStream()
Closes out the stream, finish up, etc.
void StartStream()
Sets the initial conditions for starting a stream.
bool empty()
Returns true if there are no more tokens to be read.
const RegEx & GetValueRegex() const
Returns the appropriate regex to check if the next token is a value token.
void EnsureTokensInQueue()
Scans until there's a valid token at the front of the queue, or the queue is empty.
void PopIndent()
Pops a single indent, pushing the proper token.
void pop()
Removes the next token in the queue.
void PopAllIndents()
Pops all indentations (except for the base empty one) off the stack, and enqueues the proper token ea...
Mark mark() const
Returns the current mark in the input stream.
IndentMarker * PushIndentTo(int column, IndentMarker::INDENT_TYPE type)
Pushes an indentation onto the stack, and enqueues the proper token (sequence start or mapping start)...
A scanner transforms a stream of characters into a stream of tokens.
Definition: scanner.h:28