scanner.h
Go to the documentation of this file.
1 #ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
8 
9 #include <ios>
10 #include <string>
11 #include <queue>
12 #include <stack>
13 #include <set>
14 #include <map>
15 #include "ptr_vector.h"
16 #include "stream.h"
17 #include "token.h"
18 
19 namespace YAML_PM
20 {
21  class Node;
22  class RegEx;
23 
24  class Scanner
25  {
26  public:
27  Scanner(std::istream& in);
28  ~Scanner();
29 
30  // token queue management (hopefully this looks kinda stl-ish)
31  bool empty();
32  void pop();
33  Token& peek();
34 
35  private:
36  struct IndentMarker {
37  enum INDENT_TYPE { MAP, SEQ, NONE };
39  IndentMarker(int column_, INDENT_TYPE type_): column(column_), type(type_), status(VALID), pStartToken(0) {}
40 
41  int column;
45  };
46 
48 
49  private:
50  // scanning
51  void EnsureTokensInQueue();
52  void ScanNextToken();
53  void ScanToNextToken();
54  void StartStream();
55  void EndStream();
57 
58  bool InFlowContext() const { return !m_flows.empty(); }
59  bool InBlockContext() const { return m_flows.empty(); }
60  int GetFlowLevel() const { return m_flows.size(); }
61 
64  void PopIndentToHere();
65  void PopAllIndents();
66  void PopIndent();
67  int GetTopIndent() const;
68 
69  // checking input
70  bool CanInsertPotentialSimpleKey() const;
71  bool ExistsActiveSimpleKey() const;
73  void InvalidateSimpleKey();
74  bool VerifySimpleKey();
75  void PopAllSimpleKeys();
76 
77  void ThrowParserException(const std::string& msg) const;
78 
79  bool IsWhitespaceToBeEaten(char ch);
80  const RegEx& GetValueRegex() const;
81 
82  struct SimpleKey {
83  SimpleKey(const Mark& mark_, int flowLevel_);
84 
85  void Validate();
86  void Invalidate();
87 
89  int flowLevel;
91  Token *pMapStart, *pKey;
92  };
93 
94  // and the tokens
95  void ScanDirective();
96  void ScanDocStart();
97  void ScanDocEnd();
98  void ScanBlockSeqStart();
99  void ScanBlockMapSTart();
100  void ScanBlockEnd();
101  void ScanBlockEntry();
102  void ScanFlowStart();
103  void ScanFlowEnd();
104  void ScanFlowEntry();
105  void ScanKey();
106  void ScanValue();
107  void ScanAnchorOrAlias();
108  void ScanTag();
109  void ScanPlainScalar();
110  void ScanQuotedScalar();
111  void ScanBlockScalar();
112 
113  private:
114  // the stream
116 
117  // the output (tokens)
118  std::queue<Token> m_tokens;
119 
120  // state info
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;
128  };
129 }
130 
131 #endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
132 
void ScanBlockScalar()
Definition: scantoken.cpp:377
int GetFlowLevel() const
Definition: scanner.h:60
Stream INPUT
Definition: scanner.h:115
void ScanFlowStart()
Definition: scantoken.cpp:87
std::queue< Token > m_tokens
Definition: scanner.h:118
std::stack< IndentMarker * > m_indents
Definition: scanner.h:125
bool ExistsActiveSimpleKey() const
Definition: simplekey.cpp:48
void ScanDirective()
Definition: scantoken.cpp:17
void ScanPlainScalar()
Definition: scantoken.cpp:299
IndentMarker * PushIndentTo(int column, IndentMarker::INDENT_TYPE type)
Definition: scanner.cpp:278
IndentMarker * pIndent
Definition: scanner.h:90
::std::string string
Definition: gtest.h:1979
void ScanFlowEntry()
Definition: scantoken.cpp:135
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const
Definition: scanner.cpp:263
std::stack< FLOW_MARKER > m_flows
Definition: scanner.h:127
void EndStream()
Definition: scanner.cpp:244
const RegEx & GetValueRegex() const
Definition: scanner.cpp:223
void PopIndent()
Definition: scanner.cpp:349
bool m_simpleKeyAllowed
Definition: scanner.h:122
void EnsureTokensInQueue()
Definition: scanner.cpp:57
bool InBlockContext() const
Definition: scanner.h:59
bool IsWhitespaceToBeEaten(char ch)
Definition: scanner.cpp:210
int GetTopIndent() const
Definition: scanner.cpp:366
void ScanToNextToken()
Definition: scanner.cpp:165
void PopAllIndents()
Definition: scanner.cpp:331
void ScanBlockEntry()
Definition: scantoken.cpp:155
void InvalidateSimpleKey()
Definition: simplekey.cpp:87
void ScanBlockSeqStart()
void PopIndentToHere()
Definition: scanner.cpp:307
void ScanQuotedScalar()
Definition: scantoken.cpp:335
void ScanNextToken()
Definition: scanner.cpp:88
ptr_vector< IndentMarker > m_indentRefs
Definition: scanner.h:126
bool InFlowContext() const
Definition: scanner.h:58
void ScanBlockMapSTart()
void ScanAnchorOrAlias()
Definition: scantoken.cpp:225
bool m_canBeJSONFlow
Definition: scanner.h:123
Scanner(std::istream &in)
Definition: scanner.cpp:10
void InsertPotentialSimpleKey()
Definition: simplekey.cpp:60
void ThrowParserException(const std::string &msg) const
Definition: scanner.cpp:377
bool VerifySimpleKey()
Definition: simplekey.cpp:104
bool CanInsertPotentialSimpleKey() const
Definition: simplekey.cpp:37
std::stack< SimpleKey > m_simpleKeys
Definition: scanner.h:124
void ScanDocStart()
Definition: scantoken.cpp:59
void StartStream()
Definition: scanner.cpp:233
bool m_startedStream
Definition: scanner.h:121
void PopAllSimpleKeys()
Definition: simplekey.cpp:133
Token & peek()
Definition: scanner.cpp:38
Token * PushToken(Token::TYPE type)
Definition: scanner.cpp:257
bool m_endedStream
Definition: scanner.h:121
IndentMarker(int column_, INDENT_TYPE type_)
Definition: scanner.h:39


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:03