1 #ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
15 #include "ptr_vector.h"
27 Scanner(std::istream
& in
);
30 // token queue management (hopefully this looks kinda stl-ish)
37 enum INDENT_TYPE
{ MAP
, SEQ
, NONE
};
38 enum STATUS
{ VALID
, INVALID
, UNKNOWN
};
39 IndentMarker(int column_
, INDENT_TYPE type_
): column(column_
), type(type_
), status(VALID
), pStartToken(0) {}
47 enum FLOW_MARKER
{ FLOW_MAP
, FLOW_SEQ
};
51 void EnsureTokensInQueue();
53 void ScanToNextToken();
56 Token
*PushToken(Token::TYPE type
);
58 bool InFlowContext() const { return !m_flows
.empty(); }
59 bool InBlockContext() const { return m_flows
.empty(); }
60 int GetFlowLevel() const { return m_flows
.size(); }
62 Token::TYPE
GetStartTokenFor(IndentMarker::INDENT_TYPE type
) const;
63 IndentMarker
*PushIndentTo(int column
, IndentMarker::INDENT_TYPE type
);
64 void PopIndentToHere();
67 int GetTopIndent() const;
70 bool CanInsertPotentialSimpleKey() const;
71 bool ExistsActiveSimpleKey() const;
72 void InsertPotentialSimpleKey();
73 void InvalidateSimpleKey();
74 bool VerifySimpleKey();
75 void PopAllSimpleKeys();
77 void ThrowParserException(const std::string
& msg
) const;
79 bool IsWhitespaceToBeEaten(char ch
);
80 const RegEx
& GetValueRegex() const;
83 SimpleKey(const Mark
& mark_
, int flowLevel_
);
90 IndentMarker
*pIndent
;
91 Token
*pMapStart
, *pKey
;
98 void ScanBlockSeqStart();
99 void ScanBlockMapSTart();
101 void ScanBlockEntry();
102 void ScanFlowStart();
104 void ScanFlowEntry();
107 void ScanAnchorOrAlias();
109 void ScanPlainScalar();
110 void ScanQuotedScalar();
111 void ScanBlockScalar();
117 // the output (tokens)
118 std::queue
<Token
> m_tokens
;
121 bool m_startedStream
, m_endedStream
;
122 bool m_simpleKeyAllowed
;
123 bool m_canBeJSONFlow
;
124 std::stack
<SimpleKey
> m_simpleKeys
;
125 std::stack
<IndentMarker
*> m_indents
;
126 ptr_vector
<IndentMarker
> m_indentRefs
; // for "garbage collection"
127 std::stack
<FLOW_MARKER
> m_flows
;
131 #endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66