| 172 | } |
| 173 | |
| 174 | Scope::Scope(Parser& parser,bool topLevel) |
| 175 | { |
| 176 | if(!topLevel) { |
| 177 | TokenPtr t = parser.CurrentToken(); |
| 178 | if (t->Type() != TokenType_OPEN_BRACKET) { |
| 179 | ParseError("expected open bracket",t); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | StackAllocator &allocator = parser.GetAllocator(); |
| 184 | TokenPtr n = parser.AdvanceToNextToken(); |
| 185 | if (n == nullptr) { |
| 186 | ParseError("unexpected end of file"); |
| 187 | } |
| 188 | |
| 189 | // note: empty scopes are allowed |
| 190 | while(n->Type() != TokenType_CLOSE_BRACKET) { |
| 191 | if (n->Type() != TokenType_KEY) { |
| 192 | ParseError("unexpected token, expected TOK_KEY",n); |
| 193 | } |
| 194 | |
| 195 | const std::string& str = n->StringContents(); |
| 196 | if (str.empty()) { |
| 197 | ParseError("unexpected content: empty string."); |
| 198 | } |
| 199 | |
| 200 | auto *element = new_Element(*n, parser); |
| 201 | |
| 202 | // Element() should stop at the next Key token (or right after a Close token) |
| 203 | n = parser.CurrentToken(); |
| 204 | if (n == nullptr) { |
| 205 | if (topLevel) { |
| 206 | elements.insert(ElementMap::value_type(str, element)); |
| 207 | return; |
| 208 | } |
| 209 | delete_Element(element); |
| 210 | ParseError("unexpected end of file",parser.LastToken()); |
| 211 | } else { |
| 212 | elements.insert(ElementMap::value_type(str, element)); |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // ------------------------------------------------------------------------------------------------ |
| 218 | Scope::~Scope() |
nothing calls this directly
no test coverage detected