| 314 | } |
| 315 | |
| 316 | bool Parser::ParseResource(Parser::Context &context) { |
| 317 | Resource& resource = program.resources.emplace_back(); |
| 318 | |
| 319 | // Parse the type |
| 320 | if (!ParseResourceType(context, &resource.type)) { |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | if (context.TryNext("<")) { |
| 325 | Token format = context.Next(); |
| 326 | |
| 327 | if (format.type != TokenType::ID) { |
| 328 | context.Error("Expected format identifier"); |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | resource.format = format.str; |
| 333 | |
| 334 | if (!context.TryNext(">")) { |
| 335 | context.Error("Expected end of format template"); |
| 336 | return false; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if (context.TryNext("[")) { |
| 341 | Token count = context.Next(); |
| 342 | |
| 343 | if (count.type != TokenType::Int) { |
| 344 | context.Error("Expected size integer"); |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | resource.format = count.str; |
| 349 | |
| 350 | if (!context.TryNext("]")) { |
| 351 | context.Error("Expected end of array size"); |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | while (context) { |
| 357 | Token attribute = context.Next(); |
| 358 | |
| 359 | // Must be ID |
| 360 | if (attribute.type != TokenType::ID) { |
| 361 | context.Error("Expected attribute"); |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | // Expecting a:b |
| 366 | if (!context.TryNext(":")) { |
| 367 | context.Error("Expected : between attribute and value"); |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | // Handle type |
| 372 | if (attribute == "size") { |
| 373 | while (context) { |