parser_context.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <optional>
  3. #include <jvalidate/detail/reference.h>
  4. #include <jvalidate/forward.h>
  5. namespace jvalidate::detail {
  6. template <Adapter A> struct ParserContext {
  7. using Object = decltype(std::declval<A>().as_object());
  8. Schema & root;
  9. A schema;
  10. schema::Version version;
  11. ConstraintFactory<A> const & factory;
  12. DocumentCache<A> & external;
  13. std::optional<Object> parent = std::nullopt;
  14. Reference where = {};
  15. ParserContext rebind(A const & new_schema, Reference const & new_loc,
  16. std::optional<Object> parent = std::nullopt) const {
  17. return {root, new_schema, version, factory, external, parent, new_loc};
  18. }
  19. ParserContext child(A const & child, std::string const & key) const {
  20. return rebind(child, where / key, schema.as_object());
  21. }
  22. ParserContext child(A const & child, size_t index) const { return rebind(child, where / index); }
  23. ParserContext neighbor(std::string const & key) const {
  24. return rebind((*parent)[key], where.parent() / key, parent);
  25. }
  26. schema::Node const * node() const;
  27. schema::Node const * always() const;
  28. schema::Node const * fixed_schema(bool accept) const;
  29. };
  30. }