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 
63  IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type);
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;
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 
YAML_PM::Scanner::SimpleKey::pIndent
IndentMarker * pIndent
Definition: scanner.h:90
YAML_PM::Scanner::pop
void pop()
Definition: scanner.cpp:29
YAML_PM::Scanner::INPUT
Stream INPUT
Definition: scanner.h:115
YAML_PM::Scanner::GetStartTokenFor
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const
Definition: scanner.cpp:263
YAML_PM::Scanner::IndentMarker::IndentMarker
IndentMarker(int column_, INDENT_TYPE type_)
Definition: scanner.h:39
YAML_PM::Scanner::ScanFlowEnd
void ScanFlowEnd()
Definition: scantoken.cpp:104
YAML_PM::Scanner::InBlockContext
bool InBlockContext() const
Definition: scanner.h:59
YAML_PM::Scanner::ScanKey
void ScanKey()
Definition: scantoken.cpp:176
YAML_PM::Scanner::IndentMarker::VALID
@ VALID
Definition: scanner.h:38
YAML_PM::Scanner::PushToken
Token * PushToken(Token::TYPE type)
Definition: scanner.cpp:257
YAML_PM::Scanner::IndentMarker::MAP
@ MAP
Definition: scanner.h:37
YAML_PM::Scanner::IndentMarker::INDENT_TYPE
INDENT_TYPE
Definition: scanner.h:37
YAML_PM::Scanner::SimpleKey
Definition: scanner.h:82
YAML_PM::Scanner::IndentMarker::NONE
@ NONE
Definition: scanner.h:37
YAML_PM::Scanner::ScanPlainScalar
void ScanPlainScalar()
Definition: scantoken.cpp:299
YAML_PM::Scanner::IndentMarker
Definition: scanner.h:36
YAML_PM::Scanner::EnsureTokensInQueue
void EnsureTokensInQueue()
Definition: scanner.cpp:57
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::Scanner::ScanDirective
void ScanDirective()
Definition: scantoken.cpp:17
YAML_PM::Scanner::ScanBlockSeqStart
void ScanBlockSeqStart()
YAML_PM::Scanner::SimpleKey::pKey
Token * pKey
Definition: scanner.h:91
YAML_PM::Scanner::IsWhitespaceToBeEaten
bool IsWhitespaceToBeEaten(char ch)
Definition: scanner.cpp:210
YAML_PM::Scanner::PopIndent
void PopIndent()
Definition: scanner.cpp:349
YAML_PM::Scanner::ExistsActiveSimpleKey
bool ExistsActiveSimpleKey() const
Definition: simplekey.cpp:48
YAML_PM::Scanner::IndentMarker::SEQ
@ SEQ
Definition: scanner.h:37
YAML_PM::Scanner::m_indentRefs
ptr_vector< IndentMarker > m_indentRefs
Definition: scanner.h:126
YAML_PM::Token::TYPE
TYPE
Definition: token.h:42
YAML_PM::Scanner::~Scanner
~Scanner()
Definition: scanner.cpp:15
YAML_PM::Scanner::SimpleKey::Invalidate
void Invalidate()
Definition: simplekey.cpp:26
YAML_PM::Scanner::StartStream
void StartStream()
Definition: scanner.cpp:233
YAML_PM::Scanner::ScanBlockScalar
void ScanBlockScalar()
Definition: scantoken.cpp:377
YAML_PM::Scanner::SimpleKey::Validate
void Validate()
Definition: simplekey.cpp:13
YAML_PM::Scanner::PushIndentTo
IndentMarker * PushIndentTo(int column, IndentMarker::INDENT_TYPE type)
Definition: scanner.cpp:278
YAML_PM::Scanner::m_simpleKeys
std::stack< SimpleKey > m_simpleKeys
Definition: scanner.h:124
YAML_PM::Scanner::VerifySimpleKey
bool VerifySimpleKey()
Definition: simplekey.cpp:104
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::Scanner::ScanToNextToken
void ScanToNextToken()
Definition: scanner.cpp:165
YAML_PM::Scanner::SimpleKey::SimpleKey
SimpleKey(const Mark &mark_, int flowLevel_)
Definition: simplekey.cpp:8
YAML_PM::Scanner::ScanValue
void ScanValue()
Definition: scantoken.cpp:196
YAML_PM::Scanner::FLOW_MAP
@ FLOW_MAP
Definition: scanner.h:47
YAML_PM::Scanner::IndentMarker::status
STATUS status
Definition: scanner.h:43
YAML_PM::Scanner::IndentMarker::pStartToken
Token * pStartToken
Definition: scanner.h:44
YAML_PM::Scanner::InFlowContext
bool InFlowContext() const
Definition: scanner.h:58
YAML_PM::Scanner::m_simpleKeyAllowed
bool m_simpleKeyAllowed
Definition: scanner.h:122
stream.h
YAML_PM::Scanner::SimpleKey::flowLevel
int flowLevel
Definition: scanner.h:89
YAML_PM::Scanner::IndentMarker::INVALID
@ INVALID
Definition: scanner.h:38
YAML_PM::Scanner::Scanner
Scanner(std::istream &in)
Definition: scanner.cpp:10
ptr_vector.h
YAML_PM::Scanner::GetValueRegex
const RegEx & GetValueRegex() const
Definition: scanner.cpp:223
YAML_PM::Scanner::m_canBeJSONFlow
bool m_canBeJSONFlow
Definition: scanner.h:123
YAML_PM::Scanner::IndentMarker::type
INDENT_TYPE type
Definition: scanner.h:42
YAML_PM::Scanner::ScanNextToken
void ScanNextToken()
Definition: scanner.cpp:88
YAML_PM::Scanner::ScanBlockMapSTart
void ScanBlockMapSTart()
YAML_PM::Scanner::ScanDocStart
void ScanDocStart()
Definition: scantoken.cpp:59
YAML_PM::Scanner::SimpleKey::pMapStart
Token * pMapStart
Definition: scanner.h:91
YAML_PM::Scanner::ScanTag
void ScanTag()
Definition: scantoken.cpp:259
YAML_PM::Scanner::ScanFlowStart
void ScanFlowStart()
Definition: scantoken.cpp:87
YAML_PM::Scanner::ScanAnchorOrAlias
void ScanAnchorOrAlias()
Definition: scantoken.cpp:225
YAML_PM::Scanner::GetFlowLevel
int GetFlowLevel() const
Definition: scanner.h:60
YAML_PM::Scanner::ScanDocEnd
void ScanDocEnd()
Definition: scantoken.cpp:73
YAML_PM::RegEx
Definition: regex.h:21
YAML_PM::Scanner::IndentMarker::column
int column
Definition: scanner.h:41
YAML_PM::Scanner::PopAllIndents
void PopAllIndents()
Definition: scanner.cpp:331
YAML_PM::Scanner::InsertPotentialSimpleKey
void InsertPotentialSimpleKey()
Definition: simplekey.cpp:60
YAML_PM::Scanner::ScanBlockEnd
void ScanBlockEnd()
YAML_PM::Scanner::GetTopIndent
int GetTopIndent() const
Definition: scanner.cpp:366
YAML_PM::Scanner::IndentMarker::STATUS
STATUS
Definition: scanner.h:38
YAML_PM::ptr_vector
Definition: ptr_vector.h:17
YAML_PM::Mark
Definition: mark.h:13
YAML_PM::Scanner::m_tokens
std::queue< Token > m_tokens
Definition: scanner.h:118
YAML_PM::Scanner::ScanQuotedScalar
void ScanQuotedScalar()
Definition: scantoken.cpp:335
YAML_PM::Scanner::m_indents
std::stack< IndentMarker * > m_indents
Definition: scanner.h:125
YAML_PM::Scanner::CanInsertPotentialSimpleKey
bool CanInsertPotentialSimpleKey() const
Definition: simplekey.cpp:37
YAML_PM::Stream
Definition: stream.h:20
YAML_PM::Scanner::FLOW_MARKER
FLOW_MARKER
Definition: scanner.h:47
YAML_PM::Scanner::InvalidateSimpleKey
void InvalidateSimpleKey()
Definition: simplekey.cpp:87
YAML_PM::Token
Definition: token.h:39
YAML_PM::Scanner::ThrowParserException
void ThrowParserException(const std::string &msg) const
Definition: scanner.cpp:377
YAML_PM::Scanner::PopIndentToHere
void PopIndentToHere()
Definition: scanner.cpp:307
YAML_PM::Scanner::m_startedStream
bool m_startedStream
Definition: scanner.h:121
YAML_PM::Scanner::FLOW_SEQ
@ FLOW_SEQ
Definition: scanner.h:47
YAML_PM::Scanner::peek
Token & peek()
Definition: scanner.cpp:38
YAML_PM::Scanner::ScanBlockEntry
void ScanBlockEntry()
Definition: scantoken.cpp:155
YAML_PM::Scanner::PopAllSimpleKeys
void PopAllSimpleKeys()
Definition: simplekey.cpp:133
YAML_PM::Scanner
Definition: scanner.h:24
YAML_PM::Scanner::SimpleKey::mark
Mark mark
Definition: scanner.h:88
token.h
YAML_PM::Scanner::ScanFlowEntry
void ScanFlowEntry()
Definition: scantoken.cpp:135
YAML_PM::Scanner::empty
bool empty()
Definition: scanner.cpp:21
YAML_PM::Scanner::m_flows
std::stack< FLOW_MARKER > m_flows
Definition: scanner.h:127
YAML_PM::Scanner::IndentMarker::UNKNOWN
@ UNKNOWN
Definition: scanner.h:38
YAML_PM::Scanner::m_endedStream
bool m_endedStream
Definition: scanner.h:121
YAML_PM::Scanner::EndStream
void EndStream()
Definition: scanner.cpp:244


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:46:00