simplekey.cpp
Go to the documentation of this file.
1 #include "scanner.h"
2 #include "token.h"
4 #include "exp.h"
5 
6 namespace YAML_PM
7 {
8  Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
9  : mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0)
10  {
11  }
12 
14  {
15  // Note: pIndent will *not* be garbage here;
16  // we "garbage collect" them so we can
17  // always refer to them
18  if(pIndent)
20  if(pMapStart)
22  if(pKey)
24  }
25 
27  {
28  if(pIndent)
30  if(pMapStart)
32  if(pKey)
34  }
35 
36  // CanInsertPotentialSimpleKey
38  {
40  return false;
41 
42  return !ExistsActiveSimpleKey();
43  }
44 
45  // ExistsActiveSimpleKey
46  // . Returns true if there's a potential simple key at our flow level
47  // (there's allowed at most one per flow level, i.e., at the start of the flow start token)
49  {
50  if(m_simpleKeys.empty())
51  return false;
52 
53  const SimpleKey& key = m_simpleKeys.top();
54  return key.flowLevel == GetFlowLevel();
55  }
56 
57  // InsertPotentialSimpleKey
58  // . If we can, add a potential simple key to the queue,
59  // and save it on a stack.
61  {
63  return;
64 
65  SimpleKey key(INPUT.mark(), GetFlowLevel());
66 
67  // first add a map start, if necessary
68  if(InBlockContext()) {
70  if(key.pIndent) {
71  key.pIndent->status = IndentMarker::UNKNOWN;
72  key.pMapStart = key.pIndent->pStartToken;
73  key.pMapStart->status = Token::UNVERIFIED;
74  }
75  }
76 
77  // then add the (now unverified) key
79  key.pKey = &m_tokens.back();
80  key.pKey->status = Token::UNVERIFIED;
81 
82  m_simpleKeys.push(key);
83  }
84 
85  // InvalidateSimpleKey
86  // . Automatically invalidate the simple key in our flow level
88  {
89  if(m_simpleKeys.empty())
90  return;
91 
92  // grab top key
93  SimpleKey& key = m_simpleKeys.top();
94  if(key.flowLevel != GetFlowLevel())
95  return;
96 
97  key.Invalidate();
98  m_simpleKeys.pop();
99  }
100 
101  // VerifySimpleKey
102  // . Determines whether the latest simple key to be added is valid,
103  // and if so, makes it valid.
105  {
106  if(m_simpleKeys.empty())
107  return false;
108 
109  // grab top key
110  SimpleKey key = m_simpleKeys.top();
111 
112  // only validate if we're in the correct flow level
113  if(key.flowLevel != GetFlowLevel())
114  return false;
115 
116  m_simpleKeys.pop();
117 
118  bool isValid = true;
119 
120  // needs to be less than 1024 characters and inline
121  if(INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
122  isValid = false;
123 
124  // invalidate key
125  if(isValid)
126  key.Validate();
127  else
128  key.Invalidate();
129 
130  return isValid;
131  }
132 
134  {
135  while(!m_simpleKeys.empty())
136  m_simpleKeys.pop();
137  }
138 }
139 
int GetFlowLevel() const
Definition: scanner.h:60
Stream INPUT
Definition: scanner.h:115
std::queue< Token > m_tokens
Definition: scanner.h:118
bool ExistsActiveSimpleKey() const
Definition: simplekey.cpp:48
IndentMarker * PushIndentTo(int column, IndentMarker::INDENT_TYPE type)
Definition: scanner.cpp:278
IndentMarker * pIndent
Definition: scanner.h:90
int line() const
Definition: stream.h:40
int line
Definition: mark.h:19
bool m_simpleKeyAllowed
Definition: scanner.h:122
bool InBlockContext() const
Definition: scanner.h:59
void InvalidateSimpleKey()
Definition: simplekey.cpp:87
int column() const
Definition: stream.h:41
int pos
Definition: mark.h:18
void InsertPotentialSimpleKey()
Definition: simplekey.cpp:60
bool VerifySimpleKey()
Definition: simplekey.cpp:104
bool CanInsertPotentialSimpleKey() const
Definition: simplekey.cpp:37
std::stack< SimpleKey > m_simpleKeys
Definition: scanner.h:124
const Mark mark() const
Definition: stream.h:38
void PopAllSimpleKeys()
Definition: simplekey.cpp:133
STATUS status
Definition: token.h:76
SimpleKey(const Mark &mark_, int flowLevel_)
Definition: simplekey.cpp:8
int pos() const
Definition: stream.h:39


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