Specification.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2023-2024, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Parser/Lexer.h"
  7. #include "Parser/SpecificationParsing.h"
  8. #include "Parser/XMLUtils.h"
  9. namespace JSSpecCompiler {
  10. NonnullOwnPtr<Specification> Specification::create(SpecificationParsingContext& ctx, XML::Node const* element)
  11. {
  12. VERIFY(element->as_element().name == tag_specification);
  13. auto specification = make<Specification>();
  14. specification->parse(ctx, element);
  15. return specification;
  16. }
  17. void Specification::collect_into(TranslationUnitRef translation_unit)
  18. {
  19. for (auto& clause : m_clauses)
  20. clause->collect_into(translation_unit);
  21. }
  22. void Specification::parse(SpecificationParsingContext& ctx, XML::Node const* element)
  23. {
  24. for (auto const& child : element->as_element().children) {
  25. child->content.visit(
  26. [&](XML::Node::Element const& element) {
  27. if (element.name == tag_emu_intro) {
  28. // Introductory comments are ignored.
  29. } else if (element.name == tag_emu_clause) {
  30. m_clauses.append(SpecificationClause::create(ctx, child));
  31. } else if (element.name == tag_emu_import) {
  32. parse(ctx, child);
  33. } else {
  34. ctx.diag().error(ctx.location_from_xml_offset(child->offset),
  35. "<{}> should not be a child of <specification>", element.name);
  36. }
  37. },
  38. [&](XML::Node::Text const&) {
  39. if (!contains_empty_text(child)) {
  40. ctx.diag().error(ctx.location_from_xml_offset(child->offset),
  41. "non-empty text node should not be a child of <specification>");
  42. }
  43. },
  44. [&](auto) {});
  45. }
  46. }
  47. }